获取wpf窗口对应的句柄窗口
using System;using System.Windows;using System.Windows.Interop;using IWin32Window = System.Windows.Forms.IWin32Window;public class WindowWrapper : IWin32Window { ////// 窗口句柄 /// public IntPtr Handle { get; private set; } ////// 将句柄封闭为实现IWin32Window的对象 /// /// public WindowWrapper(IntPtr handle) { Handle = handle; } ///封装为实现IWin32Window的对象 /// /// WPF窗口 public WindowWrapper(Window window) { var helper = new WindowInteropHelper(window); System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); Handle = process.MainWindowHandle; Handle = helper.Handle; } ///得到某个WPF窗口的窗口句柄 /// WPF窗口 ///窗口句柄 public IntPtr GetHandle(Window window) { return new WindowInteropHelper(window).Handle; } }
打开窗口
frmselectwx myfrmwx = new frmselectwx();myfrmwx.Show(new Utils.WindowWrapper(this));