2011-04-29 54 views
1

我想使用mshtml关闭新打开的Internet Explorer。如何使用mshtml关闭新打开的Internet Explorer

我有一个程序,它从不同的IE窗口获取值。使用元素的Click()方法调用到每个窗口的导航。一旦处理完页面,我想关闭窗口。

任何人都知道如何使用Mshtml关闭窗口。

在此先感谢 乌尼

回答

0

简单:获得HWNDIWebBrowser2,并发送一个WM_CLOSE

1

请参阅以下代码...

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. 
} 
相关问题