可以进行列表控制以可靠地显示工具提示吗? [英] Can a list control be made to display tool tips reliably?

查看:116
本文介绍了可以进行列表控制以可靠地显示工具提示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当列表控件( CListCtrl )具有扩展样式 LVS_EX_INFOTIP 时,将鼠标指针悬停在一个项目上以椭圆形结束(...)并不总是会产生显示

全文的工具提示。有什么可以做的吗?



以下网页讨论了这个问题,但没有完全回答。

https://开头social.msdn.microsoft.com/Forums/vstudio/en-US/4aae2b02-39af-4cd9-b685-20ebadd14738/tooltip-on-clistctrl-lvsexlabeltip-lvsexinfotip-problem



我尝试了什么:



作为解决方法,我调整列的大小以匹配内容:

When a list control (CListCtrl) has the extended style LVS_EX_INFOTIP, resting the mouse pointer over an item that ends in ellipses (...) does not always result in a tool tip that shows the
full text. Is there anything that can be done about this?

The following web page discusses this problem but does not answer it completely.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/4aae2b02-39af-4cd9-b685-20ebadd14738/tooltip-on-clistctrl-lvsexlabeltip-lvsexinfotip-problem

What I have tried:

As a workaround, I resize columns to match the content:

m_lc.SetColumnWidth (n, LVSCW_AUTOSIZE_USEHEADER);

但是,这不能解决问题。

However, this does not fix the problem.

推荐答案

解决方案可能正在处理 OnToolHitTest 并自己显示工具提示。



来自的代码片段现有项目(编辑和缩短):

A solution might be handling OnToolHitTest and displaying the tooltip yourself.

Code snippet from an existing project (edited and shortened):
INT_PTR CMyListCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
    // Check if clicked inside list area (including header). 
    // Must use client rect to exclude scroll bars.
    CRect rectList;
    GetClientRect(&rectList);
    if (!rectList.PtInRect(point))
        return CListCtrl::OnToolHitTest(point, pTI);

    LVHITTESTINFO tHitTest;
    tHitTest.pt = point;
    // CListCtrl::SubItemHitTest() is not declared as const.
    // However, it is an inline function doing this (see afxcmn2.inl):
    ::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, 0, reinterpret_cast<LPARAM>(&tHitTest));
    // on empty row or dummy column
    if (tHitTest.iItem < 0)
        return -1;

    // Again, CListCtrl::GetSubItemRect() is not declared as const.
    // So send message here (see winctrl2.cpp).
    RECT rect;
    rect.top = tHitTest.iSubItem;
    rect.left = LVIR_BOUNDS;
    if (!::SendMessage(m_hWnd, LVM_GETSUBITEMRECT, tHitTest.iItem, reinterpret_cast<LPARAM>(&rect)))
        return -1;

    CString strTipText;
    	
    // Check if on header.
    // This requires knowing the height of the header.
    // GetHeaderHeight() must be implemented yourself!
    int nHeaderHeight = GetHeaderHeight();
    if (tHitTest.iItem == 0 && point.y < nHeaderHeight)
    {
        HDITEM hdi; 
        // EDIT: Replaced char by TCHAR
        TCHAR buf[255];
        hdi.mask = HDI_TEXT;
        hdi.cchTextMax = sizeof(buf) / sizeof(TCHAR);
        hdi.pszText = buf;
        GetHeaderCtrl()->GetItem(tHitTest.iSubItem, &hdi); 
        strTipText = hdi.pszText;
    }
    else
        strTipText = GetItemText(tHitTest.iItem, tHitTest.iSubItem);
    int nSize = strTipText.GetLength();
    if (0 == nSize)
        return -1;
	
    // Make an ID from row and column number used also as return value.
    // We must add 1 to ensure that ID is not zero.
    // Even when passing the tooltip text here, we must return a unique ID.
    // Tooltips are not displayed when returning the same ID value as for the last call.
    pTI->uId = (UINT)((tHitTest.iItem << 8) + (tHitTest.iSubItem & 0xff) + 1);
    pTI->rect = rect;
    pTI->hwnd = m_hWnd;
    
    // Passing tool tip text using an allocated buffer.
    // By specifying the tooltip text here, we can omit the OnToolTipNotify handler.
    // If text is passed by pointer and pTI->hinst is NULL, the memory must be allocated from the local heap.
    // FilterToolTipMessage() will free the memory (see tooltip.cpp from MFC).
    // Using this allows tooltip text with more than 80 characters.
    pTI->lpszText = new TCHAR [++nSize];
    _tcscpy(pTI->lpszText, strTipText.GetString());
    pTI->hinst = NULL;
    return pTI->uId;
}


这篇关于可以进行列表控制以可靠地显示工具提示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆