Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Replacing list control in a dropdown ComboBox

Posted on 1998-09-25
2
Medium Priority
?
667 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 600 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

963 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