Size/move loop and delay in DefWindowProc

Started by
20 comments, last by MicroVirus 12 years, 12 months ago
This problem happens even if you create a timer at window-creation. I've always wondered why..
It doesn't happen if you start dragging the window right away, moving the mouse already when you click. It also pauses if you hold down the button on the minimize button for example. I think all such things are handled in some loop that doesn't return, except for that once the window starts moving it returns to allow for interactive moving.
Don't know why it waits 500 ms before returning unless the mouse moves.. the reply about double-clicking sounds plausible to me..
It also freezes if you hold down the right mouse-button in the title bar.
Advertisement
Quote:Original post by Evil Steve
Hmm, it's possible - but still seems a bit ugly to me. This is beginning to look like the only option though...


I create the timer the first time WM_MOVING is reached, and remove the timer when WM_EXITSIZEMOVE is reached. This doesn't help with the delay though. There is about a 500ms delay between the time the user clicks the title bar and I receive SC_MOVE + HTCAPTION. During this time the window stops updating.
Quote:Original post by lordikon
I create the timer the first time WM_MOVING is reached, and remove the timer when WM_EXITSIZEMOVE is reached. This doesn't help with the delay though. There is about a 500ms delay between the time the user clicks the title bar and I receive SC_MOVE + HTCAPTION. During this time the window stops updating.
Yep, it's that 500ms delay that I'm trying to avoid.
I'm also fairly interested in this solution. I wish I could help, but after some research I found no answers either.
So, it appears you've been having this problem for awhile. :D

http://www.gamedev.net/community/forums/topic.asp?topic_id=440341
Quote:Original post by lordikon
So, it appears you've been having this problem for awhile. :D

http://www.gamedev.net/community/forums/topic.asp?topic_id=440341
Yeah, I found that post while Googling, but decided not to necro the thread [smile]
Here is a quick workaround. Note that this has the little quirk of setting the cursor position to the middle of the window's caption. Also, if the app has other windows and he starts dragging them, the problem remains. Also, the delay will remain if the window is sizable and the user [EDIT: referred to in the previous sentence as "he"] clicks on the borders to resize it. Also, this will effectively disable double-clicking the title bar to maximize the window. Plus possibly a few more things I haven't thought about yet.

case WM_NCLBUTTONDOWN:		if( SendMessage( hWnd, WM_NCHITTEST, wParam, lParam ) == HTCAPTION )		{			SetTimer( hWnd, 1000, 0, NULL );			SendMessage( hWnd, WM_SYSCOMMAND, SC_MOVE, 0 );			return 0;		}		break;	case WM_TIMER:		Render();		break;	case WM_EXITSIZEMOVE:		KillTimer( hWnd, 1000 );		break;


But personally I would recommend against messing with this because, well, you're just nitpicking one of Windows' insignificant quirks. That's not patriotic!

[Edited by - hikikomori-san on January 15, 2009 10:47:56 AM]
Just found this: http://developer.popcap.com/forums/showthread.php?p=19636

They mention the same delay problem.
Quote:Original post by lordikon
Just found this: http://developer.popcap.com/forums/showthread.php?p=19636

They mention the same delay problem.
Yes, I've been through Google. I've found plenty of reports of the problems, but no solutions.

Quote:Original post by hikikomori-san
Here is a quick workaround. Note that this has the little quirk of setting the cursor position to the middle of the window's caption. Also, if the app has other windows and he starts dragging them, the problem remains. Also, the delay will remain if the window is sizable and the user [EDIT: referred to in the previous sentence as "he"] clicks on the borders to resize it. Also, this will effectively disable double-clicking the title bar to maximize the window. Plus possibly a few more things I haven't thought about yet.
Hmm, I'll give that a go later tonight, thanks.
Quote:Original post by hikikomori-san
Here is a quick workaround. Note that this has the little quirk of setting the cursor position to the middle of the window's caption. Also, if the app has other windows and he starts dragging them, the problem remains. Also, the delay will remain if the window is sizable and the user [EDIT: referred to in the previous sentence as "he"] clicks on the borders to resize it. Also, this will effectively disable double-clicking the title bar to maximize the window. Plus possibly a few more things I haven't thought about yet.
This seems to work pretty well, with a bit of an ajustment:
LRESULT D3DWindow::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam){static bool sbMoving = false;static POINT sptOffset;	switch(uMsg)	{	case WM_NCLBUTTONDOWN:		if(SendMessage(m_hWnd, WM_NCHITTEST, wParam, lParam) == HTCAPTION)		{			POINT ptCursor;			RECT rcWnd;			GetWindowRect(m_hWnd, &rcWnd);			GetCursorPos(&ptCursor);			sptOffset.x = ptCursor.x - rcWnd.left;			sptOffset.y = ptCursor.y - rcWnd.top;			SetCapture(m_hWnd);			sbMoving = true;			return 0;		}		break;	case WM_NCLBUTTONUP:	case WM_LBUTTONUP:		sbMoving = false;		ReleaseCapture();		break;	case WM_MOUSEMOVE:	case WM_NCMOUSEMOVE:		if(sbMoving)		{			POINT ptCursor;			RECT rcWnd;			GetWindowRect(m_hWnd, &rcWnd);			GetCursorPos(&ptCursor);			SetWindowPos(m_hWnd, NULL, rcWnd.left+(ptCursor.x-(rcWnd.left+sptOffset.x)),				rcWnd.top+(ptCursor.y-(rcWnd.top+sptOffset.y)), 0, 0, SWP_NOZORDER | SWP_NOSIZE);		}		break;	}	return DefWindowProc(m_hWnd, uMsg, wParam, lParam);}

I dread to think what horrible bugs this will cause though, so I think I'm just going to use the method with the 500ms delay for this, and add the above method as an alternative.
Another issue is that the user can still access the system menu of the window (Which will cause a stall), and select "Move" from there - which will stall. The second issue can be fixed with the timer as before, but probably not the stall when selecting the system menu.

Thanks for all the replies,
Steve

This topic is closed to new replies.

Advertisement