-
I am writing a vb program that utilizes two separate applications. One is the user interface and display the other is for data acquisition through usb. To communicate between the two applications I would like to use the PostMessage() API.
I am having trouble understanding how the application interprets the message. I read an article for closing an application that had the sample code below:
Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Sub CloseProgram()
Dim winHwnd As Long
Dim RetVal As Long
Const WM_CLOSE = &H10
winHwnd = FindWindow(vbNullString, "Calculator")
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
End If
End Sub
So here is the question. The Const WM_CLOSE = &H10, how do you come up with &H10? Are the standard WM_ values defined somewhere? I am not interested specifically the WM_CLOSE but all of the WM_ messages.
Also is there a way to define your own WM_ and have the other application respond.
Anyone have any answers.
-
Messages, Constants and Structures (called Types in VB) are listed in the API Text Viewer.
Start > Programs > Microsoft Visual Basic > API Text Viewer.
Once you are in it, go to File > Load TextFile and select Win32API.txt. In the API Type ComboBox, select Constants and you'll be given a list of constants.
-
What about defining your own WM_? Say I wanted to pause a timer in another application. How could I
RetVal = PostMessage(winHwnd, WM_PauseTimer1, 0&, 0&)?
-
WM_? are just constants for different messages. To write your own, you would have to define the constant in a DLL file and write it's prodecure up yourself.
-
Yep, i think you can define whatever messages you want, it's only the number that will be passed, not the WM_...
Code:
WM_MessageToBluelocust=&H1000000
The problems is that you have to find a number that does not interfer with the window messages, for instance WM_CLOSE.