OWL NExt - Knowledge Base

[ Home | Contents | Search | Next | Previous | Up ]

Moving a dialog box

Date: 11/30/99
Time: 1:07:43 AM


Q. What message is sent when you move a dialog box by grabbing it from the title bar and moving it ?
I would like to invalidaterect on the entire client area. But I'm also wondering if I do it on some dialog move command, can I avoid a series of Invalidates? I imagine I could probably flag the first move, but I will have a bunch of messages or will it be consolidated like paint?

A. Caveat - never tried this with TDialog, only TWindow derived classes, but seeing as they are related and Windoze does a lot of the work anyway, here goes...

> What message is sent when you move a dialog box by
> grabbing it from the title bar and moving it ?

Windoze sends a WM_NCHITTEST msg to the window to test for where in the non-client window area (basically the title bar and frame) the mouse down was. I let TWindow handle this, then test the return value for HTCAPTION. If you get this, Windoze takes over mouse message handling to move the widow around for you. It is here that I believe you should call InvalidateRect(). Note that this is also where you stop the using being able to move your window, by changing HTCAPTION to HTNOWHERE.

The other possibility is to capture EV_WM_WINDOWPOSCHANGED messages.
>From the help file : EV_WM_WINDOWPOSCHANGED
void EvWindowPosChanged( WINDOWPOS far &windowPos );

This is called when (quote from Win32 Help):
The WM_WINDOWPOSCHANGED message is sent to a window whose size,
position, or place in the Z order has changed as a result of a call to
the SetWindowPos function or another window-management function.

You may need to verify that you have moved x or y rather than Z-order or
size. Also note that if you have 'full window drag' enabled then you
will get lots of these messages (one each time the window is re-drawn
during the drag)!

> I would like to InvalidateRect() on the entire client
> area. But I'm also wondering if I do it on some dialog
> move command, can I avoid a series of Invalidates?
> I imagine I could probably flag the first move,
> but I will have a bunch of messages or will it
> be consolidated like paint?

Actually, InvalidateRect() updates the stored 'dirty' region for the
window and sends a paint message if this has changed. Therefore you can
happily call InvalidateRect several times and the paint message will be
delayed as you rightly mention (until there are no other messages in the
queue, I believe). You will get a slight hit for the check on the rect,
the other approach is to track when you have finally done the paint.

Hmm, hope that helps...

Mark Cooke

Last changed: July 14, 2001