Handling combo closing up in WindowProc!
Posted on 2009-02-19
I have a custom combo box that, when dropped down, hides the default windows listbox part of the control, then displays my own custom one. This all works, but I am having problems...
I have a class derived from CComboBox that handles the CBN_CLOSEUP and CBN_DROPDOWN via ON_CONTROL_REFLECT macros: I can hide and show my custom list control respectively in these handler functions. However, I am now instance subclassing an existing plain old CComboBox control: to do that I need to provide a special window procedure, which I do via SetWindowLong/GWL_WNDPROC. This is the function I have so far:
LRESULT CALLBACK CustomWndProc ( HWND hWnd, UINT msg, WPARAM wp, LPARAM lp )
WNDPROC wndProcOld = NULL;
VERIFY ( wndProcOld = ( WNDPROC ) GetProp ( hWnd, _T("OldWndProc") ) );
if ( !wndProcOld ) return 0;
LRESULT lRes = 0;
if ( msg == CB_SHOWDROPDOWN )
// Show custom list control: this works fine
if ( msg == CBN_CLOSEUP )
// Hide custom list control. This does not work!
lRes = ::CallWindowProc ( wndProcOld, hWnd, msg, wp, lp );
Clearly, I get the old window procedure that I have set in the combo box's property table, using it if necessary. I find that whereas I receive the CB_SHOWDROPDOWN every time the combo is dropped down, I don't receive the CBN_CLOSEUP message. In fact, I only ever receieve this message once - strangely enough when the combo is first dropped down. As a consequence, I am finding it hard to know when to close my custom list.
How can I handle the combo being closed?