问题描述
所以,首先,我使用Windows API,没有特殊的库。
So first i'm using the windows API, no special libraries.
我创建了一个单选按钮与此code:
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.
我已经试过检查均 WM_CTLCOLORBTN
和 WM_CTLCOLORSTATIC
消息。
I've tried checking both the WM_CTLCOLORBTN
and WM_CTLCOLORSTATIC
messages.
下面是我的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.
此外,我已经通过链接到ComCtl32.lib,创建清单并启用视觉样式了这一切。
Also i've enabled visual styles by linking to ComCtl32.lib, creating the manifest and all that.
编辑:
试图处理 NM_CUSTOMDRAW
消息现在来代替。
这里是我的code,但它有没有影响,我是pretty确保即时通讯做错了什么。
Trying to process the NM_CUSTOMDRAW
message now instead.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. Originally, these were for common controls only, but quite a few versions are already extending button behavior the same way too.
这篇关于C ++的Win32单选按钮的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!