public class WindowX : System.Windows.Window
{
private IntPtr m_handle;
/// <summary>
/// 窗体句柄
/// </summary>
public IntPtr Handle
{
get { return m_handle; }
set { m_handle = value; }
}
public WindowX()
{
this.Loaded += new RoutedEventHandler(WindowX_Loaded);
}
void WindowX_Loaded(object sender, RoutedEventArgs e)
{
m_handle = new WindowInteropHelper(this).Handle;
HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
source.AddHook(Hook);
}
protected virtual IntPtr Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
handled = true;
return IntPtr.Zero;
}
}