GetCursorPos
This function retrieves the cursor’s position, in screen coordinates. BOOL GetCursorPos(
LPPOINT lpPoint);
Parameters
lpPoint
[out] Long pointer to a POINT structure that receives the screen coordinates of the cursor.
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
This function retrieves the cursor’s position, in screen coordinates. BOOL GetCursorPos(
LPPOINT lpPoint);
Parameters
lpPoint
[out] Long pointer to a POINT structure that receives the screen coordinates of the cursor.
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
添加wm_move消息,在OnMove处理函数中能得到鼠标位置。
SetCapture肯定管用!我亲自试过,程序可以象Spy++一样定位其他程序窗口估计是你的代码不对……
行!/
//.......ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)//.......
//消息映射结束void CSpDlg::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT stTRACKMOUSEEVENT;
stTRACKMOUSEEVENT.cbSize = sizeof(stTRACKMOUSEEVENT);
stTRACKMOUSEEVENT.hwndTrack=m_hWnd;
stTRACKMOUSEEVENT.dwFlags=TME_LEAVE;
_TrackMouseEvent(&stTRACKMOUSEEVENT);
CDialog::OnMouseMove(nFlags, point);
}LRESULT CSpDlg::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{ /*这里检查鼠标位置 是为了避免鼠标滑过控件时候产生的WM_MOUSELEAVE干扰正常应用*/ POINT pt;
RECT rcWindow;
GetWindowRect( &rcWindow );
GetCursorPos( &pt );
if(pt.x > rcWindow.right ¦¦ pt.x < rcWindow.left
¦¦ pt.y < rcWindow.top ¦¦ pt.y > rcWindow.bottom)/*当鼠标移动到窗口矩形外*/
MessageBox("鼠标离开了对话框",NULL,MB_OK);
return 0;
}
////////////
另外SetCapture也是适用的,你用的有问题
你如果是类似Spy++中那样的情况,可以用SetCapture,否则只有用Hook了。