CCombobox背光不反射 [英] CCombobox backcolor not reflecting

查看:57
本文介绍了CCombobox背光不反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在VC ++中为CCombobox应用了背面颜色代码如下。

我从ac#.net项目启动这个vc ++应用程序



.Cpp文件

------------------- ----------

Hi,
I have written below code for applying back color for CCombobox in VC++.
I am launching this vc++ application from a c#.net project

.Cpp file
-----------------------------

BEGIN_MESSAGE_MAP(CMCombo, CComboBox)
    //{{AFX_MSG_MAP(CMCombo)
    ON_WM_CTLCOLOR()
    ON_WM_CTLCOLOR_REFLECT()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

CMCombo::CMCombo()
{
    m_Brush = new CBrush(RGB(255, 255, 255));
}

CMCombo::~CMCombo()
{
    if (m_Brush->GetSafeHandle())
    {
        m_Brush->DeleteObject();
    }
}


HBRUSH CMCombo::CtlColor(CDC* pDC, UINT nColor)
{
    pDC->SetBkColor(RGB(0, 0, 0));
    return (HBRUSH) ::CreateSolidBrush(RGB(0,0,0));
}

HBRUSH CMCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    pDC->SetDCBrushColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(0, 0, 0));
    m_Brush = new CBrush(RGB(0, 0, 0));
    return (HBRUSH)(m_Brush->GetSafeHandle());
}







.h文件

--- ------------




.h file
---------------

public:
	CBrush* m_Brush;

protected:
	//{{AFX_MSG(CMCombo)
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nColor);
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()









从上面的代码中,组合框的背景颜色没有变化。但是组合框下拉的背景颜色变为黑色。



如何更改组合框编辑部分的背景色。我在这里缺少任何代码





From above code the backcolor of combobox is not changing. But backcolor of combobox dropdown is getting changed to black.

How to change backcolor of edit part of combobox. Am I missing any code here

推荐答案

调用哪个颜色处理程序取决于组合框的类型(使用静态字段或使用编辑字段)。您还必须在处理程序内部检查控件的哪个部分受到影响:

Which color handler is called depends on the type of the combo box (with static field or with edit field). You must also check inside the handler which part of the control is affected:
// Get brush and set color for colored backgrounds of edit field 
// (not called for static field).
HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    if (nCtlColor == CTLCOLOR_EDIT) // Edit control
    {
        // Return brush here
    }
    return CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
}

// Get brush and set color for colored backgrounds of static text and edit field.
HBRUSH CMyComboBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
    if (nCtlColor == CTLCOLOR_STATIC || nCtlColor == CTLCOLOR_EDIT)
    {
        // Return brush here
    }
    return NULL; // Send message to parent
}


这篇关于CCombobox背光不反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆