#include <iostream>
#include <windowsh>
int main()
{
POINT pt;
while(1)
{
GetCursorPos(&pt);//调用API函数
printf("%d,%d\n",ptx,pty);
Sleep(100);
}
return 0;
}
首先在视图类(或框架类)中添加一个CPoint m_pt的成员变量,然后在视图类中添加鼠标左击消息处理WM_LBUTTONDOWN即为:
void CMy48View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pt=point;
CView::OnLButtonDown(nFlags, point);
}这样就将鼠标左键的点保存在m_pt中了
重写你的控件 (派生类)
这里拿一个 按钮控件做比喻:
自己写一个按钮类(CBTN) 继承自CButton
响应OnMouseMove()消息
void CBTN::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
if(rectPtInRect(point)){
MessageBox("鼠标位于按钮内!");
}
CButton::OnMouseMove(nFlags, point);
}
以上就是关于mfc获取鼠标位置并显示全部的内容,包括:mfc获取鼠标位置并显示、mfc单击鼠标左键获得当前鼠标的坐标、如何获取鼠标在控件中位置.MFC和API都行 谢谢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)