VB.NET Sendmessage / postmessage问题

时间:2015-10-12 00:41:02

标签: vb.net internet-explorer sendmessage postmessage

我有一张表格,在表格中我有一个小组。

点击按钮1,我启动IE的新进程,并将IE.mainhandle设置为我的panel.handle,所以我的面板中有IE。

现在我想在IE上发送鼠标点击。我该怎么办?

我刚试过Sendmessage和Postmessage,但它确实没有用!

 Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As IntPtr, ByVal wMsg As UInteger, ByVal wParam As UInteger, ByVal lParam As UInteger) As UInteger

 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As IntPtr, ByVal wMsg As UInteger, ByVal wParam As UInteger, ByVal lParam As UInteger) As UInteger

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Dim pnt = New Point(430, 290)
        Dim x As Integer = 430
        Dim y As Integer = 290

        Dim p As Process = Process.GetProcessById(processID)
        SetActiveWindow(p.MainWindowHandle)

        PostMessage(p.MainWindowHandle, WM_LBUTTONDOWN, 1, MakeLParam(x, y))
        PostMessage(p.MainWindowHandle, WM_LBUTTONUP, 0, MakeLParam(x, y))

        SendMessage(p.MainWindowHandle, WM_LBUTTONDOWN, 0, MakeLong(x, y))
        SendMessage(p.MainWindowHandle, WM_LBUTTONUP, 0, MakeLong(x, y))

    End Sub

Private Shared Function MakeLParam(ByVal LoWord As Integer, ByVal HiWord As Integer) As IntPtr
        Return New IntPtr((HiWord And &H10000) Or (LoWord And &HFFFF))
    End Function

 Public Function MakeLong(ByVal loWord As Integer, ByVal hiWord As Integer) As Integer

        Return (hiWord - 1 << 16) Or (loWord + &HFFFF)

    End Function

有人能帮助我吗?

0 个答案:

没有答案