VBA: Anyone familiar with Windows APIs?

L'Amore

Board Regular
Joined
Aug 21, 2013
Messages
116
Sorry, i realize this is probably the wrong forum / wrong site but i like this community and am sure you can help!

I am currently trying to work out the way some of the APIs in windows work. The literature is somewhat confusing but i think this is mostly due to the fact I'm new to it.
So:

This is a user posted Usage from msdn, Visual Basic 9, I am using the visual basic editor in powerpoint so not sure if this is right
Rich (BB code):
Rich (BB code):
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort  ''(i have used ...ByVal vKey As Long) As Integer  here as mentioned in another post on this forum

Public Shared ReadOnly Property KeyStatus(ByVal Key As Keys) As Boolean
    Get
        If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
            Key = Keys.RButton
        ElseIf Key = Keys.RButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
           Key = Keys.LButton
        End If
        Return API.Devices.GetAsyncKeyState(Key) And &H8000US
    End Get
End Property
i understand the reason for the if statement, (which i dont need) but can anyone explain the rest?what do the &H8000US bits mean, these have cropped up elsewhere too, but not too sure what the are, is it just a value recognised by windows and how do i find out what this value is for VBA?I have not seen the Get function before, leading me to believe i have actually got non compatiable code here in which case any help on how to implement it for VBA?why ReadOnly?, what does this do?why no Set in the declaration?is Keys.LButton recognized through the API?, or is this from VB, Sorry for this badly worded questions, i hope someone can help a little but google isn't helping a huge amount at the moment :(
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The sample you have posted is VB.Net hence the confusion.

The &H8000 refers to the bit (literally) of the return value that you want to check. If the &H8000 bit of the return value is set, the key has been pressed at least once since the last time the thread called GetAsyncKeyState. If the &H1 bit of the return value is set, the key is currently pressed down.
 
Upvote 0
this was posted seperate to the vb.net usage example so just got confused, i did think it might be different just from the commands i didnt recognise.
Dont suppose you would know how to make use fo this API?
The goal is to run a loop whilst the LMB is pressed, but im struggling with the way most of the literature is described as its all new and very different! I am looking to paste a picture when the LMB is pressed and then use the difference in location from the LMB press and LMB release to rotate the picture in that direction (to the nearest multiple of 15 degrees).
The only API i understang so far is the GetCursorPos, but i have been trying to get my head around this one and the WM_LBUTTONDOWN and the DragDetect functions.
Any help / pointers will be greatly appreciated as always
Thanks
 
Upvote 0
Can I ask why? It might be easier to use an ActiveX image control that's already in place - they have MouseMove/Up/Down events you can trap.
 
Upvote 0
I currently have a modeless userform that helps in the creation of documents, or will do when its finished. It dynamically created buttons based on the images stored in a directory and on clicking the button (currently) pastes the relevant image (shown on the button) into the slide, at the moment at a random location: 200,200. The images represent, say a light bulb, so with the plan of a house on the slide, you paste in the light bulbs in the locations you wish them to be.
Currently you paste an image in and have to move it manually. With these API calls i am aiming to allow the user to click the button, and then clik on the slide where they want the image to go and specify rotation as mentioned before. I realise this will run into problems if you then say, click a toolbar or something but i planning to write something that works out the slide location on the screen and only engages when within the bounds etc. The problems are just getting used to these new concepts that arent quite as intuitive as VBA
 
Upvote 0
I'm not really sure why you would use Excel for this. Anyway, it would probably be simpler to have controls on the userform to move/rotate the object.
 
Upvote 0
Its power point, its to produce rough sketches that show intent more rapidly than using proper AutoCAD.
It would be easier to move and rotate by hand than have buttons to do iton the userform, i realise this. But to be able to insert them directly at a particular point, like a light over a door / entrance would be far more efficent that manually inserting / creating shapes and the point you want. The form is just for indexing and catagoizing a library of schematical symbols, to allow them to be entered quicker.

There is method to my madness!

I agree though, it would be simpler to just put controls on the form, or even just leave as is, but the goal is to create a decent substitue for AutoCAD that can show design intent quicker but just as clear as CAD packages. As its only simple 2D designs.
 
Last edited:
Upvote 0
Ah, well if it's not Excel, I shall move this to the non-Excel area. ;)
 
Upvote 0

Forum statistics

Threads
1,225,657
Messages
6,186,257
Members
453,347
Latest member
mrizkiii28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top