ignah
February 28th, 2000, 03:23 AM
I want to write a message handler
for user defined message(WM_USER + N) in Visual Basic.
The message is sent to my visual basic application from DLL.
I wrote the DLL in Visual C++.
Anyone help me?
Thanks in advance!
Lothar Haensler
February 28th, 2000, 03:40 AM
MSDN article Q170570 has all the details for doing what you want.
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(byval lpPrevWndFunc as Long, _
byval hWnd as Long, _
byval Msg as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(byval hWnd as Long, _
byval nIndex as Long, _
byval dwNewLong as Long) as Long
public Const GWL_WNDPROC = -4
public Const WM_USER = &H400
public Const MY_MSG = &H400 +1
Global lpPrevWndProc as Long
Global gHW as Long
public Sub Hook()
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
public Sub UnHook()
Dim lngReturnValue as Long
lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(byval hw as Long, _
byval uMsg as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
Select Case uMsg
Case MY_MSG
'your code goes here
Case else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Select
End Function