-
March 1st, 2004, 04:19 AM
#1
How to close a Internet explorer from an external app
A Internet explorer window is open
I want to know 2 things...
1) How to close it from an external app ??
2) If that HTML page cotains a control(say Edit Box)..how to retrive it's handle ??
Give detailed source code as I'm new to COM.
I have a small idea that I should use IWebBrowser2 interface. I want to know how I would get the pointer to opened window.
-
March 1st, 2004, 04:49 AM
#2
Re: How to close a Internet explorer from an external app
Originally posted by Ram_Gupta
I want to know how I would get the pointer to opened window.
CWnd* pwndIECodeGuru = CWnd::FindWindow( "CodeGuru - Internet Explorer", NULL );
This will give you a pointer to the window that has as title "CodeGuru - Internet Explorer".
Good Luck.
-
March 1st, 2004, 04:53 AM
#3
A Internet explorer window is open
I want to know 2 things...
1) How to close it from an external app ??
...
a) use Spy to know Internet explorer Wnd class and title;
b) use FindWindow to get Internet explorer HWND:
Code:
HWND hWnd = FindWindow(..., ...);
see MSDN for FindWindow parameters;
c) post WM_CLOSE to Internet explorer :
Code:
if(::IsWindow(nWnd))
{
::PostMessage(hWnd, WM_CLOSE);
}
-
March 1st, 2004, 04:56 AM
#4
OR use EnumWindows() to navigate through all system windows until you find the one you want!
-
March 1st, 2004, 05:01 AM
#5
Take a look at the following FAQ...
-
March 1st, 2004, 05:39 AM
#6
If you want to obtain pointer to IWebBrowser2 I can suggest 2 ways:
1) Writing Browser Helper Object (BHO). See in MSDN how to do that. In this case you need to write an ActiveX, which will be called every time when some IE window is opened and IUnknown interface pointer will be passed to your ActiveX through which you can query for IWebBrowser2.
2) Locate "Internet Explorer_Server" window of the instance of IE you want to process. Then send WM_HTML_GETOBJECT message to mentioned window and then call ObjectFromLresult function to obtain the IHtmlDocument2 interface.
See following article in MSDN:
HOWTO: Get IHTMLDocument2 from a HWND
After this using IServicePovider you can obtain IWebBrowser2 interface pointer.
In second method obtaining IHtmlDocument2 you can use its methods to access any control (including EditBox) contained in document.
Or if you have IWebBrowser2 you can call its get_Document method to obtain IHtmlDocument2 pointer.
IWebBrowser2 has Quit method, which is closes, the WebBrowser object, but according MSDN:
The WebBrowser object ignores this method.
So to close WebBrowser window you can simply obtain HWND of IE, using get_HWND method of IWebBrowser2, then send WM_CLOSE message to that window as suggested in previous posts in this thread.
Last edited by Armen; March 1st, 2004 at 05:44 AM.
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
|