Sign in to follow this  
Shock

Processing window messages from a seperate thread ( win32 )

Recommended Posts

Shock    140
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

Share this post


Link to post
Share on other sites
Shock    140
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

Share this post


Link to post
Share on other sites
JohnBSmall    881
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.
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

Share this post


Link to post
Share on other sites
LessBread    1415
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.

Share this post


Link to post
Share on other sites
Catafriggm    296
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this