[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1103
  • Last Modified:

Clistbox with tooltip

I want to make a CListBox with a tooltip. I must use MFC.
Can somebody send me the code in VC++ to do this CListBox?
0
Ciccarella
Asked:
Ciccarella
1 Solution
 
cyberfrankCommented:
0
 
jhanceCommented:
What's the issue here?  

The tooltips work exactly the same with a CListBox as with any other control.

Is this a general question about how to make tooltips work?  Do they work with ANY of your window controls?  

Basically you need to:

1) Handle the TTN_NEEDTEXT message.  In your MESSAGE_MAP add:

      ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)

2) Use a function to supply the tool tip text:

BOOL CMainDialog::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{    

      CToolTipCtrl* pToolTip = AfxGetThreadState()->m_pToolTip;
      if(pToolTip->GetSafeHwnd() != NULL){
            pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 280 /* WIDTH in PIXELS */);
      }

      TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;    
      UINT nID = pNMHDR->idFrom;

    if (pTTT->uFlags & TTF_IDISHWND){
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);        
            if(nID){
            pTTT->lpszText = MAKEINTRESOURCE(nID);
            pTTT->hinst = AfxGetResourceHandle();
                  return(TRUE);
        }    
      }    
      
      return(FALSE);
}

3) Don't forget       EnableToolTips(TRUE);

in your OnInitDialog()
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now