Sign in to follow this  
xyuri

getting HWND and message loop without a window

Recommended Posts

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 :)

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
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 :)

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
so PeekMessage PostThreadMessage can be used by threads without having to create a window? Does the WINAPI WinMain create a thread automatically?

Share this post


Link to post
Share on other sites
Technically speaking, WinMain usally isn't the entry point of a Windows program. When a program is executed, the Windows kernel creates the initial thread for the program and jumps into its entry point, which is usually a function in the c runtime which after setting up internals calls WinMain.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mastaba
Technically speaking, WinMain usally isn't the entry point of a Windows program. When a program is executed, the Windows kernel creates the initial thread for the program and jumps into its entry point, which is usually a function in the c runtime which after setting up internals calls WinMain.


How can you get a handle to the application's thread then? cos i have seen a few windows functions which require you to supply a thread.

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