|
-
Apr 29th, 2006, 09:12 AM
#1
Thread Starter
Junior Member
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?
-
Apr 29th, 2006, 10:14 AM
#2
Addicted Member
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
-
Apr 29th, 2006, 03:41 PM
#3
Thread Starter
Junior Member
Re: click image in webbrowser
sorry, i'd like to minimize the program
-
Apr 29th, 2006, 04:13 PM
#4
Addicted Member
Re: click image in webbrowser
you would like to minimize with a simulated click right?
-
Apr 29th, 2006, 04:22 PM
#5
Thread Starter
Junior Member
Re: click image in webbrowser
-
Apr 29th, 2006, 04:59 PM
#6
Addicted Member
Re: click image in webbrowser
What are you trying to do then?, because you asked "how to simulate a click".
-
Apr 30th, 2006, 03:21 AM
#7
Thread Starter
Junior Member
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
-
May 5th, 2006, 04:03 AM
#8
Thread Starter
Junior Member
Re: click image in webbrowser
-
May 5th, 2006, 06:33 AM
#9
Re: click image in webbrowser
You can try something like this:
VB Code:
Option Explicit
Private Sub Form_Load()
WebBrowser1.Navigate2 "http://www.vbforums.com"
End Sub
'-------------------------------------------------------------------
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
URL As Variant)
Dim i As Integer
'Wait till document has loaded
If pDisp Is WebBrowser1.Application Then
'Loop through images
For i = 0 To WebBrowser1.Document.Images.length - 1
If WebBrowser1.Document.Images.Item(i).src = _
"http://www.vbforums.com/images/misc/birthday.gif" Then
WebBrowser1.Document.Images.Item(i).[b]Click[/b] 'Click on the image
End If
Next i
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|