您的位置:首页 > 其它

跟随鼠标的移动,动态显示提示信息

2009-11-27 00:23 645 查看


图1

这几天在做一些图像处理方面的小程序。在进行空间域图像处理的时候,我需要利用对比拉伸对一幅图像进行增强。这是无关紧要的前奏,

关键是我对一幅图像进行对比拉伸前必须设置好相关的参数。“图1”便是设置参数时弹出的对话框。

图中红色椭圆圈起来的东东便是鼠标移动到点(85,20)时给出它的位置坐标的提示信息。那么这个提示信息该如何来实现呢?

第一步:对话框类的头文件中添加变量

CToolTipCtrl m_toolTipCtrl;

第二步:重载对话框的OnInitDialog()函数,并添加以下代码:

BOOL CContrastStretchParasDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: 在此添加额外的初始化
m_toolTipCtrl.Create(this);
m_toolTipCtrl.AddTool(this,_T(""));
m_toolTipCtrl.SetDelayTime(0);
m_toolTipCtrl.Activate(true);


return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}

第三步:重载对话框类的PreTranslateMessage(MSG* pMsg)函数,并添加以下代码:

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

return CDialog::PreTranslateMessage(pMsg);
}

第四步:处理WM_MOUSEMOVE事件:

void CContrastStretchParasDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRect rect;
this->GetClientRect(&rect);

// 首先画正方形
rect.left += 50;
rect.top += 10;
rect.bottom = rect.top + 255;
rect.right = rect.left + 255;

CString str;

// 进入(r1,s1)的势力范围
if( ( point.x >= (rect.left+m_r1-1) && point.x <= (rect.left+m_r1+1) &&
point.y >= (rect.bottom-m_s1-1) && point.y <= (rect.bottom-m_s1+1) ) )
{
str.Format(_T("[%d,%d]"),m_r1,m_s1);
m_toolTipCtrl.UpdateTipText(str,this);
}else if( ( point.x >= (rect.left+m_r2-1) && point.x <= (rect.left+m_r2+1) &&
point.y >= (rect.bottom-m_s2-1) && point.y <= (rect.bottom-m_s2+1) ) )
{
str.Format(_T("[%d,%d]"),m_r2,m_s2);
m_toolTipCtrl.UpdateTipText(str,this);
}else{
//str.Format(_T(""));
m_toolTipCtrl.UpdateTipText(_T(""),this);
}


CDialog::OnMouseMove(nFlags, point);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: