Thanks for mentioning hooks!
This is my solution:
program Test;
uses
Windows, Messages, KOL;
var
Hook: HHOOK;
function HookProc(Code,wParam,lParam: Integer): Lresult; stdCall;
var
Wnd: Hwnd;
Rect: TRect;
MB_Width, MB_Height: Integer;
begin
if Code < 0 then
CallNextHookEx(Hook,Code,wParam,lParam);
if Code = HCBT_ACTIVATE then
begin
Wnd := wParam;
GetWindowRect(Wnd,Rect);
MB_Width := Rect.Right - Rect.Left;
MB_Height := Rect.Bottom - Rect.Top;
MoveWindow(Wnd,Applet.Left + ((Applet.Width - MB_Width) div 2),Applet.Top + ((Applet.Height - MB_Height) div 2),MB_Width,MB_Height,True);
UnhookWindowsHookEx(Hook);
end;
Result := CallNextHookEx(Hook,Code,wParam,lParam);
end;
procedure MouseDown(Dummy: Pointer; Sender: PControl; var Mouse: TMouseEventData);
begin
if Mouse.Button <> mbLeft then Exit;
Hook := SetWindowsHookEx(WH_CBT,HookProc,0,GetCurrentThreadId);
ShowMsg('>> Click! <<',MB_OK or MB_APPLMODAL or MB_SETFOREGROUND);
end;
begin
Applet := NewForm(nil,'Test').SetSize(640,480);
Applet.OnMouseDown := TOnMouse(MakeMethod(nil,@MouseDown));
Run(Applet);
end.