Home > Software engineering >  WINAPI - how to correctly use double buffer to redraw?
WINAPI - how to correctly use double buffer to redraw?

Time:01-23

Continue to do interface, after the last time for child Windows, although can move, but move is very unnatural, the splash screen is very serious, and the WM_PAINT, window drawing method, and when the window is too much, the program is likely to enter infinite loop eventually collapse, put a few picture:
1. The program crashes

2. Double buffer error using the

3. The expected effect

Then hear double buffer drawing can effectively improve the efficiency, and prevent many bugs, so I want to use double buffer try:
 void Draw_Panel (HDC& Hdc_old, HWND HWND PAINTSTRUCT& Ps, the RECT rc, TCHAR TXT [40], HFONT HFONT, LOGFONT lf) 
{
HBRUSH gets=NULL;
HPEN HPEN=0;
HPEN HPF=0;
HDC HDC=CreateCompatibleDC (hdc_old);
Gets=CreateSolidBrush (UICOLOR_PANEL);
SelectObject (HDC, gets);
FillRect (HDC, & amp; Rc, gets);

DeleteObject (gets);

GetWindowText (hWnd, TXT, 40);
SetTextColor (HDC, UICOLOR_BUTTON_TEXT);
SetBkMode (HDC, TRANSPARENT);
If (hFont==0)
{
Memset (& amp; Lf, 0, sizeof (LOGFONT));
Lf. LfHeight=- 16;
Wcscpy (lf) lfFaceName, L "bold");
HFont=CreateFontIndirect (& amp; Lf);//create the font
}
HFONT old=(HFONT) SelectObject (HDC, HFONT);

DrawText (HDC, TXT, wcslen (TXT), & amp; Rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

DrawFramePanel (HDC, hpen, rc, 2, UICOLOR_PANEL_FRAME);

BitBlt (hdc_old, 0, 0, rc. Right, rc. Bottom, HDC, 0, 0, SRCCOPY);
DeleteObject (hpen);
//UpdateWindow (hWnd);


DeleteDC (HDC);
ReleaseDC (hWnd, HDC);
OutputDebugStringA (TIPBOX_PANEL "PAINT");
}

 case WM_PAINT: 
{
HDC=BeginPaint (hWnd, & amp; Ps);
Memset (& amp; Lf, 0, sizeof (LOGFONT));
VertexUI_Draw_Panel (HDC, hWnd, ps, rc, TXT, hFont, lf);
EndPaint (hWnd, & amp; Ps);
break;
}
Case WM_ERASEBKGND:
{
return 1;
}

But I must be doing wrong steps, so draw something is pure white, does not display, can you tell me where the fault is, thank you
  • Related