My Tech
自信丶思考、总结

例如我们想在一个对话框中的一个button控件添加tooltip,实现的方法如下:

1. 在该对话框的类中添加一个CToolTipCtrl类型成员,并在适当的地方将其初始化如下:

m_ToolTipCtrl.Create(this);
m_ToolTipCtrl.AddTool(GetDlgItem(IDC_BUTTON1), _T("This is ToolTip"));
m_ToolTipCtrl.SetMaxTipWidth(123);
m_ToolTipCtrl.Activate(TRUE);

2. 给对画框类添加virtual BOOL PreTranslateMessage(MSG* pMsg)方法并实现如下:

BOOL CtooltipsDlg::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP)
m_ToolTipCtrl.RelayEvent(pMsg);
return CDialogEx::PreTranslateMessage(pMsg);
}

OK,现在当鼠标划过该button,就会出现This is ToolTip字样的Tooltip。很简单,留着以后用。

posted on 2012-08-27 23:17  TheAnotherWei  阅读(4411)  评论(0编辑  收藏  举报