How do I get the default check box images?

2.5k Views Asked by At

I'm trying to build an owner-drawn check box using CButton, but since I only want to change the text color, I'd like the check-box marks to remain the same.

Is there a command that allows me to retrieve the default check box bitmaps for the platform where the program is running?

(alternatively: how could I change only the text color, preserving the check box marks?)

4

There are 4 best solutions below

1
On BEST ANSWER

I use UxTheme.dll to draw my custom checkbox.

First I draw the check-box marks using: DrawThemeBackground passing it a modified rect (checkboxRect.right = pCustomDraw->rc.left + 15;)

And then I draw the text by myself using ::DrawText.

I hope it helps.

3
On

Your best strategy would be to override the OnCtlColor handler:

BEGIN_MESSAGE_MAP(CBaseDialog, CDialog)
{
    ON_WM_CTLCOLOR()
}

HBRUSH CXXX:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hBkgrBrush= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    pDC->SetTextColor(RGB(255,0,0)); // red
    pDC->SetBkMode   (TRANSPARENT );
    return hBkgrBrush;
}

See http://msdn.microsoft.com/en-us/library/0wwk06hc(VS.80).aspx|

4
On

If you only want to change the text color, implement a handler for OnCtlColor in your containing dialog. Like this:

HBRUSH CDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if(pWnd->GetDlgCtrlID() == IDC_CHECK_BOX) //check for your check box control ID
    {
        pDC->SetTextColor(RGB(255,0,0));
    }
    return hbr;
}

Beware that this works not for regular push buttons, but for check boxes there should be no problem. No need to implement an owner-drawn control.

EDIT:

You have to make sure, your check box uses the BS_AUTOCHECKBOX style. Also make sure the BS_OWNERDRAW style is not set.

EDIT #2: DrawFrameControl() with DFCS_BUTTONCHECK will let you draw the default check box bitmaps.

0
On

To get the windows system checkbox images (which is I think what was asked):

LoadBitmap(0,OBM_CHECKBOXES);

will return a bitmap handle to a 4x3 bitmap of all the checkboxes (includes radio buttons, and also enabled and disabled)