Archived

This topic is now archived and is closed to further replies.

Drawing onto the screen rather than a window

This topic is 5227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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().

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

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

Share on other sites
Call CreateDC("DISPLAY", NULL, NULL, NULL); to get a screen device contest.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 17
• 10
• 14
• 10
• Forum Statistics

• Total Topics
632660
• Total Posts
3007694
• Who's Online (See full list)

There are no registered users currently online

×