c - Processing WM_PAINT -


i have read many examples on internet i'm still stuck. i'm trying process wm_paint message sent application.

in application, draw in same dc, named g_hdc. works perfectly. when wm_paint received, try draw content of g_hdc dc returned beginpaint. guess g_hdc contains last bitmap drawn. want restore it.

case wm_paint:  paintstruct ps;   int ret;  hdc compatdc;  hdc currentdc;  hdc paintdc;  hbitmap compatbitmap;  hgdiobj oldbitmap;   paintdc   = beginpaint(g_hwnd, &ps);   currentdc = getdc(g_hwnd);  compatdc  = createcompatibledc(paintdc);  compatbitmap=createcompatiblebitmap(paintdc, config_window_width, config_window_height);  oldbitmap=selectobject(compatdc, compatbitmap);   ret = bitblt(compatdc,               ps.rcpaint.left,               ps.rcpaint.top,               ps.rcpaint.right - ps.rcpaint.left,               ps.rcpaint.bottom - ps.rcpaint.top,               currentdc,               ps.rcpaint.left,               ps.rcpaint.top,               srccopy);   ret = bitblt(paintdc,               ps.rcpaint.left,               ps.rcpaint.top,               ps.rcpaint.right - ps.rcpaint.left,               ps.rcpaint.bottom - ps.rcpaint.top,               compatdc,               ps.rcpaint.left,               ps.rcpaint.top,               srccopy);    deleteobject(selectobject(compatdc, oldbitmap));   deletedc(compatdc);  deletedc(currentdc);   endpaint(g_hwnd, &ps); 

break;

but draws white rectangle ... tried many possibilities , nothing works. can please me?

there number of things doing wrong.

first, saving g_hdc relying on implementation detail: notice pointers same, , save pointer. may work in short term variety of reasons related optimization on gdi's part (for instance, there dc cache), stop working eventually, when least convenient. or may tempted use dc pointer when don't have dc, , scribble on else (or fail due gdi object thread affinity).

the correct way access dc of window outside wm_paint calling getdc(hwnd).

createcompatibledc() creates in-memory dc compatible hdc. drawing compatdc not enough draw hdc; need draw hdc after draw compatdc. case, need have 2 bitblt() calls; second 1 blit compatdc onto hdc. see sample code details.

you cannot deleteobject() bitmap while have selected dc. selectobject(compatdc, oldbitmap) call needs come before deleteobject(compatbitmap). (this i486 trying @ in answer.)

(i'm sure answer misleading or incomplete in places; please let me know if is.)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -