当前位置:首页 > 编程笔记 > 正文
已解决

MFC 鼠标悬停提示框

来自网友在路上 153853提问 提问时间:2023-10-11 07:56:44阅读次数: 53

最佳答案 问答题库538位专家为你答疑解惑

MFC 鼠标悬停提示框

运行效果

在这里插入图片描述

在MFC窗口中添加一个控件

  1. 工具栏中拖拽List Box到MFC窗口
  2. List Box添加变量 CListBox m_listbox

增加成员变量

CWnd* m_tip_parent_wnd;
CToolTipCtrl m_tip;

m_listbox创建提示框

void create_tip_window(CWnd* tip_wnd, CToolTipCtrl* tip)
{tip->Create(tip_wnd);tip->AddTool(tip_wnd, TTS_ALWAYSTIP);tip->SetTipTextColor(RGB(200, 0, 0);tip->SetDelayTime(500)
}
// 在 OnInitDialog 函数中调用如下代码:
m_tip_parent_wnd = &m_listbox;
create_tip_window(m_tip_parent_wnd, &m_tip);

重新 virtual BOOL PreTranslateMessage(MSG* pMsg)

BOOL PreTranslateMessage(MSG* pMsg)
{if (m_tip.m_hWnd != NULL){m_tip.RelayEvent(pMsg);}return CDialogEx::PreTranslateMessage(pMsg);
}

增加鼠标移动消息映射ON_WM_MOUSEMOVE()

BEGIN_MESSAGE_MAP(XXX, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

处理鼠标移动消息afx_msg void onm ouseMove(UINT nFlags, CPoint point);

void onm ouseMove(UINT nFlags, CPoint point)
{m_tip.UpdateTipText(_T("This is test text!"), m_tip_parent_wnd);CDialogEx::OnMouseMove(nFlags, point);
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"MFC 鼠标悬停提示框":http://eshow365.cn/6-18831-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!