在 win32 中使用 DWM 时,如何以编程方式更改窗口边框和标题栏背景的颜色?
我想在 win32 中使用 DWM 自定义窗口框架以获得类似 VS2022(在标题栏上绘制菜单)或 Chrome(在标题栏上绘制选项卡)的外观,因此我使用 DwmExtendFrameIntoClientArea 函数,其边距为 {0, 0, 标题高度, 0}。不幸的是,它显示了一个宽度为 1 像素的白色窗口边框和白色标题栏区域。我使用函数 DwmDefWindowProc 来处理系统消息并显示系统控制按钮(最小、最大、关闭按钮)。但我不知道如何更改窗口边框和标题栏背景的颜色。如果我用WM_PAINT绘画,它可能会覆盖系统控制按钮并且看起来很奇怪。如果我用WM_NCPAINT绘画,WS_THICKFRAME风格的窗口阴影可能会消失,需要绘制,我觉得很难做到。
另外,1像素宽度的边框可能来自以下代码:
if (message == WM_NCCALCSIZE) {
auto client_area_needs_calculating = static_cast<bool>(wparam);
if (client_area_needs_calculating) {
auto parameters = reinterpret_cast<NCCALCSIZE_PARAMS*>(lparam);
auto& requested_client_area = parameters->rgrc[0];
requested_client_area.right -= GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
requested_client_area.left += GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
requested_client_area.bottom -= GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
return 0;
}
}
I want to customize the window frame using DWM in win32 to get an appearance like VS2022 (draw menu on title bar) or Chrome (draw tabs on title bar), so I use the function DwmExtendFrameIntoClientArea with margin {0, 0, caption height, 0}. Unfortunately, it shows a white window border with 1-pixel width and white title bar area. I use the function DwmDefWindowProc to handle the system messages and show the system control buttons (min, max, close button). But I have no idea how to change the color of the window border and title bar background. If I paint in WM_PAINT, it may cover the system control buttons and looks weird. If I paint in WM_NCPAINT, the window shadow with WS_THICKFRAME style may disappear and need to draw which I feel is difficult to do.
Additionally, the 1-pixel width border may come from the following code:
if (message == WM_NCCALCSIZE) {
auto client_area_needs_calculating = static_cast<bool>(wparam);
if (client_area_needs_calculating) {
auto parameters = reinterpret_cast<NCCALCSIZE_PARAMS*>(lparam);
auto& requested_client_area = parameters->rgrc[0];
requested_client_area.right -= GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
requested_client_area.left += GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
requested_client_area.bottom -= GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
return 0;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论