Saturday, February 20, 2010

List View ToolTip issue in Windows XP

In Windows XP, if the List View item text [item name] is long, the tooltip may not show all the characters, and may be truncated. In Vista and 2000, it is managed by the OS itself.

Fix:

Just before the tooltip is displayed, the List View will give LVN_GETINFOTIP notification. In the handler for that, we can get the Tooltip info. Structure by

LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP) lParam;
if( wcslen ( pGetInfoTip->pszText )) {

//do the string processing on pGetInfoTip->pszText

Set the value of pGetInfoTip->pszText.

StringCbCopyW( pGetInfoTip->pszText, (wcslen( pwzTmp ) + 1) * sizeof(WCHAR) , pwzTmp)); //Setting the tooltip text

// LVN_GETINFOTIP notification will be obtained only if we set the Listview extended style

DWORD ex_style = ListView_GetExtendedListViewStyle(hwndLView);
ex_style |= LVS_EX_LABELTIP | LVS_EX_INFOTIP;
ListView_SetExtendedListViewStyle(hwndLView , ex_style);

//String Processing

HGDIOBJ hFont = reinterpret_cast(SendMessage( hwndListView, (UINT) WM_GETFONT, (WPARAM) 0, (LPARAM)0 ) );

HGDIOBJ hOldFont = SelectObject( hLViewDC , hFont );

GetTextExtentPoint32( hLViewDC , (LPCTSTR)pwzTmp, nLineWidth , &sSize );
if( sSize.cx >= ( nWidth ) ){
pwzDestnText[nDestnIndex] = L'\n';
nDestnIndex++;
. . .

[The Tooltip text is extracted, manipulated and set back to the tooltip structure.]

No comments:

Post a Comment