先说下,我不是通过硬件鼠标来控制鼠标(光标)的,目前我能通过那个设备来移动鼠标,现在的问题是我把鼠标移动到某点,比如说关闭按钮,当移动到关闭按钮的时候,然后我通过SendMessage(m_hWnd,WM_LBUTTONDOWN,0,0);函数来向应用程序发送鼠标左键点下的消息,那么这时这窗口就关闭了,在WinMain函数中我们使用的是,默认的 DefWindowProc (hWnd, message, wParam, lParam) ;函数来处理这个消息,并没有去截获它!但是无效,不知为什么?求达人指教!先行谢过了!!!!
好好理解MSDN上的这段话~
SendMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,坐标);
或者
PostMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,坐标);坐标的格式如下:
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
dwPoint = MAKEWORD(temp1.x,temp1.y);
if(dis>40)
{
/*SendMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
SendMessage(m_hWnd,WM_LBUTTONUP,MK_LBUTTON,dwPoint);*/ PostMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
PostMessage(m_hWnd,WM_LBUTTONUP,MK_LBUTTON,dwPoint); SetDlgItemText(m_hWnd,IDC_EDIT_CLICK,TEXT("单击"));
这样改了还是不可以啊!
dwPoint = MAKEWORD(temp1.x,temp1.y);
if(dis>40)
{
/*SendMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
SendMessage(m_hWnd,WM_LBUTTONUP,MK_LBUTTON,dwPoint);*/ PostMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
PostMessage(m_hWnd,WM_LBUTTONUP,MK_LBUTTON,dwPoint);
这样定义坐标对吗?
是MAKELPARAM
还要注意传入的坐标是针对窗口的
dwPoint = MAKELPARAM(temp1.x,temp1.y);
if(dis>40)
{
/*SendMessage(m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
SendMessage(m_hWnd,WM_LBUTTONUP,MK_LBUTTON,dwPoint);*/ PostMessage(m_hDesk,WM_LBUTTONDOWN,MK_LBUTTON,dwPoint);
PostMessage(m_hDesk,WM_LBUTTONUP,MK_LBUTTON,dwPoint); SetDlgItemText(m_hWnd,IDC_EDIT_CLICK,TEXT("单击"));
}temp是相对于桌面的坐标,我发送消息是发送给处理桌面的消息函数