Click here to Skip to main content
15,913,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: showing binary date Pin
bkelly1324-Oct-10 17:07
bkelly1324-Oct-10 17:07 
AnswerRe: showing binary date Pin
Sauro Viti24-Oct-10 21:57
professionalSauro Viti24-Oct-10 21:57 
QuestionIs this the fastest way to access the RGB values of a Pixel ? Pin
inayathussaintoori23-Oct-10 23:08
inayathussaintoori23-Oct-10 23:08 
AnswerRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
Sauro Viti24-Oct-10 1:40
professionalSauro Viti24-Oct-10 1:40 
AnswerRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
Luc Pattyn24-Oct-10 1:56
sitebuilderLuc Pattyn24-Oct-10 1:56 
GeneralRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
inayathussaintoori24-Oct-10 2:01
inayathussaintoori24-Oct-10 2:01 
GeneralRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
Sauro Viti24-Oct-10 2:32
professionalSauro Viti24-Oct-10 2:32 
AnswerRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
Luc Pattyn24-Oct-10 2:44
sitebuilderLuc Pattyn24-Oct-10 2:44 
GeneralRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
inayathussaintoori24-Oct-10 7:53
inayathussaintoori24-Oct-10 7:53 
AnswerRe: Is this the fastest way to access the RGB values of a Pixel ? Pin
Sauro Viti24-Oct-10 21:54
professionalSauro Viti24-Oct-10 21:54 
Questionreplacing the default list box with custom made list box Pin
emmmatty123-Oct-10 18:37
emmmatty123-Oct-10 18:37 
AnswerRe: replacing the default list box with custom made list box Pin
Garth J Lancaster23-Oct-10 18:52
professionalGarth J Lancaster23-Oct-10 18:52 
GeneralRe: replacing the default list box with custom made list box Pin
emmmatty123-Oct-10 22:56
emmmatty123-Oct-10 22:56 
QuestionChange background color of CComboBox [modified] Pin
mesajflaviu23-Oct-10 7:51
mesajflaviu23-Oct-10 7:51 
AnswerRe: Change background color of CComboBox Pin
Code-o-mat23-Oct-10 8:37
Code-o-mat23-Oct-10 8:37 
GeneralRe: Change background color of CComboBox Pin
mesajflaviu23-Oct-10 9:19
mesajflaviu23-Oct-10 9:19 
GeneralRe: Change background color of CComboBox Pin
Code-o-mat23-Oct-10 9:24
Code-o-mat23-Oct-10 9:24 
GeneralRe: Change background color of CComboBox Pin
mesajflaviu25-Oct-10 0:52
mesajflaviu25-Oct-10 0:52 
GeneralRe: Change background color of CComboBox Pin
Code-o-mat25-Oct-10 1:13
Code-o-mat25-Oct-10 1:13 
AnswerRe: Change background color of CComboBox Pin
Dennis Dykstra23-Oct-10 11:48
Dennis Dykstra23-Oct-10 11:48 
GeneralRe: Change background color of CComboBox Pin
mesajflaviu25-Oct-10 0:51
mesajflaviu25-Oct-10 0:51 
GeneralRe: Change background color of CComboBox [modified] Pin
Dennis Dykstra25-Oct-10 17:01
Dennis Dykstra25-Oct-10 17:01 
I've just tried it with an MFC dialog application. It's not perfect because the color change doesn't "stick" when the edit control has the focus but it comes back when you tab away from the combo box. You'd need to do some more work to make it work the way you want when the edit control has the focus, but this should give you a starting point.

The class that I derived from CComboBox is named CColorEditCombo. In the Visual Studio designer I added a CComboBox control to the dialog window. With the ClassWizard I added a CComboBox control variable named m_ctlComboColorEdit. Then in the header file for the dialog class I changed the declaration for this variable to the following:

CColorEditCombo m_ctlComboColorEdit;


This associates that control with the new CColorEditCombo class rather than the parent CComboBox class. In the class file for CColorEditCombo I added a handler for the WM_CTLCOLOR message as follows:

HBRUSH CColorEditCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);

    switch (nCtlColor)
    {
    case CTLCOLOR_EDIT:
    case CTLCOLOR_MSGBOX:
        // Subclass the edit control.
        if (m_edit.GetSafeHwnd() == NULL)
            {
            m_edit.SubclassWindow(pWnd->GetSafeHwnd());
            }
        // Set the background color for the edit control.
        pDC->SetBkColor(RGB(255, 255, 0));
        // Recolor the edit control.
        m_brush.DeleteObject();
        m_brush.CreateSolidBrush(RGB(255, 255, 0));
        hbr = (HBRUSH) m_brush.GetSafeHandle();
        return hbr;

    case CTLCOLOR_LISTBOX:
        // Subclass the listbox control.
        if (m_listBox.GetSafeHwnd() == NULL)
            {
            m_listBox.SubclassWindow(pWnd->GetSafeHwnd());
            }
        // Add recoloring actions for the listbox here if desired.
     }

    return hbr;
    }


Note the member variable named m_brush. This has to be declared in the header file for the CColorEditCombo class as a CBrush object. It should be deleted in the class destructor as well as just before the CreateSolidBrush statement shown above.

If you'd like, I can send you the solution for the very simple MFC dialog application I put together as a test to make sure this procedure works. You'll have to give me your email address and tell me which version of Visual Studio you are using.

modified on Wednesday, October 27, 2010 1:52 PM

GeneralRe: Change background color of CComboBox Pin
mesajflaviu28-Oct-10 7:37
mesajflaviu28-Oct-10 7:37 
QuestionRegarding Addition of Items in Tree Control by Type. Pin
janaswamy uday23-Oct-10 6:48
janaswamy uday23-Oct-10 6:48 
AnswerRe: Regarding Addition of Items in Tree Control by Type. Pin
Code-o-mat23-Oct-10 7:28
Code-o-mat23-Oct-10 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.