MFC 提示框随鼠标移动动态响应

为鼠标添加动态的提示框。

当鼠标在图片控件的图像区域中移动时,动态跟新鼠标移动过程中图像的像素。

1. 新建对话框项目


在这里插入图片描述在这里插入图片描述在这里插入图片描述

2. 添加一个CToolTipCtrl变量

在对话框头文件ADDToolTipDlg.h中添加一个相应的CToolTipCtrl类型的变量:

CToolTipCtrl m_toolTipCtrl;

3. 在对话框OnInitDialog()中加载提示框

在ADDToolTipDlg.cpp的OnInitDialog()中添加:

/*提示框*/
	m_toolTipCtrl.Create(this);
	m_toolTipCtrl.AddTool(this, _T(""));
	m_toolTipCtrl.SetDelayTime(0);
	m_toolTipCtrl.Activate(true);

4. 重写对话框的PreTranslateMessage消息

在这里插入图片描述
添加代码:

BOOL CADDToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	m_toolTipCtrl.RelayEvent(pMsg);
	return CDialogEx::PreTranslateMessage(pMsg);
}

5. 添加鼠标移动响应函数

void CADDToolTipDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CString str;
	str.Format(_T("[%d ,%d] "),point.x, point.y);
	m_toolTipCtrl.UpdateTipText(str, this);
	CDialogEx::OnMouseMove(nFlags, point);
}


源码:ADDToolTip.rar

posted @ 2020-09-29 11:18  WaitFoF❤  阅读(311)  评论(0编辑  收藏  举报