Josh
Josh

Reputation: 6272

C++ Listview tooltip

I've got a listview in report view that I'm trying to display tooltips for, different per item.

But I can't get any tooltip to be displayed at all...

Here's what I figured out so far:

case LVN_GETINFOTIP:
{
    LPNMLVGETINFOTIP GetInfoTip = (LPNMLVGETINFOTIP) lParam;
    GetInfoTip->pszText = L"TESTING";
    // What do I do now? How do I display the tooltip?
    return 0;
}

After I have received the LVN_GETINFOTIP message, how do I display the tooltip?

Upvotes: 2

Views: 2518

Answers (4)

jorgon
jorgon

Reputation: 11

The Windows documentation suggests that LVN_GETINFOTIP is not sent by report view listview controls. In practice I found this to be the case (2024).

So in these circumstances how to display the tooltip?

I can see why it's necessary to find some alternative to an ordinary tooltip window when using a listview control. The problem with a large control like a listview is that although a TTN_NEEDTEXT notification message (asking for the display text to be specified) will be sent when the cursor first enters the control, a second TTN_NEEDTEXT will not be sent if the cursor then moves within the control onto a different item. This is because the cursor is still in the same control.

One workaround for this is to set the listview style to LVS_EX_TRACKSELECT and then monitor the LVN_HOTTRACK messages sent to the listview's parent. When monitoring this message, if iItem in NMLISTVIEW is -1 then the cursor is in the listview but is not over an item so no action should be taken. But otherwise you can send TTM_POPUP to the tooltip window.

This causes the tooltip to appear at the cursor and before doing so it will send TTN_NEEDTEXT to the window which was specified when the tooltip was associated with the listview using TTM_ADDTOOL.

To avoid sending TTM_POPUP each time the cursor moves in the listview control, only send it if hItem (and iSubItem if required to be tested) is different from the last time LVN_HOTTRACK was received.

Upvotes: 0

Geno Carman
Geno Carman

Reputation: 11

LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);

in report mode,at least, you will only get the message when mouse is over the 0th column

Upvotes: 0

rasmus
rasmus

Reputation: 3226

The problem is that you are replacing the pointer pszText. You need to modify the contents of the memory buffer instead. For example using StringCchPrintf.

Upvotes: 3

Indy9000
Indy9000

Reputation: 8881

Do you forget to set LVS_EX_INFOTIP ?

ListView_SetExtendedListViewStyle(hListView, LVS_EX_INFOTIP  | LVS_EX_LABELTIP);

look here for an example

Upvotes: 2

Related Questions