急等,多谢!!!

解决方案 »

  1.   

    处理WM_MOUSEMOVE消息就可以满足一般的需求了:
    重载了OnMouseMove(....,Point)时,那个Point就是鼠标的坐标:)
      

  2.   

    另外,你显示坐标的代码也可以放到OnMouseMove中。
      

  3.   

    在OnDraw函数中,利用Format函数把鼠标坐标转化为字符串,然后用TextOut在屏幕上输出鼠标坐标 .
      

  4.   

    重载WM_MOUSEMOVE消息,就可以捕获鼠标位置了
      

  5.   

    Point.x和Point.y就是鼠标的x,y坐标
      

  6.   


    #include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
    {
    static TCHAR szAppName[] = TEXT("MousePos");
    HWND         hWnd;
    MSG  msg;
    WNDCLASS     wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = szAppName; if (!RegisterClass (&wndclass))
    {
    MessageBox(NULL,TEXT("窗口类注册失败!"),szAppName,MB_ICONERROR);
    return 0;
    } hWnd = CreateWindow(szAppName,NULL,
    WS_CHILD | WS_VISIBLE,
    0,0,
    60,20,
    GetDesktopWindow(),NULL,hInstance,NULL);
    ShowWindow(hWnd,iCmdShow);
    UpdateWindow(hWnd); while (GetMessage(&msg,NULL,0,0) )
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return msg.wParam ;
    }LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    POINT       pt;
    TCHAR       Info[MAX_PATH]; switch ( message )
    {
    case WM_CREATE:
    SetTimer(hWnd,1000,100,NULL);
    return 0;
    case WM_PAINT:
    hdc = BeginPaint(hWnd,&ps);
    GetClientRect(hWnd,&rect);
    GetCursorPos(&pt);
    wsprintf(Info,TEXT("(%3d,%3d)"),pt.x,pt.y);
    DrawText(hdc,Info,-1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER );
    EndPaint(hWnd,&ps);
    return 0;
    case WM_TIMER:
    GetCursorPos(&pt);
    SetWindowPos(hWnd,NULL,pt.x,pt.y,0,0,SWP_NOZORDER | SWP_NOSIZE);
    InvalidateRect(hWnd,NULL,TRUE);
    return 0;
    case WM_DESTROY :
    KillTimer(hWnd,1000);
    PostQuitMessage(0);
    return 0;
    } return DefWindowProc(hWnd,message,wParam,lParam);
    }
      

  7.   


       用计时器每隔一小段时间取鼠标的位置就可以了。
       用WM_MOUSEMOVE消息是不行的,因为只有鼠标在窗口上面移动时,窗口才收到WM_MOUSEMOVE消息,要是鼠标不在窗口上面就收不到消息了。
       
       除了我给的用计时器解决的方法外,应该还可以用ToolTip控件,鼠标钩子等方法解决。
      

  8.   

    1. SetCapture/ReleaseCapture/WM_MOUSEMOVE
    2. 挂一个鼠标钩子
      

  9.   


      1. SetCapture/ReleaseCapture/WM_MOUSEMOVE
      是不行的,因为只有鼠标键被按下时,鼠标捕捉才有效,你不能要求用户在移动鼠标的时候总是按下一个鼠标键吧?
      

  10.   

    下面是 MSDN 2003 对SetCapture()函数的说明:SetCapture Function
    --------------------------------------------------------------------------------
    The SetCapture function sets the mouse capture to the specified window belonging to the current thread. SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down. Only one window at a time can capture the mouse.If the mouse cursor is over a window created by another thread, the system will direct mouse input to the specified window only if a mouse button is down.
      

  11.   

    MSDN这段话的意思是说,如果你在一个窗口SetCapture(),那么当鼠标移动到另一个线程创建的窗口,另一个窗口是收不到鼠标消息的(消息都捕获到设置SetCapture的窗口了),除非这时鼠标(在另一个窗口)按下。yaozijian110老兄不要误导群众。
      

  12.   

    下面是简单的显示鼠标处坐标的的代码。缺点是没有判断边界,因此移动到窗口外边会留下残影,解决方法就是SetCapture()。void CYourView::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    CClientDC dc(this);
    dc.SetBkColor(RGB(255, 255, 230));
    CString strPoint;
    strPoint.Format("x=%d,y=%d", m_ptOld);
    CSize szText;
    szText = dc.GetTextExtent(strPoint);
    CRect rcText;
    int iOffset = szText.cx / 2;
    rcText.SetRect(m_ptOld.x - iOffset, m_ptOld.y - szText.cy, m_ptOld.x + szText.cx - iOffset, m_ptOld.y);
    InvalidateRect(rcText, TRUE); strPoint.Format("x=%d,y=%d", point);
    szText = dc.GetTextExtent(strPoint);
    iOffset = szText.cx / 2;
    rcText.SetRect(point.x - iOffset, point.y - szText.cy, point.x + szText.cx - iOffset, point.y);
    ValidateRect(rcText);
    dc.TextOut(point.x - iOffset, point.y - szText.cy, strPoint);
    m_ptOld = point; CDialog::OnMouseMove(nFlags, point);
    }