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 from the client side like this

SendMessage(m_Process.MainWindowHandle, 1, (IntPtr)(-1), (IntPtr)(-1));

The problem is that the server side cannot receive this message, why?


回答1:


I found the mistake

the message id I sent must be 0x0112 not 1 this is for windows command



来源:https://stackoverflow.com/questions/41142734/send-window-message-to-wpf-application-from-another-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!