I try to use a method to save the DC, so that it only needs to call drawfun once when it is created, and directly recover from the memory DC at other times
int dystate = 1;
void CreatePanelDynamic(HWND h, HDC hdc, DRAWPANEL DrawFun, int Flag = 0)
{
if (PanelID == PrevPanelID)
{
if (dystate == 0)
{
RECT rc;
GetClientRect(h, &rc);
HDC hMemDC;
HBITMAP hBmpMem;
HBITMAP hPreBmp;
hMemDC = CreateCompatibleDC(hdc);
hBmpMem = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
hPreBmp = (HBITMAP)SelectObject(hMemDC, hBmpMem);
BitBlt(hMemDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, inhdc, 0, 0, SRCCOPY);
BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hPreBmp);
DeleteObject(hBmpMem);
DeleteDC(hMemDC);
}
if (dystate == 1) {
HBITMAP hBmpMem;
HBITMAP hPreBmp;
RECT rc;
GetClientRect(h, &rc);
inhdc = CreateCompatibleDC(hdc);
hBmpMem = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
hPreBmp = (HBITMAP)SelectObject(inhdc, hBmpMem);
DrawFun(h, inhdc);
BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, inhdc, 0, 0, SRCCOPY);
SelectObject(inhdc, hPreBmp);
DeleteObject(hBmpMem);
dystate = 0;
}
anistat = 0;
}
}
But the fact is that except for the first time, when dystate = 0, the whole window turns black and nothing is drawn.
What is the problem and how to solve it? thank you.
What I have tried:
Does it needs to store a HBITMAP?I don't know.