callback message - haster
HejJeg vil gerne modtage messages fra et andet program ind i mit program. Det kan jeg osse godt finde ud af med denne kode men der opstår en fejl i kernel når jeg afslutter.
Public 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
Public 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
Global lpPrevWndProc As Long
Public Sub Hook(xHwnd As Long)
lpPrevWndProc = SetWindowLong(xHwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub Unhook(xHwnd As Long)
Dim temp As Long
temp = SetWindowLong(xHwnd, 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
If uMsg = WM_USER + 308 Then
Label2.Caption = 1024 + 308 & \" er kommer ind\"
End If
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
Form_load: Hook me.hwnd
form_unload: Unhook me.hwnd