CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Location
    India
    Posts
    6

    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.

  2. #2
    Join Date
    Feb 2004
    Location
    Romania
    Posts
    57

    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.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    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);
    }

  4. #4
    Join Date
    Aug 1999
    Posts
    98
    OR use EnumWindows() to navigate through all system windows until you find the one you want!

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at the following FAQ...

  6. #6
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201
    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
  •  





Click Here to Expand Forum to Full Width

Featured