Sign in to follow this  
Josian

Keeping things moving during Win32 Move/Resize events

Recommended Posts

Josian    128
 
Hi everybody.
 
As many of you will know, windows move/resize events use their own message pumps, effectively blocking the host application until the operation has completed.
To keep animations running in the background we have to use SetTimer/KillTimer to keep things ticking over.
 
This works well, except for when the user mouse-downs on a window caption without moving the mouse.
In this case there's an annoying 500ms delay right after windows sends a WM_SYSCOMMAND with (SC_MOVE|HTCAPTION). 
 
These upstanding citizens on gamedev.net noticed that the handler was waiting (WaitForSingleObject style) for a mouse/keyboard message to come in...
 
Magically, if we push a mouse-move message into the queue just before syscommand comes in, everything just works:
 
switch (msg) {
	case WM_NCLBUTTONDOWN:
		if (SendMessage(hWnd, WM_NCHITTEST, wParam, lParam) == HTCAPTION) {
			POINT point;
			GetCursorPos(&point);
			ScreenToClient(hWnd, &point);
			PostMessage(hwnd, WM_MOUSEMOVE, 0, point.x | point.y << 16);
		}
		break;
	case WM_ENTERSIZEMOVE:
		SetTimer(hWnd, 1, 0, NULL);
		return 0;
	case WM_EXITSIZEMOVE:
		KillTimer(hWnd, 1);
		return 0;
	case WM_TIMER:
		UpdateAndRedraw()
		return 0;
	case ...
}

 

There must be some other people out there as anal/petty as I am... biggrin.png

Edited by Josian

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this