(e-mail address removed) (siliconsmiley) wrote in
retVal = Shell("explorer
http://www.alionscience.com",
vbMaximizedFocus)
Pretty straight forward. The problem is that the window opens on the
bottom of my desktop.
This is because you're using Explorer to navigate to the url. Explorer
(win shell) will automatically pass this to the default browser
underneath the covers, so effectively, the vbWinAppStyle value
(vbMaximizedFocus) is lost.
To work around this, try starting IE, or the default browser, directly.
See the StartBrowser proc below
' ***** Code Start *****
Const cMAX_PATH = 260
Const ERROR_NOASSOC = 31
Const ERROR_FILE_NOT_FOUND = 2&
Const ERROR_PATH_NOT_FOUND = 3&
Const ERROR_BAD_FORMAT = 11&
Const ERROR_OUT_OF_MEM = 0
Private Declare Function GetTempPath _
Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function FindExecutable _
Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) _
As Long
Sub StartBrowser(url As String, style As VbAppWinStyle)
Dim iePath As String, tmpPath As String
Dim ff As Long, tmpFilePath As String
Const tmpFile = "test.htm"
tmpPath = TempDir()
tmpFilePath = tmpPath & tmpFile
ff = FreeFile
' create a zero byte file
Open tmpFilePath For Output Shared As #ff
Close #ff
iePath = FindEXE(tmpFile, tmpPath)
If (Len(iePath) > 0) Then
Call Shell(iePath & " " & url, style)
End If
Kill tmpFilePath
End Sub
Function TempDir() As String
Dim lngRet As Long
Dim strTempDir As String
Dim lngBuf As Long
strTempDir = String$(255, 0)
lngBuf = Len(strTempDir)
lngRet = GetTempPath(lngBuf, strTempDir)
If lngRet > lngBuf Then
strTempDir = String$(lngRet, 0)
lngBuf = Len(strTempDir)
lngRet = GetTempPath(lngBuf, strTempDir)
End If
TempDir = Left(strTempDir, lngRet)
End Function
Function FindEXE(stFile As String, _
stDir As String) _
As String
'Usage Example:
' ?fFindEXE("test.xls","c:\temp")
'
Dim lpResult As String
Dim lngRet As Long
lpResult = Space(cMAX_PATH)
lngRet = FindExecutable(stFile, stDir, lpResult)
If lngRet > 32 Then
FindEXE = Left$(lpResult, InStr(1, lpResult, vbNullChar) - 1)
'Else
' Select Case lngRet:
' Case ERROR_NOASSOC: fFindEXE = "Error: No Association"
' Case ERROR_FILE_NOT_FOUND: fFindEXE = "Error: File Not
Found"
' Case ERROR_PATH_NOT_FOUND: fFindEXE = "Error: Path Not
Found"
' Case ERROR_BAD_FORMAT: fFindEXE = "Error: Bad File Format"
' Case ERROR_OUT_OF_MEM: fFindEXE = "Error: Out of Memory"
' End Select
End If
End Function
'***** Code End *****
-- Dev