先说下,我不是通过硬件鼠标来控制鼠标(光标)的,目前我能通过那个设备来移动鼠标,现在的问题是我把鼠标移动到某点,比如说关闭按钮,当移动到关闭按钮的时候,然后我通过SendMessage(m_hWnd,WM_LBUTTONDOWN,0,0);函数来向应用程序发送鼠标左键点下的消息,那么这时这窗口就关闭了,在WinMain函数中我们使用的是,默认的 DefWindowProc (hWnd, message, wParam, lParam) ;函数来处理这个消息,并没有去截获它!但是无效,不知为什么?求达人指教!先行谢过了!!!!

解决方案 »

  1.   

    A window receives this message through its WindowProc function. 
      

  2.   

    在你的按钮的窗口回调函数中可以捕获到WM_LBUTTONDOWN,而不是你父窗口的窗口过程函数中
      

  3.   

    The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.A window receives this message through its WindowProc function. 
    好好理解MSDN上的这段话~
      

  4.   

    SendMessage(m_hWnd,WM_SYSCOMMND,SC_CLOSE,0);
      

  5.   

    c重写一个窗口回调函数或者用PostMessage试试
      

  6.   

    窗口是根据你发送消息所带的坐标参数判断鼠标点击的位置的,而不是根据你的当前鼠标的坐标位置
    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. 
      

  7.   

    DWORD dwPoint;
    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("单击"));
    这样改了还是不可以啊!
      

  8.   

    DWORD dwPoint;
    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);
    这样定义坐标对吗?
      

  9.   

    不是MAKEWORD
    是MAKELPARAM
    还要注意传入的坐标是针对窗口的
      

  10.   

    LPARAM dwPoint;
    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是相对于桌面的坐标,我发送消息是发送给处理桌面的消息函数