English 中文(简体)
我怎么能够关闭一个XBAP的浏览器?
原标题:How can I close the browser from an XBAP?
  • 时间:2009-08-31 12:50:26
  •  标签:

我完全信任使用XBAP的申请。 在我点击一个 but子时,我需要关闭主办XBAP的浏览器。 我如何能够做到这一点? Application.Currenty.ShutDown() only ends the application,使浏览器空白。

最佳回答

EDIT: My mistake, here is a thread with your problem - http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21c88fed-c84c-47c1-9012-7c76972e8c1c

更具体地说(该法典需要full Trust安保环境)

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);      
}
问题回答

我知道这是一个真正的老问题,但是如果任何人都存在这个问题,那就是一个更简单的解决办法,将只是一个表格。

Environment.Exit(0);

资料来源:http://social.msdn.microsoft.com/forums/en-US/wpf/thread/686048c2-fb99-45f6-800f-b2d390f4ed37。 论坛

然而,它也关闭了所有独立实体,包括任何公开的表格。

你不会相信这一点,但如果你也提出申请的话。 现今:除此以外,国际电子计算中心关闭了全部,只是关闭了表格。

 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();
        }




相关问题
热门标签