我已经在我的应用程序中实现了双缓冲,使用下面的代码。 在病房之后,我发现我的孩子的窗户(即buttoms)没有像平常一样动画,所以我将WS_EX_COMPOSITED添加到我的父窗口,现在子窗口正确动画。但是,添加WS_EX_COMPOSITED后,我的资源创建的菜单为黑色,无法正常显示。
那么,如何在我的顶级菜单中添加双缓冲?
MainWinHwnd = CreateWindowEx(WS_EX_COMPOSITED, MainWinClassName, MainWinTitle,
WS_VISIBLE|WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SIZEBOX|WS_CLIPCHILDREN,
NULL, NULL, 609, 440, NULL, NULL, hInstance, NULL);
if (!MainWinHwnd) return FALSE;
case WM_PAINT:
{
RECT WinRt;
RECT TxtRt;
HFONT TxtFont = NULL;
SIZE TxtSize;
HDC WinDC = GetDC(hWnd);
GetClientRect(hWnd, &WinRt);
HDC WinBuffer = CreateCompatibleDC(WinDC);
HBITMAP BitBuffer = CreateCompatibleBitmap(WinDC, WinRt.right, WinRt.bottom);
SelectObject(WinBuffer, BitBuffer);
FillRect(WinBuffer, &WinRt, (HBRUSH) (COLOR_BTNFACE + 1));
SetBkColor(WinBuffer, GetSysColor((COLOR_BTNFACE)));
DrawThemeBackground(ButtonThemeData, WinBuffer, BP_GROUPBOX, GBS_NORMAL, &GroupOptionBox, NULL);
DrawThemeBackground(DragDropThemeData, WinBuffer, RP_GRIPPER, 0, &DragDropItem, NULL);
for (DWORD I = 0; I < sizeof(MainWinLabels) / sizeof(CustomLabel); I++)
{
if (MainWinLabels[I].Font == NULL)
{
TxtFont = CreateFontA(MainWinLabels[I].cFontHeight, NULL, NULL, NULL, FW_DONTCARE,
MainWinLabels[I].cFontItalic, MainWinLabels[I].cFontUnderline,
MainWinLabels[I].cFontStrikeOut, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
MainWinLabels[I].cFontQuality, DEFAULT_PITCH, MainWinLabels[I].cFontFaceName);
if (TxtFont == NULL) continue;
SelectObject(WinBuffer, TxtFont);
}
else SelectObject(WinBuffer, *MainWinLabels[I].Font);
SetTextColor(WinBuffer, MainWinLabels[I].Color);
TxtRt.left = MainWinLabels[I].X;
TxtRt.top = MainWinLabels[I].Y;
DrawTextA(WinBuffer, MainWinLabels[I].Text, strlen(MainWinLabels[I].Text), &TxtRt,
DT_LEFT|DT_SINGLELINE|DT_NOCLIP);
GetTextExtentPoint32A(WinBuffer, MainWinLabels[I].Text, strlen(MainWinLabels[I].Text), &TxtSize);
MainWinLabels[I].Width = TxtSize.cx;
MainWinLabels[I].Height = TxtSize.cy;
if (TxtFont != NULL) DeleteObject(TxtFont);
}
BitBlt(WinDC, 0, 0, WinRt.right, WinRt.bottom, WinBuffer, 0, 0, SRCCOPY);
ReleaseDC(hWnd, WinDC);
DeleteObject(BitBuffer);
DeleteDC(WinBuffer);
break;
}
答案 0 :(得分:0)
解决方案: