Einzelnen Beitrag anzeigen

Benutzerbild von Flocke
Flocke

Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#15

Re: WM_WINDOWPOSCHANGING abfangen

  Alt 31. Aug 2005, 17:03
Etwa so sollte es aussehen (alles ungetestet).

Delphi-Quellcode:
library SuperMsgHook;

uses
  Windows,
  Messages,
  SysUtils,
  Classes;

type
  TMessageHookCallback = procedure(const Msg: Windows.TMsg) of object;

var
  HookHandle: Cardinal;
  CallbackProc: TMessageHookCallback;

function GetMsgProc(code: integer; wParam: WPARAM; lParam: LPARAM): LResult;
  stdcall;
begin
  if (code = HC_ACTION) and Assigned(CallbackProc) then
    if Windows.PMsg(lParam)^.message = WM_WINDOWPOSCHANGING then
      CallbackProc(Windows.PMsg(lParam)^);

  Result := CallNextHookEx(HookHandle, Code, wParam, lParam);
end;

procedure DisableMessageHook;
  stdcall;
begin
  CallbackProc := nil;

  if HookHandle <> 0 then
  begin
    UnhookWindowsHookEx(HookHandle);
    HookHandle := 0;
  end;
end;

procedure EnableMessageHook(ACallbackProc: TMessageHookCallback);
  stdcall;
begin
  DisableMessageHook;

  CallbackProc := ACallbackProc;
  HookHandle := SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hInstance, 0);
  if HookHandle = 0 then
    RaiseLastOsError;
end;

exports
  GetMsgProc,
  EnableMessageHook,
  DisableMessageHook;

end.
... und dann in deinem Hauptprogramm:

Delphi-Quellcode:
type
  TMessageHookCallback = procedure(const Msg: Windows.TMsg) of object;

procedure DisableMessageHook; stdcall; external 'SuperMsgHook.dll';
procedure EnableMessageHook(ACallbackProc: TMessageHookCallback); stdcall; external 'SuperMsgHook.dll';
Du brauchst dann eine selbstgeschriebene Methode, die die Informationen entgegennimmt. Die übergibst du an "EnableMessageHook".
Volker
Besucht meine Garage
Aktuell: RtfLabel 1.3d, PrintToFile 1.4
  Mit Zitat antworten Zitat