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);
}
相关推荐
beijixinghe8 小时前
第15节 指针作为函数参数的工程实战用法
开发语言·c++·c++基础·c++入门·几何引擎c++
j7~8 小时前
【C++微服务项目开发脚手架】(准备篇)从 0 到跑通:Docker 容器开发环境 + 宿主机用户 + Trae 远程连接 全链路踩坑实战
linux·c++·学习·xshell·docker容器·trae
唠玖馆8 小时前
C++11
c++
云泽80810 小时前
从零搭建 WSL2 + Ubuntu C/C++ 开发环境:原理、实践与底层架构解析
linux·c++·windows·ubuntu·wsl2
初願致夕霞17 小时前
C++11:类型推导与完美转发复盘笔记
c++
小猪写代码17 小时前
C++中什么是类,什么是对象
c++
钓鱼的肝21 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
jimy11 天前
readelf 查看“派生类”的vtable符号
开发语言·c++
蒸蒸yyyyzwd1 天前
cpp 选手秋招学习笔记 day37 面经学习
c++·八股
YYYing.1 天前
【C++进阶系列 (七)】C++ RTTI 深度剖析:从 typeid 到 dynamic_cast 的底层之旅
开发语言·c++·c/c++·rtti