getting HWND and message loop without a window

Started by
11 comments, last by xyuri 18 years, 4 months ago
I am wanting to process messages and such, but, dont want a window. Is this possible? Considering the message loop is tied to a HWND, and HWND is a window handle... Any input is appreciated, thanks :)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Advertisement
I've never tried it but it seems that the message loop is tied to the window class you register, not the handle. So maybe you can leave out CreateWindow().

ace
Use PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) to create a message queue for the thread, then use PostThreadMessage using the thread ID to send the messages
You could create a window and not pass the VISIBLE flag to it or call ShowWindow(), then run the message loop.
Thanks for that fella's, I'm still getting used to windows programming with the api's :)

Could have sworn that when i tried the message loop without creating a window last time that it didnt work, but this time it is working... need to look into this a bit more.

Thanks again :)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Quote:Original post by ace_lovegrove
I've never tried it but it seems that the message loop is tied to the window class you register, not the handle. So maybe you can leave out CreateWindow().


Actually, the WndProc is tied to the window class. The message loop is tied to the thread. AP pointed in the right direction - PeekMessage and PostThreadMessage.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by Anonymous Poster
Use PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) to create a message queue for the thread, then use PostThreadMessage using the thread ID to send the messages


That was me. Anyways, this works well in multithreaded environments, or if your only using a single thread, you can still use GetCurrentThreadId to get your main thread's ID.

-D
From MSDN:

Message-Only Windows
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.

To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both the hwndParent and hwndChildAfter parameters are NULL.
Quote:Original post by Bezben
From MSDN:

Message-Only Windows
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.

To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both the hwndParent and hwndChildAfter parameters are NULL.


Thank you Bezben :) Simply changing this value worked a treat. For some reason, it worked on one case but not another... wierd. (I made a copy of the app for testing, and for each timer tick wrote something to a text file, but useing the method mentioned in this post, it did not work.)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
message only windows dont work in win versions other than 2k xp and newer

threads each have their own message queque, and it works even on win 95 or maybe even earlier (there are still win ver 3.x tutorials on msdn...lol)

This topic is closed to new replies.

Advertisement