3

I'm using SHDocVw.InternetExplorer to launch IE in my code. In certain cases InternetExplorer.Quit() doesn't work. I have tried several things to make Quit work but without success. I'm now resorting to Process.Kill.

Now if a manually launched instance of IE8 is already running when SHDocVw.InternetExplorer is used to launch another one the new one gets created as a child process of the existing IE:

SHDocVw.InternetExplorer spawned IE is a child of the existing IE

The SHDocVw.InternetExplorer IE is process id 996 on the screenshot, the manually launched one is 3388 plus its child 2876.

Now if I use InternetExplorer.HWND to retrieve the window handle of my IE and then GetWindowThreadProcessId to get the process ID I end up with 3388, the parent IE process ID when what I want is 996, the InternetExplorer.HWND launched IE process ID.

I'm not sure on which step it gets wrong.
Should I be retrieving the HWND in a different way or the process ID? Or both?

Thanks!

Edit: I've just tried sending WM_CLOSE to the HWND and it closed the parent IE. I suppose it means I'm getting a wrong HWND?

Edit: It may be worth noting that only the manually launched IE is visible when I do the closing. Would this mean I'm getting the HWND of the only visible IE therefore?

Community
  • 1
  • 1
axk
  • 5,316
  • 12
  • 58
  • 96
  • You are probably getting confuzzled by the instance IE starts up to display content in a tab. If the web page causes a crash then it won't take IE down with it. – Hans Passant Aug 22 '11 at 18:10
  • @Hans, Good point! I understand IE8 uses separate process for each tab. The thing is the instance I launch with SHDocVw.InternetExplorer gets its parent window set to a Control in my app, so it ends up embedded as a child in that Control. It would probably just add a tab to the running IE if you don't change the parent window, I should try. This may mean I need a way to launch IE as a separate process instead. I doubt it is possible with SHDocVw.InternetExplorer though. – axk Aug 22 '11 at 19:33
  • 1
    It's possible, google ObjectFromLResult. – Hans Passant Aug 22 '11 at 19:43

0 Answers0