Solved

Replacing list control in a dropdown ComboBox

Posted on 1998-09-25
2
535 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 99
ffmpeg - "rtsp://...... Operation not permitted" 4 80
unix example issues 18 89
Problem to App 4 79
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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