鼠标位置检测

cokeliu 2014-05-29 11:03:47
在对话框工程的MouseMove中我想检测鼠标光标是否在一个CStatic矩形框内.
GetDlgItem(IDC_TFT)->GetWindowRect(&MyProject.MyLayout.TFT_Mouse);
ScreenToClient(MyProject.MyLayout.TFT_Mouse);

void CTFT_ToolDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if(MyProject.MyLayout.TFT_Mouse.PtInRect(point))
{
.........
}
}
测试时候发现位置不是很准,请问是否需要做一个坐标转换?
...全文
171 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Кylin 2014-05-30
  • 打赏
  • 举报
回复
路过
cokeliu 2014-05-30
  • 打赏
  • 举报
回复
实际测试时候比较鼠标明明放在CStatic方框内了,但鼠标坐标显示在方框外,应该是鼠标坐标显示比实际小些,怎么转换到对话框的控件坐标系统做比较呢.
Saleayas 2014-05-30
  • 打赏
  • 举报
回复
GetWinowRect 想对于 屏幕 Points to a CRect object or a RECT structure that will receive the screen coordinates of the upper-left and lower-right corners. OnLButtonDown 相对于 控件. Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window.
赵4老师 2014-05-30
  • 打赏
  • 举报
回复
Coordinate Space and Transformation Functions The following functions are used with coordinate spaces and transformations. ClientToScreen CombineTransform DPtoLP GetCurrentPositionEx GetGraphicsMode GetMapMode GetViewportExtEx GetViewportOrgEx GetWindowExtEx GetWindowOrgEx GetWorldTransform LPtoDP MapWindowPoints ModifyWorldTransform OffsetViewportOrgEx OffsetWindowOrgEx ScaleViewportExtEx ScaleWindowExtEx ScreenToClient SetGraphicsMode SetMapMode SetViewportExtEx SetViewportOrgEx SetWindowExtEx SetWindowOrgEx SetWorldTransform
微型蚂蚁 2014-05-29
  • 打赏
  • 举报
回复
可以全部变换到屏幕坐标判断,因为OnLButtonDown的坐标位置好像是相对于窗口左上角,不是客户区的左上角,相差了几个像素。
信阳毛尖 2014-05-29
  • 打赏
  • 举报
回复
感觉逻辑上没有啥问题啊

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧