protected override void OnSourceInitialized(EventArgs e)
{
win_SourceInitialized(this, e);
base.OnSourceInitialized(e);
}
void win_SourceInitialized(object sender, EventArgs e)
{
//方法1
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
if (source != null) source.AddHook(WndProc);
//方法2
//HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
//if (source != null) source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages...
if (msg == 0x219)//WM_DEVICECHANGE
{
GetCameraLoactionInfo();
InitCameraInfo();
}
return IntPtr.Zero;
}
WPF重写窗口过程函数
最新推荐文章于 2021-10-30 23:19:57 发布