|
-
Nov 2nd, 1999, 08:47 PM
#1
Thread Starter
Member
Hi,
How do I focus the webbrowser object so I can send keystrokes to it?
I'm trying to write this app that enters login info for me on a form..
I tried to focus the VB form, then use Sendkeys "{Tab}..." to get the the form elements.. but somehow, it just doesn't work~
I've even tried to create a form with no other controls.. but still I can get the webbrowser object to receive focus.
Neither did webbrowser.setfocus works..
So, how do I get the object to fill up a particular field or press {enter} at a particular button? I'm prepared to count the number of tabs to get to the particular HTML object displayed if it actually works..
What did I do wrong?
-
Nov 2nd, 1999, 09:34 PM
#2
Addicted Member
Maybe this code help you. It's sample for printing with webbrowser control.
Code:
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Declare Function GetFocus Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
'GetWindow constants
Public Const GW_CHILD = 5
'GetWindowLong constants
Public Const GWL_STYLE = (-16)
Public Const WS_VSCROLL = &H200000
Sub SetFocusToBrowser(hBrowserHwnd As Long)
Dim lStyle As Long
Dim lResult As Long
Dim hwnd As Long
hwnd = hBrowserHwnd
While (lResult = 0) And (hwnd <> 0)
hwnd = GetWindow(hwnd, GW_CHILD)
lStyle = GetWindowLong(hwnd, GWL_STYLE)
lResult = lStyle And WS_VSCROLL
Wend
SetFocusAPI (hwnd)
End Sub
Private Sub Command1_Click()
Dim hwnd As Long
WebBrowser1.SetFocus
hwnd = GetFocus
SetFocusToBrowser (hwnd)
SendKeys "^P" 'Control-P to print
End Sub
Best regards.
------------------
smalig
[email protected]
smalig.tripod.com
-
Nov 2nd, 1999, 09:49 PM
#3
Frenzied Member
to send keys tab to the elements within html in a webbrowser control do this:
Option Explicit
Dim arrTabStop() As Boolean
Private Sub WebBrowser1_GotFocus()
Dim i As Integer
'Store the TabStop property for each control on the
'form and then set the TabStop property of each
'control to False
ReDim arrTabStop(0 To Controls.Count - 1) As Boolean
For i = 0 To Controls.Count - 1
arrTabStop(i) = Controls(i).TabStop
Controls(i).TabStop = False
Next
End Sub
Private Sub WebBrowser1_LostFocus()
Dim i As Integer
'Restore the Tabstop property for each control on the form
For i = 0 To Controls.Count - 1
Controls(i).TabStop = arrTabStop(i)
Next
End Sub
Private Sub Command1_Click()
'this will tab through the elements within 'the html
WebBrowser1.SetFocus
SendKeys "{Tab}"
End Sub
is this what you wanted to do?
-
Nov 2nd, 1999, 11:25 PM
#4
To print contents of a WebBrowser you don't have to use that long routine, you can achieve it with 1 line of code:
Without showing the Print Dialog Box
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
With the Print Dialog Box
WebBrowser1.ExecWB OLECMDID_PRINT,OLECMDEXECOPT_PROMPTUSER
Regards,
------------------
Serge
Software Developer
[email protected]
[email protected]
-
Nov 2nd, 1999, 11:27 PM
#5
Frenzied Member
ExecWB only work with IE4 onwards though!
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
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
|