我完全信任地使用 XBAP 应用程序。单击按钮时,我需要关闭托管 XBAP 的浏览器。我怎样才能做到这一点?Application.Currenty.ShutDown()
只关闭应用程序,将浏览器留空。
问问题
3387 次
3 回答
5
于 2012-05-23T18:33:34.873 回答
4
编辑: 我的错误,这是一个与您的问题有关的线程 - http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21c88fed-c84c-47c1-9012-7c76972e8c1c
更具体地说(此代码需要完全信任安全设置)
using System.Windows.Interop;
using System.Runtime.InteropServices;
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Auto)]
private static extern IntPtr GetAncestor(IntPtr hwnd, int flags);
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
private void button1_Click(object sender, RoutedEventArgs e)
{
WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow);
IntPtr ieHwnd = GetAncestor(wih.Handle, 2);
PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero);
}
于 2009-08-31T12:55:42.887 回答
1
这太棒了!但它也会关闭所有 IE,包括所有打开的标签
你不会相信这个,但如果你也做了一个 Application.Current.Shutdown(): 在上面它中止整个 IE 关闭并只是关闭应用程序选项卡。
private void exitButton_Click(object sender, RoutedEventArgs e)
{
// This will Shut entire IE down
WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow);
IntPtr ieHwnd = GetAncestor(wih.Handle, 2);
PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero);
// Singularly will just shutdown single tab and leave white screen, however with above aborts the total IE shutdown
// and just shuts the current tab
Application.Current.Shutdown();
}
于 2010-06-27T07:42:50.187 回答