我发现如果将 TTF_TRACK 标志设置为 CTooltipCtrl,SetDelayTime 不再起作用,因此工具提示不会自动消失。我想在指定控件下方显示工具提示,并希望它在几秒钟后消失(时间可以用 SetDelayTime 设置)。任何人都可以帮助我吗?
这是我构建工具提示的步骤:
1. Add member variable
CToolTipCtrl m_tooltip;
2. override PreTranslateMessage
BOOL CPF_GetSetNameDlg::PreTranslateMessage( MSG* pMsg )
{
switch (pMsg->message)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_MOUSEMOVE:
m_tooltip.RelayEvent(pMsg);
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
3. OnInitialDialog
BOOL CPF_GetSetNameDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//tooltip
EnableToolTips();
m_tooltip.Create(this , WS_POPUP | TTS_NOPREFIX | TTS_BALLOON);
m_tooltip.SetDelayTime(TTDT_INITIAL, 0);
m_tooltip.SetDelayTime(TTDT_AUTOPOP, 30000);
m_tooltip.SetDelayTime(TTDT_RESHOW, 30000);
m_tooltip.AddTool(GetDlgItem(IDC_SETNAME), _T(""));
m_tooltip.SetMaxTipWidth(600);
}
4. Control to show tool tip
if(bShow)
{
m_tooltip.UpdateTipText(_T("Hello, money~"), pWnd);
CToolInfo sTinfo;
m_tooltip.GetToolInfo(sTinfo, pWnd);
sTinfo.uFlags = TTF_TRACK;
m_tooltip.SetToolInfo(&sTinfo);
CRect rect;
pWnd->GetWindowRect(rect);
m_tooltip.SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)MAKELONG(rect.left, rect.bottom));
m_tooltip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM)&sTinfo );
}