Results 1 to 12 of 12

Thread: Simulate click on webbrowser

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    297

    Simulate click on webbrowser

    Sup all?

    OK, I made a program that simulates a mouse click on a specific X , Y coordinates on the webbrowser. The thing is that, is not working here is my code

    VB.NET Code:
    1. Class Control
    2.         Public Sub New(ByVal Handle As IntPtr)
    3.             hWnd = Handle
    4.         End Sub
    5.  
    6.         Private hWnd As IntPtr = IntPtr.Zero
    7.         Public Property ControlHandle() As IntPtr
    8.             Get
    9.                 Return hWnd
    10.             End Get
    11.             Set(ByVal value As IntPtr)
    12.                 hWnd = value
    13.             End Set
    14.         End Property
    15.  
    16. Const WM_LBUTTONDOWN As Int32 = &H201
    17. Const WM_LBUTTONUP As Int32 = &H202
    18.  
    19. <DllImport("user32.dll", SetLastError:=True)> _
    20.         Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    21.         End Function    
    22.    
    23.        Public Sub ClickControl(ByVal x As Integer, ByVal y As Integer)
    24.             Dim coords As Integer = (y << 16) + x
    25.             Dim lParam As New IntPtr(coords)
    26.             PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, lParam)
    27.             PostMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, lParam)
    28.         End Sub
    29.  
    30.         Public Sub ClickControl(ByVal p As Point)
    31.             ClickControl(p.X, p.Y)
    32.         End Sub
    33.   End Class
    34. End Namespace

    I call is like this

    VB.NET Code:
    1. handle = Control.FindControl(WebBrowser1.Handle, Nothing) '"Internet Explorer_Server")
    2.         MyControl = New Control(handle)
    3.         Dim test As Point
    4.         test.X = 200
    5.         test.Y = 58
    6.         MyControl.ClickControl(test)

    But the thing is that, is does not work! What did I do wrong here?

    I also tried changing
    Const WM_LBUTTONDOWN As Int32 = &H201
    to
    Const WM_LBUTTONDOWN As Int32 = &H2

    and my webbrowser goes blank.
    Last edited by simon66; Feb 20th, 2011 at 12:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width