Einzelnen Beitrag anzeigen

r29d43

Registriert seit: 18. Jan 2007
287 Beiträge
 
Delphi 10.4 Sydney
 
#1

lokaler Hook wird immer doppelt durchlaufen?

  Alt 30. Apr 2016, 13:10
Hallo, weil ich seit langem mal wieder einen lokalen Hook brauche, konstruierte ich mir erstmal einen solchen in Form eines quasi simpelst möglichen getMsg-Hooks. Allerdings habe ich bei dem jetzt das kuriose Prob, dass alle Messages, die an das Panel1 gehen und auf dem ich mit der Maus jetzt gerade herumklicke, diesen Hook irgendwie doppelt durchlaufen, also dann auch in der Case-Anweisung im Code doppelt gezählt werden.

Delphi-Quellcode:
function GetMsgProc (nCode: Integer; wParam, lParam: Longint): Longint; stdcall;
type MSG = record
       hwnd : HWND;
       message : UINT;
       wParam : DWord;
       lParam : DWord;
       time : DWORD;
       pt : TPOINT;
     end;
     PMSG = ^MSG;
begin
{ }
  if nCode = HC_ACTION
// if not nCode < 0
  then begin

    with form4 do
    if PMSG(lParam)^.hwnd = Form4.panel1.handle then
    case PMSG(lParam)^.message of
      WM_LBUTTONDOWN :
                       begin
                         inc(LButtonDownCounter);
                         label1.caption := IntToStr(LButtonDownCounter)
                       end;
      WM_LBUTTONUP :
                       begin
                         inc(LButtonUpCounter);
                         label2.caption := IntToStr(LButtonUpCounter)
                       end;
      WM_LBUTTONDBLCLK :
                       begin
                         inc(DoppelklickCounter);
                         label3.caption := IntToStr(DoppelklickCounter)
                       end;
    end; { of case }
  end;

  Result := CallNextHookEx(Form4.HookID, nCode, wParam, lParam);
end;


procedure TForm4.FormCreate(Sender: TObject);
begin
  HookID := SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc , 0, GetCurrentThreadId());
  LButtonDownCounter := 0;
  LButtonUpCounter := 0;
  DoppelklickCounter := 0;
end;


procedure TForm4.FormDestroy(Sender: TObject);
begin
  if HookID <> 0 then UnHookWindowsHookEx(HookID);
end;

Irgendwo muss hier doch noch ein winzig kleiner Fehler stecken, nur wo?
(leider habe ich gerade 2 dicke Tomaten auf den Augen).
  Mit Zitat antworten Zitat