ComboBox with Item Tooltips
Posted
by Edward Antonyan
on April 18th, 2001

Environment: VC6 SP5, NT4 SP6 ( not tested on other OS )
To use this combo box, follow the following steps:
- Include TooltipComboBox.h, TooltipComboBox.cpp, TooltipListCtrl.h and TooltipListCtrl.cpp in your project.
- In the resource editor create a droplist combobox.
- Create a control member variable for the combobox in VC's classwizard.
- Include TooltipComboBox.h and replace CComboBox with CTooltipComboBox in your .h file. Also include afxtempl.h to support CMap.
- To have your own tips, you can either use SetItemTip, SetComboTip functions, or replace GetItemTip function in CTooltipListCtrl, and GetComboTip function in CTooltipComboBox.
Cause this combo box uses CComboBox's listbox to store items, it has no special behavior, and can be used a usual CComboBox. It uses Hai Ha's article style to replace standard drop-down list with a virtual list control. A virtual one to prevent having two identical lists. Only droplist combo style is currently working like standard CComboBox.
I think the code is simple enough and doesn't need any other comments.

Comments
It doesn't work
Posted by symreds on 10/21/2011 04:12amPerfect - if only there was a way to make multiline tooltips
Posted by Mike Pliam on 11/02/2006 01:43amThis is just what I've been looking for. It would really be ideal if I could link the items to multi-line tooltips from a WinHelp file.
Replyselected item visible
Posted by shean85 on 09/13/2004 04:48pmHow to make selected item from the combobox to be visible when I open the combobobox again (to scroll , to make selected item visible) thank you
ReplyFix for missing CBN_SELCHANGE message (fixes ON_CBN_SELCHANGE issues)
Posted by Mr. X on 09/03/2004 07:00amThis 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 never called. e.g. Method OnSelchangeCombo1() for entries like this in your dialog's message map: ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)). 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 Enter-key.***]: void CTooltipListCtrl::OnKillFocus(CWnd* pNewWnd) { CPoint point; 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) pParentDlg->PostMessage(WM_COMMAND,MAKELONG(m_pComboParent->GetDlgCtrlID(), CBN_SELCHANGE),(LPARAM)m_pComboParent->m_hWnd); // AJY End Fix. } m_pComboParent->SetCurSel( m_nLastItem ); m_pComboParent->SetFocus( ); CListCtrl::OnKillFocus( pNewWnd ); }-
-
ReplyThis worked for me.
Posted by paresh_chitte on 02/16/2007 07:41amThanks.
ReplyThis was also required by me
Posted by NtwoO on 09/07/2004 09:38amTnx for the fix.
ReplyFix for Paul Garber's sorted list fix
Posted by Mr. X on 09/03/2004 06:46amThanks 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) return -1; 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; return nRow; }ReplyFix for compiler error under VS.NET 7.1
Posted by Mr. X on 09/03/2004 06:41amnot fully working
Posted by psychodad on 08/29/2004 11:46amif 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.
ReplyThe tootip isn't shown...
Posted by Legacy on 01/19/2004 12:00amOriginally posted by: Tommy Svensson
ReplyHow We Can Change A Font Of TextBox ?
Posted by Legacy on 10/16/2003 12:00amOriginally posted by: mohammed aseer
HOW WE CAN CHANGE A FONT OF TEXT BOX BY PROVIDING 2 LIST BOXES ONE FOR FONT STYLE & OTHER FOR FONT FAMILY?
ReplyComboBox strupid selection
Posted by Legacy on 07/31/2003 12:00amOriginally posted by: fov
Hi folkes !
ReplyI'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 !
fov
Loading, Please Wait ...