c++ - GDI+ Double Buffering: backbuffer dual-colored monochrome -


i trying build simple graphical app using c++, windows api , gdi+. when first trying build app, heavy flickering introduced, code tries use double buffering, fails. hdcbuf backbuffer.

when trying draw backbuffer using gdi+ graphics::drawcachedbitmap bitmap drawn dual-colored in black , white.

loadbitmapres creates cachedbitmap exe resources; function works single buffering.

is there wrong in code? in advance!

global:

cachedbitmap* fish; hdc hdc; hdc hdcbuf; hbitmap hbmpbuf; graphics* gfxbuf; 

wm_create:

hdc = getdc(hwnd); hdcbuf = createcompatibledc(hdc); hbmpbuf = createcompatiblebitmap(hdcbuf, 640, 480); selectobject(hdcbuf, hbmpbuf); gfxbuf = graphics::fromhdc(hdcbuf);  fish = loadbitmapres(gfxbuf, makeintresource(fish2), "sprite"); 

wm_paint:

hdc temp = beginpaint(hwnd, &ps); gfxbuf->drawcachedbitmap(fish, x, y); bitblt(temp, 0, 0, 640, 480, hdcbuf, 0, 0, srccopy); endpaint(hwnd, &ps); 

when creating memory dc using createcompatibledc display surface 1 monochrome pixel wide , 1 monochrome pixel high. consequently when calling createcompatiblebitmap on memory dc monochrome bitmap created.

since bitmap selected memory dc controls color characteristics, have make sure matches dc using display contents of memory dc. should pass destination dc createcompatiblebitmap.

corrected code:

hdc = getdc(hwnd); hdcbuf = createcompatibledc(hdc); hbmpbuf = createcompatiblebitmap(hdc, 640, 480); // uses source dc selectobject(hdcbuf, hbmpbuf); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -