I'm trying to override OnToolTipNotify for the CListCtrl to have tooltips that support more than 80 characters. I want the tooltips to appear for specific cells. I've seen a bunch of posts related to this, but none have completely helped me understand the best way to do this. Here is what I have so far, but I'm concerned with the wide char code that uses T2W. I read T2W uses memory off the stack and when the function returns it will be cleaned up. So, lpszText will become invalid. This seems to work though and I cannot find another way to do it.
BOOL CListCtrlEx::OnToolTipNotify(UINT tooldId, NMHDR* notifMsg, LRESULT result)
{
USES_CONVERSION;
TOOLTIPTEXTA* tttA = reinterpret_cast<TOOLTIPTEXTA*>(notifMsg);
TOOLTIPTEXTW* tttW = reinterpret_cast<TOOLTIPTEXTW*>(notifMsg);
...
int row, col;
cellHitTest(row, col);
CString tipStr;
// Note getTooltip() returns const ref to cell's tooltip string
if (-1 < row && -1 < col)
tipStr = m_Data[row]->colvals[col]->getTooltip();
if (tipStr.IsEmpty()) return FALSE;
if (TTN_NEEDTEXTA == notifMsg->code)
{
tttA->lpszText = tipStr.GetBuffer();
tttA->hinst = 0;
}
else
{
// Question: Is this a problem? Will the buffer pointed to
// by tttW->lpszText be deleted after this function ends
// making the pointer invalid?
tttW->lpszText = T2W(tipStr.GetBuffer());
tttW->hinst = 0;
}
...
}
ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnGetInfoTip)andvoid CMyListCtrlEx::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult)- sergiol