Any idea how to quickly change background color of CBS_DROPDOWNLIST CComboBox to white. since CBS_DROPDOWN has white background, i also want CBS_DROPDOWNLIST to have white background.
Printable View
Any idea how to quickly change background color of CBS_DROPDOWNLIST CComboBox to white. since CBS_DROPDOWN has white background, i also want CBS_DROPDOWNLIST to have white background.
Did you try to handle WM_CTLCOLOR?
Also see this thread.
I tried below code
// MyComboBox.h
//MyComboBox.cppCode:
#if !defined(AFX_MYCOMBOBOX_H__6C1728B4_F098_408B_919A_A8DA393AA426__INCLUDED_)
#define AFX_MYCOMBOBOX_H__6C1728B4_F098_408B_919A_A8DA393AA426__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyComboBox.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMyComboBox window
class CMyComboBox : public CComboBox
{
// Construction
public:
CMyComboBox();
// Attributes
public:
CBrush m_Brush;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyComboBox)
public:
virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyComboBox();
// Generated message map functions
protected:
//{{AFX_MSG(CMyComboBox)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYCOMBOBOX_H__6C1728B4_F098_408B_919A_A8DA393AA426__INCLUDED_)
//MyDialog.hCode:
// MyComboBox.cpp : implementation file
//
#include "stdafx.h"
#include "TestColorCombo.h"
#include "MyComboBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyComboBox
CMyComboBox::CMyComboBox()
{
m_Brush.CreateSolidBrush(RGB(255, 0, 0));
}
CMyComboBox::~CMyComboBox()
{
m_Brush.DeleteObject();
}
BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
//{{AFX_MSG_MAP(CMyComboBox)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyComboBox message handlers
BOOL CMyComboBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
// TODO: Add your specialized code here and/or call the base class
if(WM_CTLCOLOREDIT != message)
return CComboBox::OnChildNotify(message, wParam, lParam, pLResult);
HDC hdcChild = (HDC)wParam;
if(NULL != hdcChild)
{
SetBkMode(hdcChild, TRANSPARENT);
SetTextColor(hdcChild, RGB(255, 255, 0));
SetBkColor(hdcChild, RGB(255, 0, 0));
*pLResult = (LRESULT)(m_Brush.GetSafeHandle());
}
return TRUE;
// return CComboBox::OnChildNotify(message, wParam, lParam, pLResult);
}
#MyDialog.cppCode:#include "CMyComboBox.h"
.
..... //here .... means necessary constructors() and all
.....
....
public :
CMyComboBox mybox;
......
....
}
Now result after compilation is ,dialog is not even loading, cursor rotates and nothing opensCode:.......
....
...
Bool MyDialog::OnInitDialog()
{
........
mybox.SetCursel(1); //DDX mapping is done by me
.....
return true;
}
Anyone please suggest?
Yes i debugged. OnInitDialog() is not called. From where it is supposed to called there dlg.DoModal() is returning -1
Then, please, post your real actual code, not a pseudo code you have posted.
The best would be to post the small test project that can reproduce this behavior.
Able to load and open dialog . But background color is not reflected. I placed the breakpoint at OnChildNotify() but it is not called. I check DDX mapping ,there memory is allocated to MyCComboBox variable
Your manner to not post your actual code (and instead post pseudo code or/and some meaningless "description") doesn't make much sense and does not help to understand what and how you really do. :cool::rolleyes: