gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 351
- Office Version
- 365
- Platform
- Windows
- Mobile
I have been studying some of the code snippets posted to the forums. I have a very broad question to ask, so forgive me if I ramble.
I am trying to understand how VBA works with Windows Controls, Messages, etc. I don't have anything specific in mind that I'm trying to do, but I want to learn it for future uses. This is from something @Jaafar Tribak posted that is meant to allow mouse scrolling in Combo Boxes.
I understand the purpose of declaring these, but it is difficult to find them in the documentation since it is not being updated https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85) (RECT struct). I am trying to determine what other structures are available.
1) What do I need to understand about the user32.dll & kernel32.dll other than that they are the libraries associated with these functions?
2) Why are they sometimes called macros in the docs instead of functions? Is there any difference I should be concerned about?
3) How do I determine what type is appropriate in the declaration? For example, in the WindowFromPoint function the return type is HWND, but in VBA we use LongPtr - why? In others, BOOL is return type, but in VBA it is Long.
4) Some return types are Long, others are LongPtr, but I thought they were always supposed to be LongPtr in 64-bit?
5) Is Any the same as Variant?
6) Why do some functions have A or W suffix, and what's the difference?
I do plan on learning C++ a bit more than I currently know, so hopefully that will help me understand the intuitive approach to these problems.
I have more questions than this, but I don't want to go overboard. Thanks for any help!
I am trying to understand how VBA works with Windows Controls, Messages, etc. I don't have anything specific in mind that I'm trying to do, but I want to learn it for future uses. This is from something @Jaafar Tribak posted that is meant to allow mouse scrolling in Combo Boxes.
Code:
Private Type POINTAPI x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
I understand the purpose of declaring these, but it is difficult to find them in the documentation since it is not being updated https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85) (RECT struct). I am trying to determine what other structures are available.
Code:
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] VBA7 Then [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] Win64 Then
Private Declare PtrSafe Function WindowFromPoint Lib "user32" (ByVal Point As LongPtr) As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
Private Declare PtrSafe Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
Code:
Private Declare PtrSafe Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As MSG, ByVal hWnd As LongPtr, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long Private Declare PtrSafe Function WaitMessage Lib "user32" () As Long
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function SetFocus Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
1) What do I need to understand about the user32.dll & kernel32.dll other than that they are the libraries associated with these functions?
2) Why are they sometimes called macros in the docs instead of functions? Is there any difference I should be concerned about?
3) How do I determine what type is appropriate in the declaration? For example, in the WindowFromPoint function the return type is HWND, but in VBA we use LongPtr - why? In others, BOOL is return type, but in VBA it is Long.
4) Some return types are Long, others are LongPtr, but I thought they were always supposed to be LongPtr in 64-bit?
5) Is Any the same as Variant?
6) Why do some functions have A or W suffix, and what's the difference?
I do plan on learning C++ a bit more than I currently know, so hopefully that will help me understand the intuitive approach to these problems.
I have more questions than this, but I don't want to go overboard. Thanks for any help!