unit Unit2;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TMyCallBack =
procedure(nCode: Integer; WPARAM: WPARAM; LPARAM: LPARAM);
stdcall;
TInstallHook =
function(hWnd: THandle; aCallBack: TMyCallBack): Boolean;
stdcall;
TUninstallHook =
function: Boolean;
stdcall;
TForm2 =
class(TForm)
Label1: TLabel;
Memo1: TMemo;
Label2: TLabel;
Button1: TButton;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
InstallHook: TInstallHook;
UninstallHook: TUninstallHook;
lib: Cardinal;
HotKey1_gesetzt: Boolean;
procedure Hooken;
// procedure WndProc(var Msg: TMessage); override;
public
{ Public-Deklarationen }
protected
{ Protected-Deklarationen }
procedure WMHotKey(
var Message: TMessage);
message WM_HOTKEY;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure HookCallWndProc(nCode : Integer; WPARAM : WPARAM; LPARAM : LPARAM);
stdcall;
var
cwps: TCWPStruct;
begin
If nCode = HC_ACTION
then
begin
CopyMemory(@cwps, Pointer(LPARAM), SizeOf(CWPSTRUCT));
case cwps.
message of
WM_GETMINMAXINFO:
begin
Form2.Memo1.Lines.add(Format('
Message - %d', [cwps.hwnd]));
// TWMGetMinMaxInfo(Msg.message).MinMaxInfo.ptMaxSize.X := 40000;
// TWMGetMinMaxInfo(cwps.message).MinMaxInfo.ptMaxSize.Y := 40000;
// TWMGetMinMaxInfo(cwps.message).MinMaxInfo.ptMaxTrackSize.X := 40000;
// TWMGetMinMaxInfo(cwps.message).MinMaxInfo.ptMaxTrackSize.Y := 40000;
end;
WM_WINDOWPOSCHANGING:
begin
// Form2.Memo1.Lines.add(Format('Position - %d', [cwps.hwnd]));
end;
WM_MOVING:
begin
Form2.Memo1.Lines.add(Format('
Moving - %d', [cwps.hwnd]));
end;
end;
end;
end;
//----------------------------------------------------------------------------//
procedure TForm2.Hooken;
var
h: THandle;
begin
//MainForm verstecken
Form2.Visible := false;
//kurze Zeit
Sleep(500);
h := GetForeGroundWindow;
Label1.Caption := IntToStr(h);
Label2.Caption := Format('
App: %d - Form: %d', [Application.Handle, Form2.Handle]);
If h <> 0
then
InstallHook(h, HookCallWndProc);
Form2.Visible := true;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Memo1.Clear;
end;
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
UnInstallHook;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
//DLL laden
lib := LoadLibrary(PWideChar(ExtractFilePath(Application.ExeName) + '
\WndProcHook.dll'));
If (lib > 0)
and (lib <> INVALID_HANDLE_VALUE)
then
begin
InstallHook := GetProcAddress(lib, '
InstallHook');
UnInstallHook := GetProcAddress(lib, '
UninstallHook');
end
else
begin
ShowMessage('
Fehler beim Laden der DLL!');
exit;
end;
//Hot-Key für "ganzer Bildschirm" setzen (Alt + F1)
HotKey1_gesetzt := RegisterHotKey(Self.Handle, 1, MOD_ALT, VK_F1);
If not HotKey1_gesetzt
then
ShowMessage(SysErrorMessage(GetLastError));
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
//Registrierungen von HotKeys entfernen (nur wenn wirklich vorhanden)
If HotKey1_gesetzt
then
UnRegisterHotKey(Self.Handle, 1);
end;
procedure TForm2.WMHotKey(
var Message: TMessage);
begin
case Message.WParam
of
1:
begin //Alt + F1
hooken;
end;
end;
end;
end.