Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserve painted client area between calls to WM_PAINT in win32
    primarykey
    data
    text
    <p>I am trying to paint(draw) text on the client area on a window in response to some event(not in the <code>WM_PAINT</code> message), so how can I preserve the state of the client area between calls to <code>WM_PAINT</code>? I understand that every time there is a <code>WM_PAINT</code> message(or window refreshes) the window gets redrawn and everything out side <code>WM_PAINT</code> doesn't matter anymore. I think I will be able to communicate better with code, so here is what I have now.</p> <pre><code>HDC mdc; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { LoadBitmap(...); // for skinning the app. stuff.. } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { case WM_PAINT: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &amp;ps); BITMAP bm; HDC dcSkin = CreateCompatibleDC(hdc); GetObject(hSkinBmp, sizeof(bm), &amp;bm); SelectObject(dcSkin, hSkinBmp); BitBlt(dcSkin, 0, 0, wWidth, wHeight, mdc, 0, 0, SRCCOPY); BitBlt(hdc, 0, 0, wWidth, wHeight, dcSkin, 0, 0, SRCCOPY); DeleteDC(dcSkin); EndPaint(hwnd, &amp;ps); break; case WM_LBUTTONDOWN; HDC hdc = GetDC( hwnd ); mdc = CreateCompatibleDC( hdc ); LPRECT rect; GetClientRect( hwnd, rect); SelectObject( mdc, CreateCompatibleBitmap( hdc, rect-&gt;right, rect-&gt;bottom ) ); BitBlt( mdc,0,0,rect-&gt;right,rect-&gt;bottom,hdc,0,0,SRCCOPY ); HFONT hfont = CreateFont( 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_SWISS , 0 ); HFONT hOldFont = (HFONT)SelectObject( mdc, hfont ); SetTextColor( mdc, RGB(255,0,0) ); SetBkColor( mdc, RGB(255,255,0) ); TextOut( mdc, 50, 150, logintext.c_str(), strlen( logintext.c_str() ) ); SelectObject( mdc, hOldFont ); ReleaseDC( hwnd, hdc); InvalidateRect( hwnd, 0, TRUE ); break; } </code></pre> <p>As you can see, I have to paint the client area of the window with a bmp, then when mouse button down message comes, I have to output some text on top of the skinned client area. What I am doing is saving the memory dc created in the <code>WM_LBUTTONDOWN</code> message and trying to paint the window dc first with the dc for skin then the dc for text(memory dc created in <code>WM_LBUTTONDOWN</code>).</p> <p>The skin bitmap show as it is supposed to, but the Text doesn't.</p> <p>How do I achieve this ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload