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




Reply With Quote
