1,.h
CToolTipCtrl m_tooltip;
2,.cpp
CXXXXX::CXXXXX()
{
......
m_tooltip.m_hWnd = NULL;
}
3,
BOOL CXXXXX::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
InitToolTip();
m_tooltip.RelayEvent(pMsg);
return CXXXXX::PreTranslateMessage(pMsg);
}
4,
void CXXXXX::InitToolTip()
{
if (m_tooltip.m_hWnd == NULL)
{
// Create ToolTip control
m_tooltip.Create(this);
// Create inactive
m_tooltip.Activate(FALSE);
// Enable multiline
m_tooltip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400);
} // if
}
5,
void CXXXXX::SetToolTipText(LPCTSTR lpstr,BOOL bActivate)
{
// We cannot accept NULL pointer
if (lpstr == NULL) return;
// Initialize ToolTip
InitToolTip();
// If there is no tooltip defined then add it
if (m_tooltip.GetToolCount() == 0)
{
CRect rectBtn;
GetClientRect(rectBtn);
m_tooltip.AddTool(this, lpstr, rectBtn, 1);
} // if
// Set text for tooltip
m_tooltip.UpdateTipText(lpstr, this, 1);
m_tooltip.Activate(bActivate);
}