I am trying to write some code that will launch a URL and pause the execution in VB until the browser is closed.
I have code that will launch a program and pause that:
This will happily sit and wait for the application and then continue with the code directly after the line that it is called from
I have code to launch a URL:
This will open the browser but then I need to put the pause in.
I thought if I could identify the browser process it opens I could modify my first lot of code to essentially use the process number but I am not sure how to do this. Could I use a createobject command to make this easier?
My second idea is to embed an IE control into the form and reference that. I think that it should be easy enough to check when it has an activate URL and when its been completed.
Any ideas would be appreciated.
Mark
Mark Davies
Warwickshire County Council
I have code that will launch a program and pause that:
Code:
'---------- Functions for pausing shell execution ----------
Private Declare Function OpenProcess Lib "Kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32" _
(ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STATUS_PENDING = &H103&
'---------- Functions for pausing shell execution ----------
Function RunShell(cmdline As String)
Dim hProcess As Long
Dim ProcessId As Long
Dim exitCode As Long
' uses the original shell to run command
ProcessId = Shell(cmdline, vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, exitCode)
DoEvents
Loop While exitCode = STATUS_PENDING
Call CloseHandle(hProcess)
End Function
This will happily sit and wait for the application and then continue with the code directly after the line that it is called from
I have code to launch a URL:
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Function OpenBrowser(ByVal URL As String) As Boolean
Dim res As Long
' it is mandatory that the URL is prefixed with http:// or https://
If InStr(1, URL, "http", vbTextCompare) <> 1 Then
URL = "[URL unfurl="true"]http://"[/URL] & URL
End If
res = ShellExecute(0&, "open", URL, vbNullString, vbNullString, vbNormalFocus)
OpenBrowser = (res > 32)
End Function
Private Sub cmdTestUrl_Click()
Call OpenBrowser(txtURL.Text)
' >>>> PAUSE HERE <<<<
MsgBox "You're back in play"
End Sub
This will open the browser but then I need to put the pause in.
I thought if I could identify the browser process it opens I could modify my first lot of code to essentially use the process number but I am not sure how to do this. Could I use a createobject command to make this easier?
My second idea is to embed an IE control into the form and reference that. I think that it should be easy enough to check when it has an activate URL and when its been completed.
Any ideas would be appreciated.
Mark
Mark Davies
Warwickshire County Council