Solved

Replacing list control in a dropdown ComboBox

Posted on 1998-09-25
2
583 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
[X]
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
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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