[英]C++ Win32 Radio button background color
So first i'm using the windows API, no special libraries. 所以首先我使用的是Windows API,没有特殊的库。
I've created a radio button with this code: 我用以下代码创建了一个单选按钮:
g_hRadioButton = CreateWindowEx(0, "BUTTON", "Radio Button",
WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON,
10, 55, 120, 25, hWnd, (HMENU)RADIOBUTTON, GetModuleHandle(NULL), NULL);
Now I have a black background for the main window, so I would like the text to be white, and the background to be transparent. 现在主窗口有黑色背景,所以我希望文本为白色,背景为透明。
I've tried checking both the WM_CTLCOLORBTN
and WM_CTLCOLORSTATIC
messages. 我尝试检查
WM_CTLCOLORBTN
和WM_CTLCOLORSTATIC
消息。
Here's my code: 这是我的代码:
case WM_CTLCOLORBTN:
SetTextColor((HDC)wParam, 0xffffff);
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)GetStockObject(BLACK_BRUSH);
case WM_CTLCOLORSTATIC:
SetTextColor((HDC)wParam, 0xffffff);
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
This doesn't work, the backgrounds still white and the text is black. 这不起作用,背景仍然为白色,文本为黑色。
Also i've enabled visual styles by linking to ComCtl32.lib, creating the manifest and all that. 另外,我还通过链接到ComCtl32.lib,创建清单以及所有这些来启用了视觉样式。
EDIT: 编辑:
Trying to process the NM_CUSTOMDRAW
message now instead. 现在尝试改为处理
NM_CUSTOMDRAW
消息。 Here's my code but it's having no effect, and i'm pretty sure im doing something wrong. 这是我的代码,但是没有任何效果,我敢肯定我做错了什么。
case WM_NOTIFY:
{
if (((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
{
LPNMCUSTOMDRAW nmCD = (LPNMCUSTOMDRAW)lParam;
switch(nmCD->dwDrawStage)
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
SetTextColor(nmCD->hdc, 0xffffff);
SetBkColor(nmCD->hdc, 0x000000);
return CDRF_DODEFAULT;
}
}
break;
}
Could someone at least point me in the right direction? 至少有人能指出我正确的方向吗?
Perhaps as soon as your application is running with visual styles, you will be better off handling NM_CUSTOMDRAW notification for button control. 也许您的应用程序以视觉样式运行后,您最好处理NM_CUSTOMDRAW通知以进行按钮控制。 Originally, these were for common controls only, but quite a few versions are already extending button behavior the same way too.
最初,这些仅用于通用控件,但是已经有许多版本以相同的方式扩展了按钮的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.