examples 1 and 2 have not worked for me:
example 3 works but unacceptable flash off/on
1)
webbrowser1.setfocus by itself
2)
Public Declare Function GetFocus Lib "USER32" () As Long
Public Declare Function SetFocus Lib "USER32" (ByVal hWnd As Long) As Long
dim hwndwb as long
webbrowser1.setfocus
hwndwb = GetFocus
call setfocus (hwndwb)
3)
webbrowser1.Visible = False: webbrowser1.Visible = True
Wayne
Check this out:
http://support.microsoft.com/support/kb/articles/q176/4/00.asp
There is a routine "SetFocusToBrowser"
If that doesn't work, what about locking the parent window from refresh then
setting then toggle the visible property?
Rick
"Wayne Hall" <way...@rcn.com> wrote in message
news:uJJ2dGqZ$GA.1744@cppssbbsa06...
00.asp from MSkb is the code that I have not been successful with.
It would not set focus or for that matter, print the web page.
Toggling visible works but causes automation error
if documentcomplete event fires when web browser momentarily not visible
Wayne
----cut---
I played around with it and found a solution. I was able to find the
correct handle for the window but still had problems using send keys. I did
however work out an API solution to scroll the browser.
Good Luck,
Rick Cardarelle
Here is an Example:
Private Sub Command1_Click()
' Must pass in a parent handle such as the form
ScrollBrowser Me.hWnd, SCROLL_DOWN
End Sub
Module Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal
wCmd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const GW_CHILD As Long = 5
Private Const GW_HWNDNEXT As Long = 2
Private Const WM_VSCROLL As Long = &H115
Private Const WM_HSCROLL As Long = &H114
Private Const SB_LINEDOWN As Long = 1
Private Const SB_LINELEFT As Long = 0
Private Const SB_LINERIGHT As Long = 1
Private Const SB_LINEUP As Long = 0
Enum SB_DIRECTION
SCROLL_UP = 1
SCROLL_DOWN = 2
SCROLL_LEFT = 3
SCROLL_RIGHT = 4
End Enum
Public Sub ScrollBrowser(ByVal hwndParent As Long, ByVal Direction As
SB_DIRECTION)
Dim hwndBrowser As Long
hwndBrowser = FindWebDoc(hwndParent)
If hwndBrowser > 0 Then
Select Case Direction
Case SCROLL_UP
Call SendMessage(hwndBrowser, _
WM_VSCROLL, _
SB_LINEUP, ByVal 0&)
Case SCROLL_DOWN
Call SendMessage(hwndBrowser, _
WM_VSCROLL, _
SB_LINEDOWN, ByVal 0&)
Case SCROLL_LEFT
Call SendMessage(hwndBrowser, _
WM_HSCROLL, _
SB_LINELEFT, ByVal 0&)
Case SCROLL_RIGHT
Call SendMessage(hwndBrowser, _
WM_HSCROLL, _
SB_LINERIGHT, ByVal 0&)
End Select
End If
End Sub
Private Function FindWebDoc(ByVal hWndStart As Long) As Long
Dim strClassName As String
Dim RetVal As Long
Dim hWnd As Long
Const MAX_CHARS As Long = 255
hWnd = GetWindow(hWndStart, GW_CHILD)
Do Until hWnd = 0
RetVal = FindWebDoc(hWnd)
If RetVal = 0 Then
strClassName = String$(MAX_CHARS, 32)
RetVal = GetClassName(hWnd, strClassName, MAX_CHARS)
strClassName = Left(strClassName, RetVal)
'If (strClassName = "Shell Embedding") Then
'If (strClassName = "Shell DocObject View") Then
If (strClassName = "Internet Explorer_Server") Then
FindWebDoc = hWnd
Exit Do
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Else
FindWebDoc = RetVal
Exit Do
End If
Loop
End Function
Now if only I could print the web page to print by itself without the side
and top frames also printing
This prints all frames
webbrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0
sendkeys of Control P does not work even when focused to proper web page
handle
Wayne
Rick Cardarelle <eclip...@geocities.com> wrote in message
news:wsvj4.320$6X5....@news.uswest.net...