WPF重写窗口过程函数
来源:互联网 发布:美国留学费用知乎 编辑:程序博客网 时间:2024/05/16 15:14
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; }