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);
}
相关推荐
Forget the Dream1 小时前
设计模式之责任链模式
java·c++·设计模式·责任链模式
停止重构1 小时前
【开源】低代码 C++程序框架,Linux多线程程序
c++·低代码·多线程·开源框架·云计算引擎
Duramentee1 小时前
C++ 设计模式 十二:责任链模式 (读书 现代c++设计模式)
c++·设计模式·责任链模式
_GR1 小时前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
萌の鱼1 小时前
leetcode 3183. 达到总和的方法数量
数据结构·c++·算法·leetcode
Forget the Dream2 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
攻城狮7号4 小时前
【第十节】C++设计模式(结构型模式)-Flyweight( 享元)模式
c++·设计模式·享元模式
Forget the Dream4 小时前
设计模式之享元模式
java·c++·设计模式·享元模式
溟洵8 小时前
【C/C++】理解C++内存与Linux虚拟地址空间的关系---带你通透C++中所有数据
linux·c语言·c++
Chandler2410 小时前
C++11 智能指针:unique_ptr、shared_ptr和weak_ptr 功能特性 模拟实现
开发语言·c++