我的菜单的双重缓冲
Double buffering for my Menu
我使用以下代码在我的应用程序中实现了双缓冲。在病房之后,我发现我的子窗口(即屁股)没有像正常那样进行动画处理,所以我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;
}
解决方案:
- 请勿使用WS_EX_COMPOSITED。
- 不使用 GetDC(hWnd) 使用 BeginPaint(hwnd, &ps) 和 EndPaint(hwnd, &ps)
相关文章:
- 无法获取菜单选择以运行函数.C++
- 如何使用原子指针执行双缓冲
- 消费者和生产者问题的双重缓冲
- C++ 中的图形菜单
- C++ 程序菜单使用做同时和切换
- 我正在尝试创建一个菜单,但我的代码一直在循环
- 如何检测是否在缓冲绘画动画中绘制最后一帧?
- 我似乎无法修改帧缓冲
- 如何在C++中写入 1000 个文件时有效地缓冲
- 触发另一个窗口的菜单按钮
- 从子菜单返回后,正确的输入至少进入验证循环一次
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 如何为我的游戏设置主菜单场景?QT C++
- C++循环菜单时做
- 难以从 CImageList 设置菜单项位图
- 如何将我的程序添加到文件和文件夹的macOS右键单击菜单?
- 如何以编程方式显示功能区按钮的下拉菜单?
- 帧缓冲纹理变为白色(片段着色器不会影响它)
- 如何在win32的窗口类中设置动态菜单?
- 我的菜单的双重缓冲