Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Replacing list control in a dropdown ComboBox

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 108
Turn a spreadsheet into a vba executable. 2 92
Folder Comparison 12 54
firstChar challenge 13 119
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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