MFC 鼠标悬停提示框

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 OnMouseMove(UINT nFlags, CPoint point);

复制代码
void OnMouseMove(UINT nFlags, CPoint point)
{
	m_tip.UpdateTipText(_T("This is test text!"), m_tip_parent_wnd);
	CDialogEx::OnMouseMove(nFlags, point);
}
相关推荐
Code Warrior4 分钟前
【每日算法】专题五_位运算
开发语言·c++
OneQ6665 小时前
C++讲解---创建日期类
开发语言·c++·算法
Coding小公仔7 小时前
C++ bitset 模板类
开发语言·c++
菜鸟看点7 小时前
自定义Cereal XML输出容器节点
c++·qt
悲伤小伞8 小时前
linux_git的使用
linux·c语言·c++·git
ysa0510309 小时前
数论基础知识和模板
数据结构·c++·笔记·算法
小小小小王王王12 小时前
求猪肉价格最大值
数据结构·c++·算法
岁忧12 小时前
(LeetCode 面试经典 150 题 ) 58. 最后一个单词的长度 (字符串)
java·c++·算法·leetcode·面试·go
码农编程录13 小时前
【c/c++3】类和对象,vector容器,类继承和多态,systemd,std&boost
c++
??tobenewyorker14 小时前
力扣打卡第二十一天 中后遍历+中前遍历 构造二叉树
数据结构·c++·算法·leetcode