Archived

This topic is now archived and is closed to further replies.

Simple Windows message question.

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a WindowsEngine class, with WndProc outside of it (so it is unfortunately global). Well, I want to handle messages outside of WndProc and in the class, so I set up my own message handling function. The weird thing is, after I translate the message, and check the "message" component of it for WM_CLOSE, for example, it never ever registers that the message is WM_CLOSE. Right after I check, I send the very same message to WndProc with DispatchMessage, and it does register the message to be WM_CLOSE. I use OutputDebugString to see if it was received. This is where I check for the message...
void CWindowsEngine::HandleInternals()
{
	if (m_Status == ES_OK)
	{
		MSG WindowsMsg;

		while (PeekMessage(&WindowsMsg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&WindowsMsg);
			switch (WindowsMsg.message)
			{
			case WM_CLOSE:
				{
					OutputDebugString("*****WM_CLOSE received in HandleInternals*****\n");
				}
			case WM_DESTROY:
				{
					OutputDebugString("*****WM_DESTROY received in HandleInternals*****\n");
				}
			}
			DispatchMessage(&WindowsMsg);
		}
	}
}
 
And this is WndProc...
long CALLBACK WndProc(HWND hWnd, unsigned int Message, WPARAM wParam, LPARAM lParam)
{
	switch (Message)
	{
	case WM_CREATE:
		{
			return 0;
		}
	case WM_CLOSE:
		{
			OutputDebugString("*****WM_CLOSE received in WndProc*****\n");
			return 0;
		}
	case WM_DESTROY:
		{
			OutputDebugString("*****WM_CLOSE received in WndProc*****\n");
			return 0;
		}
	default:
		{
			return DefWindowProc(hWnd, Message, wParam, lParam);
		}
	}
} 
I hope the formatting isn''t messed up... I call WindowsEngine::HandleMessages every frame.

Share this post


Link to post
Share on other sites
The same happens if I check the message after it is sent to WndProc... it''s "message" component isn''t the same as it is in WndProc. Does anyone know why?

Share this post


Link to post
Share on other sites
Hmm... that doesn't work eiher. Maybe the message is changed by DispatchMessage internally?

Well, either way, I looked at the macro for LOWORD, and I don't quite understand part of it. Here it is...

#define LOWORD(l)           ((WORD)((DWORD_PTR)(l) & 0xffff))   



I beleive it is performing a bitwise & of the value you specify and 2^16-1, or 65535, then casting it do a DWORD (a DWORD_PTR is a DWORD, and a DWORD is an unsigned long), then casting that to a WORD (which is an unsigned short). My question is... why & it by 65535? In case a float is given? But casting to an unsigned long would get rid of the floating part, right?

[edited by - PlayGGY on November 29, 2003 10:10:55 PM]

[edited by - PlayGGY on November 29, 2003 10:43:09 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Invader X
LOWORD unsets all but the first 16 bits (that's what the AND does) and returns an unsigned short.


Colin Jeanne | Invader's Realm


Yeah, but isn't casting to an unsinged short doing the same thing? I don't see what the & is for, considering the bits would be chopped off anyways. Anyways, thanks a lot for your help.



[edited by - PlayGGY on November 29, 2003 11:48:18 PM]

[edited by - PlayGGY on November 29, 2003 11:48:26 PM]

Share this post


Link to post
Share on other sites
Some messages are sent internally by DefWindowProc and you wont see them in the message pump.

One way to get a WM_CLOSE is when the user clicks the X on the top right corner. In the pump you''ll see only (guessing here: WM_NCLBUTTONDOWN/UP) which DefWindowProc will translate to WM_CLOSE and if that''s not handled by you followed by WM_DESTROY and so on...

Share this post


Link to post
Share on other sites
quote:
Original post by Endurion
Some messages are sent internally by DefWindowProc and you wont see them in the message pump.

One way to get a WM_CLOSE is when the user clicks the X on the top right corner. In the pump you'll see only (guessing here: WM_NCLBUTTONDOWN/UP) which DefWindowProc will translate to WM_CLOSE and if that's not handled by you followed by WM_DESTROY and so on...





Oh... that explains it!

EDIT: OK, I don't expect any more replies now, but the message parameter of WndProc is WM_CLOSE, so it has its message identifier after it is "dispatched", while in WndProc, but outside of it. And, like I said, the LOWORD macro doesn't work. I think I have a way around this, though, but it is pretty messy.



[edited by - PlayGGY on November 30, 2003 1:00:49 PM]

[edited by - PlayGGY on November 30, 2003 3:43:50 PM]

Share this post


Link to post
Share on other sites