Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: Detect start and end of window move

Tags:

window

delphi

I'm using the OnIdle-event for some simple animations, and it works all right. The trouble, though, is when the user starts to move or resize the window, the OnIdle-event stops firing until the move/resize-operation is completed.

I need to detect when this happens, so that I can pause all animations. But how do I detect movement of the window?

like image 296
Vegar Avatar asked May 05 '09 20:05

Vegar


2 Answers

I'd go with mghie comment : use a timer for the animation, and activate/deactivate it with message handlers.

In your case, you may want to add the following message handlers :

//fired when starting/ending a "move" or "size" window
procedure WMEnterSizeMove(var Message: TMessage) ; message WM_ENTERSIZEMOVE;
procedure WMExitSizeMove(var Message: TMessage) ; message WM_EXITSIZEMOVE;


  procedure TForm.WMEnterSizeMove(var msg: TMessage);
  begin
    AnimationTimer.Enabled := false;
    inherited;
  end;

  procedure TForm.WMExitSizeMove(var msg: TMessage);
  begin
    AnimationTimer.Enabled := true;
    inherited;
  end;
like image 158
LeGEC Avatar answered Nov 11 '22 01:11

LeGEC


I haven't tried this, but I'd say you could probably use WM_WINDOWPOSCHANGING to tell when the window is being moved. http://msdn.microsoft.com/en-us/library/ms632653(VS.85).aspx

Delphi code would be:

TSomeForm = class(TForm)
protected
  ...
  procedure WindowPosChanging(var Msg : TMessage); message WM_WINDOWPOSCHANGING;
  ...
end;
like image 45
Kroden Avatar answered Nov 11 '22 01:11

Kroden