• ### Announcements

#### Archived

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

# Page Flipping with Win32

## Recommended Posts

Hi. I want to set up a page flipping scheme for my Win32/GDI Tetris clone. I know I should be using DirectX but I''m not. Anyway, I''m assuming that I would do something like this:
HDC WindowDC = GetDC(hwnd);
HDC OffscreenDC = CreateCompatibleDC(WindowDC);

And, assuming that the display is 640 x 480, I can simply blit everything to OffscreenDC, and when the frame is complete, blit the OffscreenDC to WindowDC as follows:
BitBlt(WindowDC, 0, 0, 640, 480, OffscreenDC, 0, 0, SRCCOPY);

Is this correct? If so, I have one question: how does CreateCompatibleDC know what size (in this case, 640x480) to make the surface? Does it make a DC the same exact size as WindowDC? If so, then what about the memory DC''s I make for smaller bitmaps? Are they all 640x480 as well, therefore containing thousands of wasted, unused bytes? I''m confused.

##### Share on other sites
there is no surface associated with a DC. you need to create and select a bitmap into your memory DC and use that as your drawing target. blitting from the memory DC to the display DC will then cause the pixels from the memory bitmap to be copied to the display.

fwiw, you probably don''t want to blit the whole bitmap except under OS requested re-paint conditions. instead, you should only blit those portions of your bitmap that change. the dirty rectangle technique is one such way to achieve this.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627671
• Total Posts
2978551

• 11
• 10
• 10
• 12
• 22