如何获取默认复选框图像?

发布于 2024-08-05 12:27:09 字数 132 浏览 3 评论 0原文

我正在尝试使用 CButton 构建一个所有者绘制的复选框,但由于我只想更改文本颜色,因此我希望复选框标记保持不变。

是否有命令允许我检索程序运行平台的默认复选框位图?

(或者:如何仅更改文本颜色,保留复选框标记?)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉世弥音 2024-08-12 12:27:09

我使用 UxTheme.dll 来绘制自定义复选框。

首先,我使用以下方法绘制复选框标记: DrawThemeBackground 向其传递一个修改后的矩形 (checkboxRect.right = pCustomDraw->rc.left + 15;)

然后我使用 ::DrawText 自己绘制文本。

我希望它有帮助。

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.

度的依靠╰つ 2024-08-12 12:27:09

您最好的策略是覆盖 OnCtlColor 处理程序:

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;
}

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

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|

客…行舟 2024-08-12 12:27:09

如果您只想更改文本颜色,请在包含的对话框中实现 OnCtlColor 的处理程序。像这样:

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;
}

请注意,这不适用于常规按钮,但对于复选框应该没有问题。无需实现所有者绘制的控件。

编辑:

您必须确保您的复选框使用BS_AUTOCHECKBOX样式。另请确保未设置 BS_OWNERDRAW 样式。

编辑#2:
DrawFrameControl() 与 DFCS_BUTTONCHECK 会让你绘制默认复选框位图。

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.

左秋 2024-08-12 12:27:09

要获取 Windows 系统复选框图像(我认为这是所要求的):

LoadBitmap(0,OBM_CHECKBOXES);

将返回所有复选框的 4x3 位图的位图句柄(包括单选按钮,还启用和禁用)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文