1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TPanel = class(Vcl.ExtCtrls.TPanel)
private
class var WatchWnd :THandle;
class var NotifyTo :TPanel;
class procedure WinEventProc(hWinEventHook: THandle; aEvent: dword; aWnd: hWnd; aObject, aChild: cardinal; aEventThread, aEventTime: dword); static; stdcall;
private
Hook :THandle;
protected
procedure SetParent(aParent :TWinControl); override;
procedure OnWindowMoveSizeStart;
procedure OnWindowMoveSizeEnd;
public
constructor Create(aOwner :TComponent); override;
destructor Destroy; override;
end;
TForm1 = class(TForm)
Panel1: TPanel;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TPanel }
constructor TPanel.Create(aOwner: TComponent);
begin
inherited;
NotifyTo := Self;
Hook := SetWinEventHook(EVENT_SYSTEM_MOVESIZESTART, EVENT_SYSTEM_MOVESIZEEND, 0, @WinEventProc, 0, GetCurrentThreadID, WINEVENT_OUTOFCONTEXT);
end;
destructor TPanel.Destroy;
begin
UnhookWinEvent(Hook);
inherited;
end;
procedure TPanel.SetParent(aParent :TWinControl);
begin
inherited;
if Assigned(aParent) then
WatchWnd := GetAncestor(Handle, GA_ROOT);
end;
procedure TPanel.OnWindowMoveSizeEnd;
begin
Caption := 'End';
end;
procedure TPanel.OnWindowMoveSizeStart;
begin
Caption := 'Start';
end;
class procedure TPanel.WinEventProc(hWinEventHook: THandle; aEvent: dword; aWnd: hWnd; aObject, aChild: cardinal; aEventThread, aEventTime: dword);
begin
if aWnd = WatchWnd then
case aEvent of
EVENT_SYSTEM_MOVESIZESTART : NotifyTo.OnWindowMoveSizeStart;
EVENT_SYSTEM_MOVESIZEEND : NotifyTo.OnWindowMoveSizeEnd;
end;
end;
end. |
Partager