WPFでウィンドウメッセージを処理する
滅多にないと思いますが、WPFアプリケーションでウィンドウメッセージを処理したい場合は、HwndSource.AddHook
を使います。
public class MyWindow : Window
{
public MyWindow()
: base()
{
Loaded += (sender, e) =>
{
(PresentationSource.FromVisual(this) as HwndSource).AddHook(new HwndSourceHook(WndProc));
};
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
return IntPtr.Zero;
}
}

スポンサーリンク