简体   繁体   English

如何获取对话框上的列表控件的多行工具提示?

[英]How to get multiline tooltip for a list control on a dialog box?

As text on my list box is very huge I am trying to get multiline a tooltip on the list control. 由于列表框上的文本非常大,因此我试图在列表控件上多行显示工具提示。

BOOL CTestDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    mylist.EnableToolTips(TRUE);
    mylist.SetExtendedStyle(LVS_EX_INFOTIP | mylist.GetExtendedStyle());

    mylist.InsertColumn(0, L"suri", LVCFMT_LEFT, 10000);
    CString str1 = L"nonNegativeInteger GetVehicleOwnerHolderByRegNumAndDateResponse.GetVehicleOwnerHolderByRegNumAndDateResult[optional].GetVehicleOwnerHolderByRegNumAndDateResultType.VHOwnerHolderResponse.VHOwnerHolderResponseType.Body.VehicleCountries.VehicleCountriesType.VehicleCountry[1, unbound].VehicleCountryType.VehCountryReplies.VehCountryRepliesType.VehCountryReply[1, unbound].Messages[optional].Message[1, unbound].MessageType.MessageCode"; 
    for (int i = 0; i < 20 ; i++) {
        CString str2;
        str2.Format(L"%d",i);
        str2 = str2 + str1;
        mylist.InsertItem(LVIF_TEXT | LVIF_PARAM, i, str2, 0, 0, 0, NULL);
    }

    return TRUE;  // return TRUE  unless you set the focus to a control
}

I am getting following output which is truncated text ie complete text is missing. 我正在跟随以下输出,该输出是截断的文本,即缺少完整的文本。 在此处输入图片说明

How to get text on tooltip multiline? 如何在工具提示多行上获取文本?

EDIT: I used following also. 编辑:我也使用以下。 still same result. 还是一样的结果。

CToolTipCtrl* pToolTip = AfxGetModuleThreadState()->m_pToolTip;
   if (pToolTip)
      pToolTip->SetMaxTipWidth(SHRT_MAX);

You can get multi-line tooltips using newlines-charecters with SetMaxTipWidth() set to a large value. 您可以使用将SetMaxTipWidth()设置为较大值的换行符来获取多行工具提示。 And if calling SetMaxTipWidth() with a small value, then it will automatically break into multiple lines when meeting a space-character. 如果使用较小的值调用SetMaxTipWidth() ,则遇到空格字符时它将自动分成多行。

You need to subclass your tooltip/infotip in order to use it: 您需要对工具提示/信息提示进行子类化才能使用它:

BEGIN_MESSAGE_MAP(CListCtrl_InfoTip, CListCtrl)
    ON_NOTIFY_REFLECT_EX(LVN_GETINFOTIP, OnGetInfoTip)
    ON_NOTIFY_EX(TTN_NEEDTEXTA, 0, OnToolNeedText)
    ON_NOTIFY_EX(TTN_NEEDTEXTW, 0, OnToolNeedText)
END_MESSAGE_MAP()

void CListCtrl_InfoTip::PreSubclassWindow()
{
    CListCtrl::PreSubclassWindow();
    SetExtendedStyle(LVS_EX_INFOTIP | GetExtendedStyle());
}

BOOL CListCtrl_InfoTip::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult)
{
    // Will only request tooltip for the label-column
    NMLVGETINFOTIP* pInfoTip = (NMLVGETINFOTIP*)pNMHDR;
    CString tooltip = GetToolTipText(pInfoTip->iItem, pInfoTip->iSubItem);
    if (!tooltip.IsEmpty())
    {
        _tcsncpy(pInfoTip->pszText, static_cast<LPCTSTR>(tooltip), pInfoTip->cchTextMax);
    }
    return FALSE;    // Let parent-dialog get chance
}

BOOL CListCtrl_InfoTip::OnToolNeedText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
...
   // Break tooltip into multiple lines if it contains newlines (\r\n)
   CToolTipCtrl* pToolTip = AfxGetModuleThreadState()->m_pToolTip;
   if (pToolTip)
      pToolTip->SetMaxTipWidth(SHRT_MAX);
...
}

There are two aspects to consider: 有两个方面需要考虑:

1. The size of the window 1.窗口大小

To activate multilines mode. 激活多行模式。 This instruction is sufficient : 该说明就足够了:

 pToolTip->SetMaxTipWidth(SHRT_MAX);

2. Number of characters to display 2.要显示的字符数

For this second point it is necessary to be wary because the size of the field pszText is limited to 80 characters : 对于第二点,有必要提防,因为pszText字段的大小限制为80个字符

typedef struct tagNMTTDISPINFOA {
NMHDR hdr;
LPSTR lpszText;
char szText[80];
...
}

Therefore, even if you change SetMaxTipWidth you will not see any difference. 因此,即使更改SetMaxTipWidth ,也不会看到任何差异。 I suggest you to use the lpszText field which has no limit. 我建议您使用无限制的lpszText字段。 Below is the code fragment that interests you: 以下是您感兴趣的代码片段:

pTTTW->lpszText = T2W (strTipText.GetBuffer (strTipText.GetLength ()));

Where strTipText is the CString that contains the message to show in the pop-up 其中strTipText是包含要在弹出窗口中显示的消息的CString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM