[英]How to change the background color of the title bar color C++/SDL2
I don't think that's possible with just SDL2, but you can get the native window and use that.我认为仅使用 SDL2 是不可能的,但您可以获得本机窗口并使用它。
Looking at your screenshot, I assume you are using Windows.查看您的屏幕截图,我假设您使用的是 Windows。 You can get the
HWND
like this ( see this answer ):您可以像这样获得
HWND
(请参阅此答案):
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
HWND hwnd = wmInfo.info.win.window;
Once you have that, you'll want to set both the border color and the caption color ( see this answer ):完成后,您需要同时设置边框颜色和标题颜色(请参阅此答案):
#include <dwmapi.h>
COLORREF titlebar_color = 0x0015171E;
DwmSetWindowAttribute(
hwnd, DWMWINDOWATTRIBUTE::DWMWA_BORDER_COLOR,
&titlebar_color, sizeof(titlebar_color)
);
DwmSetWindowAttribute(
hwnd, DWMWINDOWATTRIBUTE::DWMWA_CAPTION_COLOR,
&titlebar_color, sizeof(titlebar_color))
);
Of course, all of that only works on Windows (10 or later I think), and, as far as I understand, isn't even guaranteed to work.当然,所有这些只适用于 Windows(我认为是 10 或更高版本),而且据我所知,甚至不能保证有效。 So you may want to error-check everything.
因此,您可能希望对所有内容进行错误检查。
Another solution that isn't exactly what you ask for but is done entirely within SDL2 is to create a borderless window and draw your own title bar...另一个不完全是你要求但完全在 SDL2 中完成的解决方案是创建一个无边框窗口并绘制你自己的标题栏......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.