Hook setzen
-
Hallo,
ich bekomme das einfach nicht hin in c++. Unter VB läufts einwandfrei!
Kann mir jemmand sagen wie ich das in c++ hinbekomme ?Option Explicit Private Declare Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long, ByVal dwNewLong As Long) _ As Long Private 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 Private Const GWL_WNDPROC = (-4&) Private Const WM_LBUTTONDOWN As Long = &H201 Dim PrevWndProc& Public Sub Init(hWnd As Long) PrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, _ AddressOf SubWndProc) End Sub Public Sub Terminate(hWnd As Long) Call SetWindowLong(hWnd, GWL_WNDPROC, PrevWndProc) End Sub Private Function SubWndProc(ByVal hWnd As Long, _ ByVal Msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long if Msg = WM_LBUTTONDOWN then call MsgBox("MouseDown") End if SubWndProc = CallWindowProc(PrevWndProc, hWnd, Msg, _ wParam, lParam) End Function
Ganz klar was das hier bedeutet, mit Init initialisiere ich das hook, mit Terminate aktiviere ich wieder das alte und mit SubWndProc prüfe ich die Nachrichten. In diesem Falle wir bei einem Mousedown auf das Fenster eine Meldung ausgegeben.
Wie kann ich den dies mit c++ programmieren! Habe schon probiert es genauso nachzubauen. Aber das funktioniert nicht!
Gruß Ronny
-
Schau mal bei codeguru, da gibts ein gutes beispielprojekt.
Devil
-
das ist kein Hook, in deinem Beispiel tauschst du die Fenster Prozedur nur aus - sogennantes Control Subclassing, außerdem warum erröffnest du denn zwei Threads? Reicht einer nicht? http://www.c-plusplus.net/forum/viewtopic.php?t=55193 ist ja auch von dir.