views:

58

answers:

1

I've successfully registered a window class using RegisterClassEx and created a window using CreateWindowEx:

m_hInstance = ::GetModuleHandle(NULL);
...
m_hWnd = ::CreateWindowEx(0, "CMyClassName", "Message Window", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, m_hInstance, 0);

The associated window procedure receives messages 36, 129, 131, and 1, and the returned HWND is not null. However, when I later call PostMessage (from another thread):

bool bPosted = ::PostMessage(m_hWnd, WM_APP + 3, 0, 0);

even though bPosted is true, the window procedure isn't called. I'm trying to work out why that should be. The window procedure is the one from the MSDN example - I'd intented to add another case once I'd confirmed the messages were getting through.

What conditions need to be fulfilled for a window message to be posted?

+1  A: 

There are no conditions.

Some constraints exist when using messages [0, WM_USER) but none over WM_APP.

Are you checking the return code of PostMessage?

You should probably post (at least some of) the code you're using to PostMessage, as well as the registered WndProc.

You also have to provide a message loop, if you are not doing so. Most frameworks will hide this detail (at least somewhat), but if you're dealing with win32 directly you have to provide your own.

Kevin Montrose
I've updated the question in reply to some of your concerns
Simon
The WndProc is probably important here. I guess the message loop as well, if just for completeness.
Kevin Montrose
I've added a link to the wndproc code I used. Do I need to write a message loop? I already received the four messages I described, so I assumed there was a message loop running.
Simon
Not knowing the details of the rest of your code, maybe. Its pretty basic boilerplate so it shouldn't be too rough to just try it. I've added a link to a relevant MSDN article.
Kevin Montrose
Yep, it was the message loop that I lacked. Thanks!
Simon