本文介绍了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

推荐答案

// 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背光不反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 07:23