天天看点

C++ tooltip

1..h 定义

CToolTipCtrl m_ToolTip; 

2. .cpp创建显示

初始化函数中:

CRect rectTip;

GetDlgItem(IDC_XXX)->GetWindowRect(&rectTip);

ScreenToClient(&rectTip);

EnableToolTips(TRUE);

m_ToolTip.Create(this, TTS_ALWAYSTIP);

m_ToolTip.AddTool(this, g_szTipText, rectTip, 1);  //用此方法不受控件的enable状态限制

m_ToolTip.SetTipBkColor(COLORREF(RGB(255, 255, 255))); //background color 

m_ToolTip.SetMaxTipWidth(300);

m_ToolTip.SetDelayTime(TTDT_INITIAL, 5);      //鼠标指向多久后显示提示,毫秒

m_ToolTip.SetDelayTime(TTDT_AUTOPOP, 30000);  //鼠标保持指向,提示显示多久,毫秒

m_ToolTip.Activate(TRUE); //显示 如若不让其显示 设为F

BOOL CDlgApiSimple::PreTranslateMessage( MSG* pMsg )

{

// TODO: Add your specialized code here and/or call the base class

if (NULL != m_ToolTip.GetSafeHwnd())

{

m_ToolTip.RelayEvent(pMsg);

}

return CDialog::PreTranslateMessage(pMsg);

}

//--------------------------------------------------------over------------------------------------------------------------------------