一、前言

在编写dll工程的时候,我习惯生成一个MFC的exe进行测试dll的性能。然而有的时候dll中的某些接口的某个参数反对多种配置,这个时候去找对应的文档阐明感觉比拟麻烦,因而最好将文档中的对应阐明在界面中进行显示,这就防止了频繁的查看文档。

二、次要流程

1、定义CToolTipCtrl对象

在须要应用提醒的界面类中顶一个CToolTipCtrl对象

2、设置提示信息

在对应界面类的OnInitDialog函数中,实现如下的代码:

//提示信息m_Mytip.Create(this);CString strTip = _T("1——connect,\r\n 2——accept,\r\n 3——disconn,\r\n ");strTip.AppendFormat(_T("%s"), _T("1——url,\r\n 2——data,\r\n 3——ip_data,\r\n"));strTip.AppendFormat(_T("%s"),_T("0x40——dns,\r\n 0x80——smb,\r\n 0x1000——cb,\r\n"));strTip.AppendFormat(_T("%s"),_T("0x2000——add_rule,\r\n 0x4000——del_rule,\r\n 0x8000——notify_caller,\r\n"));strTip.AppendFormat(_T("%s"),_T("0x400000——block,\r\n 0x800000——allow\r\n"));m_Mytip.AddTool(GetDlgItem(IDC_EDIT_FLAGS), strTip);strTip = _T("1——in,\r\n 2——out,\r\n 3——both,\r\n 17——send,\r\n 18——recv\r\n");m_Mytip.AddTool(GetDlgItem(IDC_EDIT_DIRECTION), strTip);strTip = _T("1——ICMP,\r\n 6——TCP,\r\n 17——UDP\r\n");m_Mytip.AddTool(GetDlgItem(IDC_EDIT_PROT), strTip);strTip = _T("2——AF_INET,\r\n 23——AF_INET6\r\n");m_Mytip.AddTool(GetDlgItem(IDC_EDIT_IP_FAMILY), strTip);m_Mytip.SetDelayTime(TTDT_INITIAL, 100); //设置提早m_Mytip.SetDelayTime(TTDT_AUTOPOP, 20000);    //显示提醒工夫m_Mytip.SetMaxTipWidth(200);                //设置显示宽度,超长主动换行m_Mytip.SetTipTextColor( RGB(85,123,205) ); //设置提醒文本的色彩m_Mytip.SetTipBkColor( RGB(255,255,255)); //设置提示框的背景色彩m_Mytip.Activate(TRUE); //设置是否启用提醒

3、重写PreTranslateMessage函数

关上工程的Class View(Ctrl+Shift+C),找到应用CToolTipCtrl类的界面类,关上其属性,点击Oerrides

抉择PreTranslateMessage,此时在对应界面类中会生成一下内容:

//头文件virtual BOOL PreTranslateMessage(MSG* pMsg);//cpp文件BOOL CSetNetDrvRuleDialog::PreTranslateMessage(MSG* pMsg){    // TODO: Add your specialized code here and/or call the base class    return CDialog::PreTranslateMessage(pMsg);}

4、鼠标在控件上显示提醒内容

在PreTranslateMessage中增加代码

BOOL CSetNetDrvRuleDialog::PreTranslateMessage(MSG* pMsg){    // TODO: Add your specialized code here and/or call the base class    if(pMsg->message == WM_MOUSEMOVE )        m_Mytip.RelayEvent(pMsg);    return CDialog::PreTranslateMessage(pMsg);}

到此,当用户将鼠标移到到对应控件上时,会显示对应的提示信息