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. 

解决方案 »

  1.   

    鼠标在窗体中:
    添加wm_move消息,在OnMove处理函数中能得到鼠标位置。
      

  2.   

    没有用!在WM_MOUSEMOVE只能处理当前当前窗体的消息!离开窗体后,它接受不到该消息
      

  3.   

    allisone:问题是我离开窗体后窗体怎样得到消息?只有得到不在该窗体的消息时,我才能针对消息处理GETCURPOS呀!不知我说明白没有!鼠标离开窗体A,A如何继续接受消息?是哪个消息或过程来处理?
      

  4.   


    SetCapture肯定管用!我亲自试过,程序可以象Spy++一样定位其他程序窗口估计是你的代码不对……
      

  5.   

    SetCapture,我用过的!/
    行!/
      

  6.   

    利用_TrackMouseEvent具体实现://填加消息映射
    //.......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 &brvbar;&brvbar; pt.x < rcWindow.left
            &brvbar;&brvbar; pt.y < rcWindow.top &brvbar;&brvbar; pt.y > rcWindow.bottom)/*当鼠标移动到窗口矩形外*/
        MessageBox("鼠标离开了对话框",NULL,MB_OK);
        return 0;
    }
    ////////////
    另外SetCapture也是适用的,你用的有问题
      

  7.   

    SetCapture不是没问题,是有很大的问题!在Win16下SetCapture一切工作正常,但在Win32下SetCapture只能捕获到本进程创建的窗口,对其他进程的窗口无能为力。只有一种情况例外:就是像Spy++中那样,按下鼠标键不要释放,此时能捕捉到WM_MOUSEMOVE和最后的WM_LBUTTONUP消息。
    你如果是类似Spy++中那样的情况,可以用SetCapture,否则只有用Hook了。