Startseite ¦  was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews ¦  sonstiges
kylix ¦  tutorials ¦  online shop ¦  fotos ¦  Add&Win Gewinnspiel


Willkommen Gast. Bitte einloggen oder registrieren.
22.05.2012, 14:56:19
Übersicht Hilfe Suche Einloggen Registrieren

+  SwissDelphiCenter Forum
|-+  German Forums
| |-+  WinAPI Forum
| | |-+  Probleme beim Hook!
« vorheriges nächstes »
Seiten: [1] Drucken
Autor Thema: Probleme beim Hook!  (Gelesen 1579 mal)
EgoFelix
Full Member
***
Offline Offline

Beiträge: 139


99943504
WWW
« am: 09.05.2002, 11:49:02 »

Hi Leute!
Hier erstmal der Code:
Code:
library KeyboardHook;



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, DirectMemory;



var

  MyDc: HDC;

  MyCanvas: TCanvas;



  MyHwnd: HWND;



  HookHandle: Cardinal = 0;

  WindowHandle: Cardinal = 0;

  STitle: array[0..260] of char;



function Action(nCode: Integer; wParam: WPARAM; lParam: LPARAM):

 LRESULT; stdcall;

var

  NextHandle: HWND;

  NextTitle: array[0..260] of char;

begin

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

    if TMsg(Pointer(lParam)^).message = WM_PAINT then begin

    //NextHandle := TMsg(Pointer(lParam)^).hwnd;

    //GetWindowText(NextHandle, NextTitle, 255);



    MyCanvas.TextOut(20, 20, 'Mein Text');



    if (Pos(STitle,NextTitle) > 0) then begin

      //MessageBox(0, PChar('Hook läuft'), 'Hook Status', 0);



    end;

    //MessageBox(0, PChar('Hook läuft in ' + NextTitle), 'Hook Status', 0);

  end;

end;



function InstallHook(Handle: HWND): Boolean; stdcall;

begin

  Result := False;

  if HookHandle = 0 then begin

//Erstmal Hook installieren

//First install the hook

    HookHandle := SetWindowsHookEx(WH_GETMESSAGE, @Action, HInstance, 0);

//Uebergebenes Fensterhandle sichern

//Save the given window handle

    MyHwnd := Handle;

    WindowHandle := Handle;

    GetWindowText(Handle, STitle, 255);



    MyDc := GetWindowDC(Handle);

    MyCanvas := TCanvas.Create;

    MyCanvas.Handle := MyDC;

    BeginPath(MyCanvas.Handle);

    MyCanvas.Font.Color := clBlue;

    MyCanvas.Font.Name := 'Arial';

    MyCanvas.Font.Size := 10;

    SetBkMode(MyCanvas.Handle, TRANSPARENT);

    EndPath(MyCanvas.Handle);



    MyCanvas.TextOut(20, 20, 'Hook installed');



    Result := TRUE;

  end;

end;



function UninstallHook: Boolean; stdcall;

begin

//Hook aus der Hookchain entfernen

//Uninstall hook from hook chain

  Result := UnhookWindowsHookEx(HookHandle);

  HookHandle := 0;

  MyCanvas.TextOut(20, 20, 'Hook deinstalled');

end;



exports

//Installations- und Deinstallationsroutine exportieren

//Export the installation and deinstallation routine

  InstallHook,

  UninstallHook;

end.


So, da muss ich wohl einiges zu sagen...
Also, beim Installieren wird normalerweise das Handle übergeben...
Blos, dass WM_PAINT Ereignis wird immer nur vom Aktiven Handle ausgeführt, und das mit MyCanvas.Textout in der Action Funktion funktioniert nur, wenn ich das Handle nehme, von dem ihc den Hook aus starte... Bei anderen Handels funktioniert das irgendwie nicht...

Kann mir wer helfen?

Danke
Gespeichert

EgoFelix
Seiten: [1] Drucken 
« vorheriges nächstes »
Gehe zu:  


Einloggen mit Benutzername, Passwort und Sitzungslänge

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Prüfe XHTML 1.0 Prüfe CSS