2
votes

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?

1
You're calling SetTextColor with RGB(0,0,0) which is black - pezcode
@pezcode Fixed. In my actual program I have it call a function that returns the color, either white or red. I was cleaning it up to make it simpler for this question. - Josh
No, the background is still white, and text black. - Josh
Where are you handling the messages? They must be handled by the parent window. - pezcode
@pezcode They are being. - Josh

1 Answers

1
votes

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.