So first i’m using the windows API, no special libraries.
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.
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.
EDIT:
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.