现在,当我将鼠标悬停在编辑框上时,会弹出一个工具提示。问题是这个工具提示包含多个错误消息,并且它们都在一行上。我需要让每个错误消息都单独占据一行。错误消息包含在一个CString中,并用换行符分隔。
下面是我的现有代码。
BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
// need to handle both ANSI and UNICODE versions of the message
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
// TCHAR szFullText[256];
CString strTipText=_T("");
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
}
//m_errProjAccel[ch] contains 1 or more error messages each seperated by a new line.
if((int)nID >= ID_PROJECTED_ACCEL1 && (int)nID < ID_PROJECTED_ACCEL1 + PROJECTED_ROWS -1 ) {
int ch = nID - ID_PROJECTED_ACCEL1;
strTipText = m_errProjAccel[ch];
}
#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0]));
else
_mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0]));
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
_wcstombsz(pTTTA->szText, strTipText, sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0]));
else
lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0]));
#endif
*pResult = 0;
// bring the tooltip window above other popup windows
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
return TRUE; // message was handled
}
pTTT->lpszText = const_cast<LPTSTR>(static_cast<LPCTSTR>(strTipText));
- Mangs