如何设置Win32 API的C ++按钮的背景颜色和文本颜色? [英] how to set win32 api c++ button background color and text color?
问题描述
IM使用Win32应用程序简单的按钮,我喜欢改变其颜色和文本
但我不能在谷歌所有的搜索如何做到这一点找到。
我有这个code,稀土present一个按钮:
这是在rc文件:
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. i have this code that represent a button: this is in the rc file :
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
}
和主CPP文件,我只简单TRIGER警报Massegebox
and in the main cpp file i only triger simple Massegebox alerts
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?
推荐答案
您不能,或者至少你不能做如此简单。如果你想有一个彩色按钮,那么你需要设置所有者绘制风格和自己绘制它。老式按钮没有自定义颜色。
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.
这篇关于如何设置Win32 API的C ++按钮的背景颜色和文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!