How do I get the default check box images?

╄→гoц情女王★ 提交于 2019-12-11 11:46:12

问题


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?)


回答1:


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.




回答2:


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|




回答3:


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.




回答4:


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)



来源:https://stackoverflow.com/questions/1486740/how-do-i-get-the-default-check-box-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!