关于mfc:MFC界面控件显示提示信息

8次阅读

共计 1907 个字符,预计需要花费 5 分钟才能阅读完成。

一、前言

在编写 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);
}

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

正文完
 0