Fix for missing CBN_SELCHANGE message (fixes ON_CBN_SELCHANGE issues)
Posted by Mr. X
on 09/03/2004 07:00am
This tooltip combobox control works well, once you have fixed:
(1) the compiler error and
(2) handling sorted lists
(3) added sending CBN_ONSELECT message
The latter is a problem if you happen to have
code that depends on the combobox selection made
it will never be called -- for example if your
dialog enables/disables other controls depending
on the choice made. This problem occurs because,
unlike MFC's CComboBox, this one does not send a
CBN_SELCHANGE message when a new selection is
made, consequently, any message handlers are
e.g. Method OnSelchangeCombo1() for entries like
this in your dialog's message map:
The following update (implemented in the child
TooltipList control) fixes the problem
[***Note: this fix works with selections made by
mouse-button, mouse-wheel, arrow-keys and/or the
void CTooltipListCtrl::OnKillFocus(CWnd* pNewWnd)
GetCursorPos( &point );
CWnd *pWnd = WindowFromPoint( point );
if ( pWnd->GetSafeHwnd( ) != m_pComboParent->GetSafeHwnd( ) )
ShowWindow( SW_HIDE );
// AJY Start fix.
CWnd *pParentDlg = m_pComboParent->GetParent(); // The parent's parent (typically the dialog window)
// AJY End Fix.
m_pComboParent->SetCurSel( m_nLastItem );
CListCtrl::OnKillFocus( pNewWnd );
Thanks for the sorted list fix Paul.
There was a small but obvious bug in the fix
(most likely a typo). Here is the fixed code:
// Additional code from Paul Garber (codeguru.com) required to correctly order tooltips for sorted lists.
int CTooltipListCtrl::InsertItemTip( int nRow, CString sTip)
if (nRow < 0)
if ( nRow < m_pComboParent->GetCount( ) )
for (int i = m_pComboParent->GetCount( ) - 1; i >= nRow; --i)
// AJY Serious but obvious BUG: m_itemToTip[nRow + 1] = GetItemTip(i);
// Shuffle existing tips at the end of the list along to squeeze new one into the correct place.
int idxNew = i + 1; // Templates can't handle expressions in-line.
m_mpItemToTip[idxNew] = (CString)GetItemTip(i);
m_mpItemToTip[nRow] = sTip;
Here is a fix for the compiler error that I saw when compiling this control under VS.NET 7.1:
// AJY - The following code would not compile in VS7:
// OLD: m_lstCombo.CreateEx( 0, WC_LISTVIEW, NULL, dwStyle, rc, this, 0 );
CWnd* pWnd = &m_lstCombo;
pWnd->CreateEx( 0, WC_LISTVIEW, NULL, dwStyle, rc, this, 0 );
// AJY End.
if you place 2 or more tooltipcombos into a dialog and move the mouse over one combobox it shows the tooltip, but if you go over another one its not shown. its always only shown on the first combo you hit.
can someone help me plz to fix this, i found no solution :/
the selchanged event isnt working too.
Hi folkes !
I'm using visual c++ 6 and need to know the value of the new selected item in a combo box. When using CBN_SELCHANGE or CBN_SELENDOK with WM_GETTEXT the result is actually the old item value as the above two messages are processed before the new value is set. How can I get the new value ?
Thank you !