AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Hook / Popupmenu

Ein Thema von golisan · begonnen am 5. Aug 2007 · letzter Beitrag vom 21. Aug 2007
 
golisan

Registriert seit: 17. Jan 2007
43 Beiträge
 
Delphi 2007 Professional
 
#6

Re: Hook / Popupmenu

  Alt 7. Aug 2007, 18:05
@c113plpbr

Sorry, ich habe nur den Teil gepostet, da der Rest funktioniert. Ich dachte, evtl. ist es nur ein kleiner Bug.

Also die Hooks sind in einer DLL.
Den Tastatur- und Maushook habe ich nur zur Testzwecken, um zu prüfen, ob's überhaupt tut...

Delphi-Quellcode:
library myhook;

uses
  Windows,
  Messages,
  SysUtils;

var
  HookHandleKB : Cardinal = 0;
  HookHandleM : Cardinal = 0;
  HookHandleMsg : Cardinal = 0;
  WindowHandle : Cardinal = 0;

// ------------------------------ Keyboard -------------------------------


function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
 LRESULT; stdcall;
 var
 Scancode : Integer;
begin
  Result := CallNextHookEx(HookHandleKB, nCode, wParam, lParam);
  case nCode < 0 of
    TRUE: exit; //wenn code kleiner 0 wird nix gemacht

    FALSE:
      begin
        MessageBox(0,'ok','Info',MB_OK);
      end;
  end;
end;

// ------------------------------ Mouse -------------------------------


function MouseHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
 LRESULT; stdcall;
 var
 Scancode : Integer;
begin

  Result := CallNextHookEx(HookHandleM, nCode, wParam, lParam);
  case nCode < 0 of
    TRUE: exit; //wenn code kleiner 0 wird nix gemacht

    FALSE:
      begin

      end;
  end;
end;

// ------------------------------ MSG -------------------------------

function MsgHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
 LRESULT; stdcall;
 var
 Scancode : Integer;
 type PMsg = ^TMsg;
  var msg: PMsg;

begin
 if ncode = HC_ACTION then
    with Windows.PMsg(lParam)^ do
      begin
        if (message = WM_INITDIALOG) or (message = WM_SETFOCUS) then
        begin
          MessageBox(0,'ok','Info',MB_OK);
        end

      end;

Result := CallNextHookEx(HookHandleMsg, nCode, wParam, lParam);



end;

function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
  Result := False;
  if HookHandleKB = 0 then begin
    HookHandleKB := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,
    HInstance, 0);
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
  if HookHandleM = 0 then begin
    HookHandleM := SetWindowsHookEx(WH_MOUSE, @MouseHookProc,
    HInstance, 0);
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
  if HookHandleMSG = 0 then begin
    HookHandleMsg := SetWindowsHookEx(WH_GETMESSAGE, @MsgHookProc,
    HInstance, 0);
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
end;

function UninstallHook: Boolean; stdcall;
begin
//Hook aus der Hookchain entfernen
//Uninstall hook from hook chain
  Result := UnhookWindowsHookEx(HookHandleKB);
  Result := UnhookWindowsHookEx(HookHandleM);
  Result := UnhookWindowsHookEx(HookHandleMsg);
  HookHandleKB := 0;
  HookHandleM := 0;
  HookHandleMsg := 0;
end;

exports
//Installations- und Deinstallationsroutine exportieren
//Export the installation and deinstallation routine
  InstallHook,
  UninstallHook;
end.
In einer Form lade ich den Hook..
Delphi-Quellcode:
initialization
begin
  lib := LoadLibrary('myhook.dll');
  if lib <> INVALID_HANDLE_VALUE then
  begin
    InstallHook := GetProcAddress(lib, 'InstallHook');
    UnInstallHook := GetProcAddress(lib, 'UninstallHook');
    end else showmessage('myHook.dll wurde nicht gefunden!');
end;
und starte dann den Hook..
installHook(0); // Wozu brauche ich hier ein HWND?? Es geht auch ohne... Wie gesagt, Maus- und Tastatur-Hook funktionieren! Nur der Message-Hook nicht richtig.
Es kommen Messages an, nur nicht WM_INITPOPUPMENU oder WM_CONTEXTMENU, obwohl die laut Winsight/ Winspector "rumschwirren"
Und DAS verstehe ich nicht.
Was läuft beim Message-Hook anders als beim Maus- Tastatur-Hook??

Habt ihr eine Idee??

Danke!

PS: ShowMessage tut auch in einer nonVCL, hab's aber trotzdem gegen ein MessageBox getauscht.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:11 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz