我完全信任使用XBAP应用程序。单击按钮时,我需要关闭托管XBAP的浏览器。我怎样才能做到这一点? Application.Currenty.ShutDown()
仅关闭应用程序,使浏览器留空。
最佳答案
编辑:
我的错误,这是您遇到的问题-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);
}
关于c# - 如何从XBAP关闭浏览器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1357308/