while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// process the messenger
messenger.Process();
}
}
It seems the line which says messenger.Process() is never reached. Why is this?... Its only reached if I put that line before the while loop and then put this within the process()method: PostMessage(hwnd,RANDOM_ID,0,0); This seems to allow Process to be called, but I know this is wrong and is not the way to do it. This method also seems to disrupt the "focus" on other application windows.
Any help is appreciated
DarkStar
UK
-------------------------------
Loves cross-posting because it works
Drawing onto the screen rather than a window
Hi Guys Im trying to draw onto the screen using GDI and not the window, I am doing this by getting the hdc from a NULL hwnd, like so:
HDC hdc = GetDC(NULL);
when i draw using that hdc, using GDI commands, it works but it requires that the application''s window is showing. I want my app to run as a system tray icon which it does, but it only draws graphics when its application window is showing.
When I hide the window, no graphics gets shown even though Im drawing to the hdc acquired using the above code.
Another question is how do I process my program during a windows message loop here''s the loop:
I don''t know about your DC problem, but I *suspect* there are nicer ways than GetDC(NULL). You might want to dig around on msdn.microsoft.com.
GetMessage() may be the cause of your message loop woes; it blocks until it actually gets a message. If you want your processing to be done all the time you should replace GetMessage() with PeekMessage().
GetMessage() may be the cause of your message loop woes; it blocks until it actually gets a message. If you want your processing to be done all the time you should replace GetMessage() with PeekMessage().
read up on what GetMessage does when the event stack is empty. I''m thinking it returns 0.
capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5
capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5
It will block; from the MSDN:
"Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning."
Which is not the clearest way to put it, but whatever.
The idea being that for "typical" applications (i.e., not games) if you have no messages pending, you need no processing time, so your process is blocked until you get a message so that other programs get some time.
"Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning."
Which is not the clearest way to put it, but whatever.
The idea being that for "typical" applications (i.e., not games) if you have no messages pending, you need no processing time, so your process is blocked until you get a message so that other programs get some time.
Yes, GetMessage will block if no messages are coming to your window, which is likely to happen if the window is not shown.
The "normal" way to do something like this would be to make a separate thread for your graphics work, which will separate it from the message processing loop, using CreateThread().
The PeekMessage thing is also doable, but unless you put a delay in that loop it will use a lot of CPU time as it loops as fast as it can. And if you put a delay inside, it limits the message handling capability of the application, which may or may not be a problem for you depending on the rest of your code.
GetDC(NULL) is a fine way to get access to the screen, in most cases.
The "normal" way to do something like this would be to make a separate thread for your graphics work, which will separate it from the message processing loop, using CreateThread().
The PeekMessage thing is also doable, but unless you put a delay in that loop it will use a lot of CPU time as it loops as fast as it can. And if you put a delay inside, it limits the message handling capability of the application, which may or may not be a problem for you depending on the rest of your code.
GetDC(NULL) is a fine way to get access to the screen, in most cases.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement