Results 1 to 9 of 9

Thread: click image in webbrowser

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    Netherlands
    Posts
    24

    click image in webbrowser

    hey, i have this image in a webbrowser control, and want to click it. the code is : <INPUT class=IMAGE id=_ctl6__ctl0_Rate2 type=image alt="" src="http://.com/Rate2g.gif" border=0 name=_ctl6:_ctl0:Rate2>
    how can i simulate a click?

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Posts
    155

    Re: click image in webbrowser

    Using the API Function called mouse_event you can simulate your click:

    API Function:
    Code:
    Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    The Constants:

    Code:
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Const MOUSEEVENTF_MIDDLEUP = &H40
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10
    Const MOUSEEVENTF_MOVE = &H1
    The LeftClick:
    Code:
    Public Sub LeftClick() 'Programmatically click
        LeftDown
        LeftUp
    End Sub
    
    Public Sub LeftDown() 'MouseDown
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    End Sub
    
    Public Sub LeftUp() 'MouseUp
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Sub
    
    
    'You can also use these for different mouse events:
    
    Public Sub MiddleClick()
        MiddleDown
        MiddleUp
    End Sub
    Public Sub MiddleDown()
        mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
    End Sub
    
    Public Sub MiddleUp()
        mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
    End Sub
    
    Public Sub MoveMouse(xMove As Long, yMove As Long)
        mouse_event MOUSEEVENTF_MOVE, xMove, yMove, 0, 0
    End Sub
    
    Public Sub RightClick()
        RightDown
        RightUp
    End Sub
    
    Public Sub RightDown()
        mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
    End Sub
    
    Public Sub RightUp()
        mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    Netherlands
    Posts
    24

    Re: click image in webbrowser

    sorry, i'd like to minimize the program

  4. #4
    Addicted Member
    Join Date
    Apr 2006
    Posts
    155

    Re: click image in webbrowser

    you would like to minimize with a simulated click right?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    Netherlands
    Posts
    24

    Re: click image in webbrowser

    not really

  6. #6
    Addicted Member
    Join Date
    Apr 2006
    Posts
    155

    Re: click image in webbrowser

    What are you trying to do then?, because you asked "how to simulate a click".

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    Netherlands
    Posts
    24

    Re: click image in webbrowser

    well, I found this code:
    Public Sub SubmitByValue(www As WebBrowser, ByVal strValue As String)
    'strValue is the Text displayed on the Submit Button
    Dim aItem() As String
    Dim iItem As Integer
    Dim iChar As Integer
    Dim dString As String
    Dim i As Integer
    On Error Resume Next
    For i = 0 To www.Document.All.length - 1
    dString = dString & CStr(i) & "-" & _
    Trim(www.Document.All.Item(i).Value) & vbTab
    Next i
    aItem = Split(dString, vbTab)
    For i = 0 To UBound(aItem)
    iChar = InStr(1, aItem(i), strValue)
    If iChar > 0 Then
    iItem = CInt(Mid(aItem(i), 1, iChar - 2))
    www.Document.All(iItem).Click
    Exit For
    End If
    Next i
    End Sub

    it presses a command button in a webbrowser. But now it isn't a command button but an image I want to press

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2004
    Location
    Netherlands
    Posts
    24

    Re: click image in webbrowser

    bump

  9. #9
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: click image in webbrowser

    You can try something like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     WebBrowser1.Navigate2 "http://www.vbforums.com"
    5. End Sub
    6.  
    7. '-------------------------------------------------------------------
    8.  
    9. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
    10.        URL As Variant)
    11.     Dim i As Integer
    12.     'Wait till document has loaded
    13.  
    14.     If pDisp Is WebBrowser1.Application Then
    15.         'Loop through images
    16.  
    17.         For i = 0 To WebBrowser1.Document.Images.length - 1
    18.  
    19.             If WebBrowser1.Document.Images.Item(i).src = _
    20.                "http://www.vbforums.com/images/misc/birthday.gif" Then
    21.                
    22.                 WebBrowser1.Document.Images.Item(i).[b]Click[/b] 'Click on the image
    23.                
    24.             End If
    25.  
    26.         Next i
    27.  
    28.     End If
    29.  
    30. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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