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);
}
相关推荐
hsjkdhs42 分钟前
C++文件操作
开发语言·c++
沐怡旸1 小时前
【穿越Effective C++】条款4:确定对象使用前已先被初始化——C++资源管理的基石
c++·面试
淀粉肠kk1 小时前
【C++】多态
c++
ceclar1232 小时前
C++Lambda表达式
开发语言·c++·算法
bkspiderx2 小时前
Linux网络与路由配置完全指南
linux·运维·网络·c++
慧都小妮子2 小时前
基于C++ UA Server SDK开发高性能与跨平台 OPC UA 服务器
c++·跨平台·高性能·opc ua·ua server sdk
INGNIGHT2 小时前
单词搜索 II · Word Search II
数据结构·c++·算法
楼田莉子3 小时前
C++学习:C++11关于类型的处理
开发语言·c++·后端·学习
彷徨而立3 小时前
【C/C++】只知道窗口句柄,如何擦除窗口内容,清理窗口?
c语言·c++·windows
強云3 小时前
匿名命名空间 - c++
c++