9

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?

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Vegar
  • 12,828
  • 16
  • 85
  • 151
  • 5
    Using OnIdle is not really a good idea, as it will cause 100% cpu load on the active core. Use a timer event instead, which has two advantages: It will fire in the secondary message loop as well, so animation continues during move/resize (which it should when full window dragging is active); and you will be able to set a sensible number of animation steps per second, regardless of system speed. – mghie May 06 '09 at 04:33
  • Timer vs idle is an interesting topic. Both have pros and cons, but for my small decorative animations, onidle will do just fine. – Vegar May 06 '09 at 11:09
  • Such "small decorative animations", if $user can't disable them, can cost a lot of battery time on a laptop. Also, you're actively stealing cpu cycles from other applications. Try it for yourself, in reality OnIdle has only cons. – mghie May 06 '09 at 14:20
  • I made this a separate question, so if you like, you could state your point there. I can see your point about cpu-use on netbooks though. I have to change two lines of code to use a timer instead of the onidle-event so there is no big deal for me :-) – Vegar May 06 '09 at 15:58
  • Timer vs Idle: http://stackoverflow.com/questions/829135/animation-timer-vs-idle – Vegar May 06 '09 at 15:59

2 Answers2

12

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;
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • 1
    I will check out those two messages later to day. I did not know about them before. Thanks. – Vegar May 06 '09 at 10:58
  • @LeGEC: But why disable the animation at all? It doesn't interfere with the moving / sizing, and matches full window dragging if enabled. – mghie May 06 '09 at 14:23
4

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;
Kroden
  • 81
  • 2