Showing Tooltips in a ListView

 

horizontal rule

Back Home Next

Author Aart Onkenhout
Date 27-10-2000

 

When you have a ListView in Report-view, it's possible that labels are partially hidden. There are two ways to show tooltips for these partially hidden labels.

 

 

Method 1

 

The first requires you to have comctl32.dll version 5.80 or later and PowerBuilder 7.0 or later. To show tooltips you have to code the following (e.g. in the constructor-event of your ListView):

 

Long             ll_ExStyle
Constant Integer LVM_SETEXTENDEDLISTVIEWSTYLE = 4150
Constant Integer LVM_GETEXTENDEDLISTVIEWSTYLE = 4151
Constant Integer LVS_EX_LABELTIP = 16384

ll_ExStyle = Send( Handle( this ), LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 )

ll_Exstyle += LVS_EX_LABELTIP
Send( Handle( this ), LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ll_ExStyle )

 

Method 2

 

The second is to use u_lv_tooltip, a standard visual userobject of type ListView I wrote. This object makes use of some Windows-API's to establish the same result. This method also just works with PowerBuilder 7.0 or later and on Windows NT 4.0 or later and Windows 98 or later.

When you want to show tooltips, just use u_lv_tooltip instead of the standard ListView-control.

This object makes use of an object nvo_tooltip (I can't found anymore who made it, because the website I got it from doesn't exist anymore), and some event-code of an object similar to this object to show Tooltips for Treeviewitems that has partially hidden labels (which isn't needed anymore with PB 7 because it's a property of the TreeView from that version on).

You don't have to call any additional functions, all is on the control.

 

How it works

 

A ue_mousemove event was added to the ListView to capture mousemovements within the ListView. On moving over, the function of_ShowTip() is called.

First thing that happens in this function is sending a message - LVM_SUBITEMHITTEST - to the ListView to see what row and column the mouse is over. This information is used when sending a LVM_GETSUBITEMRECT message to the ListView, which returns a rectangle. This gives you the current width of the column. After determining the width of the column, you must know the text that is in the current ListView-cell. This is determined by sending a LVM_GETITEMTEXT message to the ListView. Now you must know the width needed for this text to be shown at all, so a call is made to the Windows API GetTextExtentPoint32A. This function gives you width and height of the text, based on the current font of the ListView.

Now it's just a matter of comparing the columnwidth against the textwidth to know if a tooltip must be shown.

 

Hiding the tooltip is done in three cases:

  1. When you leave the client-area of the ListView. For this case some code is added to the other-event. I know, this normally isn't a good place to add code to, but it makes the whole thing work very well. In the other event I check if the ListView receives a WM_MOUSELEAVE message (this message is only sent within Windows NT 4 and Windows 98 or later). This message is sent to a control when the mouse leaves the client-area of the control. Within a ListView the client-area is everything inside the header, the scrollbars and the borders. When the mousepointer leaves the ListView while the tooltip is visible, the function of_HideTip() is called to let it disappear.

  2. When the mouse isn't over a valid row and column combination.

  3. When the columnwidth is big enough to show the whole label.

 

Download

 

You can download a sample application (PB7) here.

 

Download LvTooltip.zip