开发者

How can I close the newly opened Internet Explorer using the mshtml

开发者 https://www.devze.com 2023-03-01 06:36 出处:网络
I want to close a newly opened Internet Explorer using the mshtml. I have a program , which takes values from different IE Window. The navigati开发者_高级运维on to each Window is invoked using the Cl

I want to close a newly opened Internet Explorer using the mshtml.

I have a program , which takes values from different IE Window. The navigati开发者_高级运维on to each Window is invoked using the Click() method of element. Once process the page, I want to close the Window.

Any one know how to close the window using the Mshtml.

thanks in advance Unni


See the following code...

using System.Runtime.InteropServices;
// IE can be found in COM library called 
// Microsoft Internet Controls: 
using IE = SHDocVw.InternetExplorer; 
static void OpenAndCloseIE()
{
    // Get an instance of Internet Explorer: 
    Type objClassType = Type.GetTypeFromProgID("InternetExplorer.Application");
    var instance = Activator.CreateInstance(objClassType) as IE;

    // Close Internet Explorer again: 
    instance.Quit();

    // Release instance: 
    System.Runtime.InteropServices.Marshal.ReleaseComObject(instance);
    instance = null; // Don't forget to unreference it. 
}


Easy: Get the HWND from IWebBrowser2, and send it a WM_CLOSE.

0

精彩评论

暂无评论...
验证码 换一张
取 消