我先取得程序的句柄,
然后用PostMessage(hWnd, WM_MOUSEMOVE, 0, 0)
虽然能检测到消息确实发送到了,但是却没有任何反应。
谁能帮我解决这个问题?

解决方案 »

  1.   

    你要响应什么?你这样的写法:
    1.鼠标坐标无效,因为你对lParam参数是直接“0”
    2.没有按键WM_MOUSEMOVE
    The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse. WM_MOUSEMOVE 
    fwKeys = wParam;        // key flags 
    xPos = LOWORD(lParam);  // horizontal position of cursor 
    yPos = HIWORD(lParam);  // vertical position of cursor 
     
    Parameters
    fwKeys 
    Value of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: Value Description 
    MK_CONTROL Set if the ctrl key is down. 
    MK_LBUTTON Set if the left mouse button is down. 
    MK_MBUTTON Set if the middle mouse button is down. 
    MK_RBUTTON Set if the right mouse button is down. 
    MK_SHIFT Set if the shift key is down. 
    xPos 
    Value of the low-order word of lParam. Specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
    yPos 
    Value of the high-order word of lParam. Specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
      

  2.   

    Option Explicit
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()
     Dim X As Long
     Dim Y As Long
     Dim a As Long
     Dim mHwnd As Long
     mHwnd = 2425730 'Form2.Command1.hwnd
     X = 81
     Y = 81
     a = PostMessage(mHwnd, WM_LBUTTONDOWN, 0, (X And &HFFFF) + (Y And &HFFFF) * &H10000)
     a = PostMessage(mHwnd, WM_LBUTTONUP, 0, (X And &HFFFF) + (Y And &HFFFF) * &H10000)
    ' a = PostMessage(mHwnd, WM_LBUTTONDOWN, 0, (X And &HFFFF) + (Y And &HFFFF) * &H10000)
    ' a = PostMessage(mHwnd, WM_LBUTTONUP, 0, (X And &HFFFF) + (Y And &HFFFF) * &H10000)
     
     '连续发两次可以触发Click事件
    End SubPrivate Sub Form_Load()
       Form2.Show
    End Sub
      

  3.   

    在窗体的鼠标事件里面还要响应一下 MsgBox就行了
      

  4.   

    我通过用子类处理对我的窗体消息进行监测发现,
    对于单击鼠标左键这个动作会给窗体发送几个消息,比如:(LPARAM为坐标值,
    消息名称均以其值对应书写。)
    WM_NCHITTEST, 0, LPARAM 
    WM_NCHITTEST, 0, LPARAM
    WM_SETCURSOR, WM_LBUTTONDOWN, WM_LBUTTONUP
    WM_LBUTTONDOWN, MK_LBUTTON, LPARAM
    WM_LBUTTONUP, 0, LPARAM
    &H215, 0, 0      // 在api viewer里没有找到这个常数,猜测或许是单击事件的消息编号?
    ...
    看来在鼠标单击发生后系统底层还做了许多处理,
    因此简单地发送一个WM_LBUTTONDOWN过去似乎不能解决问题……
    这也或许是发送的WM_LBUTTONDOWN不起作用的原因?
    希望有高手能答疑。
      

  5.   

    还有就是 mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 100, 100, 0, 0
    这里的 100, 100是0~65535,怎么转换成象素?