Processing window messages from a seperate thread ( win32 )
Hello there!
I am trying to process the messages for a window in a seperate thread. I create the window in my main thread.
Does anyone know how I could possibly do this?
I need the stuff WM_CHAR, WM_MOUSEMOVE, etc... provide in my second thread.
Thanks
Try passing the HWND to the thread as the thread parameter and set up the message loop in the thread function.
Thanks for the reply LessBread,
I should of been more specific. I have tried passing the handle, but everytime I call PeekMessage() with my main window handle I just get a "hourglass" cursor and my window doesn't respond to anything.
- Shock
I should of been more specific. I have tried passing the handle, but everytime I call PeekMessage() with my main window handle I just get a "hourglass" cursor and my window doesn't respond to anything.
- Shock
I'm not certain, but I don't think you're allowed to do that. Afaik, message queues are per-thread, and you can't get at messages for a window created in thread A by calling functions in thread B. I may be wrong, but if not, you'll have to think of another way to do what you want.
I'm trying to find confirmation on MSDN at the moment.
Edit: Confirmed.
Emphasis mine. Same thing in the PeekMessage documentation.
John B
I'm trying to find confirmation on MSDN at the moment.
Edit: Confirmed.
Quote:From the MSDN documentation of GetMessage:
hWnd
[in] Handle to the window whose messages are to be retrieved. The window must belong to the calling thread. The NULL value has a special meaning: ...
Emphasis mine. Same thing in the PeekMessage documentation.
John B
What JohnBSmall wrote makes sense. CreateWindowEx sends a couple of messages to the WndProc - most noteably WM_CREATE - and I've read in other places that a window belongs to the thread that created it. So, move the call to CreateWindowEx to the thread function. In this light consider that WinMain is just a specialized thread function.
Technically, there are no such things as window message queues, only thread message queues. The window the message is for is just an HWND field in the message that allows the system to search for the first message in the thread's queue which is for that window. Any time messages get sent "to windows", it's just posting the message to the window's thread's message queue.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement