2010. február 11., csütörtök

Detect a form movement


Problem/Question/Abstract:

How to detect a form movement

Answer:

Solve 1:

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMEXITSIZEMOVE(var Message: TMessage); message WM_EXITSIZEMOVE;
    procedure WMENTERSIZEMOVE(var Message: TMessage); message WM_ENTERSIZEMOVE;

implementation

procedure TForm1.WMENTERSIZEMOVE(var Message: TMessage);
begin
  Form1.Caption := 'Starting moving and sizing';
end;

procedure TForm1.WMEXITSIZEMOVE(var Message: TMessage);
begin
  Form1.Caption := 'Finished moving and sizing';
end;


Solve 2:

Handle the WM_MOVING or WM_WINDOWPOSCHANGING message from windows, i.e.:

{ Private declarations }

procedure WMWINDOWPOSCHANGING(var msg: TWMWINDOWPOSCHANGING);
  message WM_WINDOWPOSCHANGING;

procedure TForm1.WMWINDOWPOSCHANGING(var msg: TWMWINDOWPOSCHANGING);
var
  r: TRect;
begin
  if ((SWP_NOMOVE or SWP_NOSIZE) and msg.WindowPos^.flags) <> (SWP_NOMOVE
    or SWP_NOSIZE) then
  begin
    { Window is moved or sized, get usable screen area }
    { Do something here }
  end;
  inherited;
end;

Nincsenek megjegyzések:

Megjegyzés küldése