[英]how to set win32 api c++ button background color and text color?
im using simple button in win32 application and i like to change its color and text but i can't find from all searching in google how to do it.我在 win32 应用程序中使用简单的按钮,我喜欢更改它的颜色和文本,但我无法从谷歌的所有搜索中找到如何做到这一点。 i have this code that represent a button: this is in the rc file:
我有这个代表一个按钮的代码:这是在 rc 文件中:
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 0, 0, 273, 209
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Win32 demo"
FONT 8, "Ms Shell Dlg"
{
DEFPUSHBUTTON "My Button1 ", IDOK, 59, 176, 69, 14
PUSHBUTTON "Log Off", IDC_BUTTON1, 155, 175, 54, 14
}
and in the main cpp file i only triger simple Massegebox alerts在主 cpp 文件中,我只触发简单的 Massegebox 警报
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
MessageBox(NULL, L"IDOK button pressed!", L"Pinky says...", MB_OK | MB_ICONEXCLAMATION);
break;
case IDC_BUTTON1:
MessageBox(NULL, L"IDC_BUTTON1 button pressed!",L"Pinky says...", MB_OK | MB_ICONEXCLAMATION);
break;
break;
}
break;
where and how i change the buttons background colors and text?我在哪里以及如何更改按钮背景 colors 和文本?
You can't, or at least you can't do so simply.你不能,或者至少你不能简单地这样做。 If you want a coloured button then you need to set the owner-draw style and draw it yourself.
如果您想要一个彩色按钮,那么您需要设置所有者绘制样式并自己绘制它。 Plain old buttons don't have customisable colours.
普通的旧按钮没有可定制的颜色。
There are several approaches you could take for this:为此,您可以采取多种方法:
The easiest way is just to handle WM_CTLCOLORBTN .最简单的方法就是处理WM_CTLCOLORBTN 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.