Jump to content
  • Advertisement


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


GDI questions

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, a couple questions for all you gdi masters. 1. Double buffering? ---------------------- I have 2 HDC Variables in my code, like this: HDC g_hdcWindow = NULL; HDC g_hdcBackBuffer = NULL; I set the first one like this: g_hdcWindow = GetDC(g_hWnd); And the second like this: g_hdcBackBuffer = CreateCompatibleDC(g_hdcWindow); Then I blt my images to g_hdcBackBuffer (after selecting my bitmap objects into g_hdcMemory, of course): BitBlt (g_hdcBackBuffer, 0, 0, 10, 10, g_hdcMemory, 0, 0, SRCCOPY); Then after a couple more blts to the backbuffer, I do this BitBlt(g_hdcWindow, 0, 0, 50, 50, g_hdcBackBuffer, 0, 0, SRCCOPY); But it doesn''t seem to work. Any ideas?? 2. Meesage Pump? ---------------- In my program, I am doing some simple blts to the window, about 10 times a second, in a timer message in my message pump. My message loop code looks like this: PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE ); while (WM_QUIT != msg.message ){ if (PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE )){ if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } } I found this taking up 100% of my cpu. so I added this: } else{ Sleep(10); } } Which seemed to do the trick. Is this safe??? Thanks all, and sorry about the big post! Kevin

Share this post

Link to post
Share on other sites
Sure it's safe. The reason it's taking 100% of the CPU is because you are using PeekMessage(). You are never yielding, so you end up using 100% of each of your timeslices (before the OS preempts you). By calling Sleep(10), you are giving up the remainder of your current timeslice. Sleep(1) should do the trick too.

If that is exactly what your message pump looks like, then just use GetMessage(). It will sleep until you receive a message, and in your case would be slightly "safer" then Sleep(10), because it selectively Sleep()'s (only when you don't have any pending messages, otherwise it processes them as fast as possible).


Edited by - Brannon on December 16, 2001 4:43:07 AM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!