hwndsource

PresentationSource.FromVisual(this) returns null value in WPF

泪湿孤枕 提交于 2019-12-22 04:49:17
问题 I'm using the following code for my: protected override void OnSourceInitialized(EventArgs e) { ... .... HwndSource source = PresentationSource.FromVisual(this) as HwndSource; ... ... } In some systems the "source" value comes out to be null and i cant find the reason why... 回答1: I think you may have to wait until the UI is rendered until you try to assign the Hwnd. Try putting it in the event handler for Window.Loaded instead. This happened to me before, I had the Hwnd assignment after

Send window message to WPF application from another WPF application

淺唱寂寞╮ 提交于 2019-12-12 01:53:48
问题 I used this code in the server side void Window_Loaded(object sender, RoutedEventArgs e) { HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); source.AddHook(new HwndSourceHook(WndProc)); } private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // Handle messages... var htLocation = DefWindowProc(hwnd, msg, wParam, lParam).ToInt32(); if (msg == 1) { MessageBox.Show("" + msg); } return new IntPtr(1); } And I send the message