【发布时间】:2015-05-20 17:35:00
【问题描述】:
我在 vs2008 上有一个不支持 unicode 的项目,并且没有显示工具提示文本。我已经在另一个支持 unicode 的项目上尝试了相同的代码,它工作正常。我做错了什么?
BOOL CListCtrl_ToolTip::OnToolNeedText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
CPoint pt(GetMessagePos());
ScreenToClient(&pt);
int nRow, nCol;
CellHitTest(pt, nRow, nCol);
CString tooltip = GetToolTipText(nRow, nCol);
//MessageBox(tooltip,NULL, MB_OK);
if (tooltip.IsEmpty())
return FALSE;
// Non-unicode applications can receive requests for tooltip-text in unicode
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
lstrcpyn(pTTTA->szText, static_cast<LPCTSTR>(tooltip), sizeof(pTTTA->szText));
else
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
_wcstombsz(pTTTA->szText, static_cast<LPCTSTR>(tooltip), sizeof(pTTTA->szText));
else
lstrcpyn(pTTTW->szText, static_cast<LPCTSTR>(tooltip), sizeof(pTTTW->szText)/sizeof(WCHAR));
#endif
// If wanting to display a tooltip which is longer than 80 characters,
// then one must allocate the needed text-buffer instead of using szText,
// and point the TOOLTIPTEXT::lpszText to this text-buffer.
// When doing this, then one is required to release this text-buffer again
return TRUE;
}
工具提示字符串填充了所需的值,但文本未显示。分配 pTTW->szText 时会出现问题。我试图将我的字符串的地址分配给 lpszText,但工具提示显示中文符号或其他东西。
【问题讨论】: