Solved

Replacing list control in a dropdown ComboBox

Posted on 1998-09-25
2
511 Views
Last Modified: 2013-11-19
I am trying to replace the listctrl in a CComboBox with my own dropdown window.  I am handling the CB_SHOWDROPDOWN, CBN_DROPDOWN, and CBN_CLOSEUP messages and most of the time everything works perfectly.  However, the listctrl will still popup randomly.  Is there an easy way to get a HWND to the listctrl, or is there something else I am missing?  I have traced through the messages with Spy++ and don't see anything.  Thanks.
0
Comment
Question by:mcollins
2 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 200 total points
ID: 1322620
The following info is taken from the MFC FAQ:

How do I subclass the list box portion of a combo box?

The listbox portion of a combo box is of type COMBOLBOX (notice the "L").    Because the ComboLBox window is not a child of the ComboBox window, it is not obvious how to subclass the COMBOLBOX control. Luckily, under the Win32 API, Windows sends a message to the COMBOBOX (notice no "L") called WM_CTLCOLORLISTBOX before the list box is drawn. The lParam passed with this message contains the handle of the list box. For example:

LRESULT CFileUpdateCombo::OnCtlColorListBox(WPARAM wParam,
   LPARAM lParam)
{
    if ( ! m_bSubclassedListBox )
{
        HWND hWnd = (HWND)lParam;
        CWnd* pWnd = FromHandle(hWnd);
        if ( pWnd && pWnd != this )
        {
            // m_ListBox is derived from CListBox.
            m_ListBox.SubclassWindow(hWnd );
            m_ListBox.SetOwner(this);
            m_bSubclassedListBox = TRUE;
        }
    }
    return (LRESULT)GetStockObject(WHITE_BRUSH);
}

As you can see it is possible from there to get a handle to the listctrl of the combobox. In your implementation you could either subclass it with your own dropdown window or just keep that handle and disable/hide the listctrl.  The subclassing might do a better job and prevent some unusual flicker.
0
 

Author Comment

by:mcollins
ID: 1322621
Thanks, plaroche.  I can't believe I didn't see that before.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now