|
-
Jun 28th, 2001, 05:06 PM
#1
Thread Starter
New Member
Help with WaitForSingleObject and internetexplorer
I'm having a problem using the internetexplorer webbrowser control with the WaitForSingleObject function. What I need to do, is to have my application open up a new Internet Explorer window in a new process using the internetexplorer control. Then after I get a process handle for the new IE window that I opened up, I need to pass this handle to the WaitForSingleObject function and wait until IE is closed by the user.
Currently the method I use to do this works fine if there are no other IE instances currently running, but if there are other IE instances running while my app creates a new internetexplorer object, then my new IE instance will use the same process as the other IE instance that was already running.
So basically my question is, how do I force the internetexplorer control to create a new process when the object is created? If that is impossible, then does anyone have any other suggestions for waiting for the new IE window to close?
Here is the code I am currently using for this:
Dim ieMain As InternetExplorer
Dim lPid As Long, hProcess As Long, lRet As Long, bRet As Boolean
Set ieMain = CreateObject("InternetExplorer.Application")
ieMain.Navigate "http://www.blahblahblah.com"
ieMain.Visible = True
'Sets lPid to the process id by passing in a window handle
Call GetWindowThreadProcessId(ieMain.hwnd, lPid)
'Returns a handle to the process id
hProcess = OpenProcess(SYNCHRONIZE, False, lPid)
lRet = WaitForSingleObject(hProcess, INFINITE)
bRet = CloseHandle(hProcess)
-
Jun 29th, 2001, 06:32 PM
#2
Here's create process & waitforsingleobject:
Code:
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258
ReturnValue = CloseHandle(proc.hProcess)
End Sub
-
Jul 2nd, 2001, 08:02 AM
#3
Thread Starter
New Member
Thanks for the reply Jim. I've used that method as well, but unfortunately using that method I won't get the benefit of controlling IE using the webbrowser control. I figured that I could probably just use the SendMessage API to send URLs to IE and then use your method as well, but I'm just worried that the implementation might be different across different versions of IE using SendMessage.
Has anyone used SendMessage to control IE before, and if so, does it seem to work pretty consistently across different versions of IE?
Thanks,
Super
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
|