博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MFC 获取picture控件的鼠标点击坐标位置的方法
阅读量:4123 次
发布时间:2019-05-25

本文共 878 字,大约阅读时间需要 2 分钟。

转载来自:http://blog.csdn.net/wesleyluo/article/details/7056026  

在一个自定义的Dialog中加入了picture控件,想要获取鼠标在该控件上的点击位置,遇到一些困难,最终解决了。方法如下:

     其实挺简单的,首先用自定义的Dialog类重载CDialog的PreTranslateMessage函数,并在其中用到了Dialog的OnLButtonDown函数(其实不用也行,我只是想把操作封在这个函数里)这样就可以通过此函数传递点击位置。

BOOL PrintDialog::PreTranslateMessage(MSG* pMsg)

{
// TODO: Add your specialized code here and/or call the base class

if(pMsg->message == WM_LBUTTONDOWN && GetDlgItem(IDC_PACKPIC)->GetSafeHwnd() == pMsg->hwnd)
   OnLButtonDown(MK_LBUTTON, pMsg->pt);   //在此传递点击部位在对话框中的坐标

return CDialog::PreTranslateMessage(pMsg);
}

接下来在Dialog中的OnLButtonDown函数中判段是否点在picture控件内(lRect是控件的区域)

if((point.x>=lRect.left && point.x<=lRect.right) && (point.y>=lRect.top && point.y<=lRect.bottom))

{

               //  通过对point的处理,获得实际在picture控件中的点击位置(坐标),完成。

CRect lRect;

GetDlgItem(IDC_PACKPIC)->GetWindowRect(&lRect);  //获取控件相对于屏幕的位置
point.x-=lRect.left;
point.y-=lRect.top;

}

你可能感兴趣的文章
新工作的第4天
查看>>
Product Investigation on Saturday
查看>>
Ideas from Software Process Training
查看>>
Another day
查看>>
First Impression Written Down
查看>>
This One-one Meeting
查看>>
If your Commute Card unavailable?
查看>>
Decided to take test
查看>>
About today’s daily meeting
查看>>
It’s not what I wanted
查看>>
郁可维最棒
查看>>
All of coincidence
查看>>
SQL SERVER和ORACLE 的TimeZone问题
查看>>
工程,工艺
查看>>
大对象,小对象
查看>>
自上而下,自下而上
查看>>
你认为Agile为什么会如此受欢迎?
查看>>
Allow Batch in ADO.NET
查看>>
应不应该使用存储过程的几个要点
查看>>
社会价值观的多元化
查看>>