ComboBox with Item Tooltips

Environment: VC6 SP5, NT4 SP6 ( not tested on other OS )

To use this combo box, follow the following steps:

  1. Include TooltipComboBox.h, TooltipComboBox.cpp, TooltipListCtrl.h and TooltipListCtrl.cpp in your project.
  2. In the resource editor create a droplist combobox.
  3. Create a control member variable for the combobox in VC's classwizard.
  4. Include TooltipComboBox.h and replace CComboBox with CTooltipComboBox in your  .h file. Also include afxtempl.h to support CMap.
  5. 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.

Downloads

Download source - 6 Kb


Comments

  • It doesn't work

    Posted by symreds on 10/21/2011 04:12am

    The combo doesn't drop down...

    Reply
  • Perfect - if only there was a way to make multiline tooltips

    Posted by Mike Pliam on 11/02/2006 01:43am

    This 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.

    Reply
  • selected item visible

    Posted by shean85 on 09/13/2004 04:48pm

    How 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

    Reply
  • 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
    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 );
    }
    

    • This worked for me.

      Posted by paresh_chitte on 02/16/2007 07:41am

      Thanks.

      Reply
    • This was also required by me

      Posted by NtwoO on 09/07/2004 09:38am

      Tnx for the fix.

      Reply
    Reply
  • Fix for Paul Garber's sorted list fix

    Posted by Mr. X on 09/03/2004 06:46am

    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)
        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;
    }

    Reply
  • Fix for compiler error under VS.NET 7.1

    Posted by Mr. X on 09/03/2004 06:41am

    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.

    Reply
  • not fully working

    Posted by psychodad on 08/29/2004 11:46am

    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.

    Reply
  • The tootip isn't shown...

    Posted by Legacy on 01/19/2004 12:00am

    Originally posted by: Tommy Svensson

    For those of you who don't see the tooltip...
    
    Make sure that you insert tooltip texts, starting with row 0! (Instead of row 1).

    m_comboCars.SetItemTip(0,"Volvo 1234567890");
    m_comboCars.SetItemTip(1,"Volvo 3141592654");
    m_comboCars.SetItemTip(2,"Volvo 2714241424");

    /Tommy

    Reply
  • How We Can Change A Font Of TextBox ?

    Posted by Legacy on 10/16/2003 12:00am

    Originally 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?

    Reply
  • ComboBox strupid selection

    Posted by Legacy on 07/31/2003 12:00am

    Originally posted by: fov

    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 !
    fov

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Not long ago, security was viewed as one of the biggest obstacles to widespread adoption of cloud-based deployments for enterprise software solutions. However, the combination of advancing technology and an increasing variety of threats that companies must guard against is rapidly turning the tide. Cloud vendors typically offer a much higher level of data center and virtual system security than most organizations can or will build out on their own. Read this white paper to learn the five ways that cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds