Wpf窗口中打开WinForm窗口
获取wpf窗口对应的句柄窗口
using System; using System.Windows; using System.Windows.Interop; using IWin32Window = System.Windows.Forms.IWin32Window; public class WindowWrapper : IWin32Window { /// <summary> /// 窗口句柄 /// </summary> public IntPtr Handle { get; private set; } /// <summary> /// 将句柄封闭为实现IWin32Window的对象 /// </summary> /// <param name="handle"></param> public WindowWrapper(IntPtr handle) { Handle = handle; } /// <summary> 封装为实现IWin32Window的对象 /// </summary> /// <param name="window">WPF窗口</param> public WindowWrapper(Window window) { var helper = new WindowInteropHelper(window); System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); Handle = process.MainWindowHandle; Handle = helper.Handle; } /// <summary> 得到某个WPF窗口的窗口句柄 </summary> /// <param name="window">WPF窗口</param> /// <returns>窗口句柄</returns> public IntPtr GetHandle(Window window) { return new WindowInteropHelper(window).Handle; } }
打开窗口
frmselectwx myfrmwx = new frmselectwx(); myfrmwx.Show(new Utils.WindowWrapper(this));
posted on 2019-01-16 16:07 gds通用软件开发系统 阅读(815) 评论(0) 编辑 收藏 举报