从另一个WPF应用程序向WPF应用程序发送窗口消息

问题描述:

我在服务器端使用了此代码

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?

我发现了错误

我发送的消息ID必须为0x0112而不是1 这是用于Windows命令

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