List Control with Tooltips

This article contains a simple CListCtrl wrapper called CFileDropListCtrl which was made to wrap a CListCtrl so it can display ToolTip text for each item in the control regardless of the style of the view : REPORT, LIST, ICON

Previous articles only listed tooltip text for the Report view.

It was adapted from a previous wrapper which adds Drag&Drop to the control so it can receive files.

The tooltip code was also adapted from a previous tooltip article in this section which supplied tooltip for only REPORT style views. The author simply left out the ability to handle Icon view reports which don't use a column width, but instead just use a rect boundary. To display ICON tooltips, simply includ an IF statment to detect which form the control is in, and if it's an icon view, then set the columnwidth to an arbitrary 10000 so it will not be used in detection. In any case, here is the code below.


  1. Include the 2 files in your project.
  2. Use Classwizard to add a member variable for your CListCtrl such as m_List.
  3. Change in the .h file, CListCtrl m_List change it to CFileDropListCtrl m_List. Thats it!
  4. Modify the ToolTip function to display any other text you like, currently it just displays the item's name.

Note the detection of the control type. Report style views have a column width for each item which we use in mouse-click detection for the tooltip. In List and Icon views, we do not have a column width. So, in those cases we set ColumnWidth to an arbitrary high value so it will not be used, and also column count to 1.

// If not REPORT style for the list, then use 1 column
// Otherwise, find the column in the report style view.
if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
 // Window is not Report style, so no headers. Deal with it!
 nColumnCount = 1;
 // Get the number of columns in Report style.
 pHeader = (CHeaderCtrl*)GetDlgItem(0);
 nColumnCount = pHeader->GetItemCount();

Here we see the rectangle boundary for Icon, List, and Report views.

// Get bounding rect of item and check whether point falls in it.
CRect rect, rectLabel;
if( (GetWindowLong(m_hWnd, GWL_STYLE) 
 // If not Report style, get label / icon boundaries.
 GetItemRect( row, &rect, LVIR_ICON );
 GetItemRect( row, &rectLabel, LVIR_LABEL );
 // If Report style, get bounds of cell.
 GetItemRect( row, &rect, LVIR_BOUNDS );

if( rect.PtInRect(point) ||

Finally, to change what is displayed in the ToolTip simple change the line GetItemText() below to display whatever you like.

BOOL CFileDropListCtrl::OnToolTipText( UINT id, 
                                       NMHDR * pNMHDR, 
                                       LRESULT * pResult )
 // need to handle both ANSI and UNICODE versions of the message
 CString strTipText;
 UINT nID = pNMHDR->idFrom;

if( nID == 0 ) // Notification in NT from automatically
 return FALSE; // created tooltip

int row = ((nID-1) >> 10) & 0x3fffff ;
int col = (nID-1) & 0x3ff;

// Use Item's name as the tool tip. Change this for something different.
// Like use its file size, etc.
strTipText = GetItemText( row, col );

That is it. Here are the 2 files to include in your project.


Download source - 17 Kb


  • Works like a charm

    Posted by turkim on 11/18/2010 04:44am

    Followed your usage points, and voala .. it instently works

  • Turki

    Posted by turkim on 11/18/2010 04:42am

    Many thanks. Because of guys like you, the internet is a wonderful place.

  • NT notification

    Posted by Legacy on 05/15/2003 12:00am

    Originally posted by: Sven

    When I use it in my code, the nID is always 0, so he returns false...

    if( nID == 0 ) // Notification in NT from automatically
    return FALSE; // created tooltip

    What doas that mean, that NT creates tje tooltip automatically?

  • Great!

    Posted by Legacy on 05/12/2002 12:00am

    Originally posted by: Gu Erdan

    It works fine!

    Many Thanks!

  • Does not seem to work

    Posted by Legacy on 07/04/2001 12:00am

    Originally posted by: Jon Taylor

    Unfortunately this does not work when I use it in my application. When I debug it, OnToolTipText never gets called (although OnToolHitTest *does*).

    I'm using VC 6, SP4.

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

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date