Public Group

Archived

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

Simple Windows message question.

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

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:
{
}
case WM_DESTROY:
{
}
}
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:
{
return 0;
}
case WM_DESTROY:
{
return 0;
}
default:
{
return DefWindowProc(hWnd, Message, wParam, lParam);
}
}
} 
I hope the formatting isn''t messed up... I call WindowsEngine::HandleMessages every frame.

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 on other sites
You should probably only be testing the low word of MSG::message.

quote:
From the MSDN, on struct MSG
message
Specifies the message identifier. Applications can only use the low word; the high word is reserved by the system.

Share on other sites
So, would that be the first 16 bits (Meaning from the 1 bit to the 2^16-1 bit)?

Share on other sites
Casting to a short isn''t working either...

Share on other sites
Use the LOWORD macro. For reference purposes there is also a HIWORD macro.

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 on other sites
LOWORD unsets all but the first 16 bits (that''s what the AND does) and returns an unsigned short.

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

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 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...

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 76
• 11
• 10
• 14
• Forum Statistics

• Total Topics
632968
• Total Posts
3009584
• Who's Online (See full list)

There are no registered users currently online

×