从另一个WPF应用程序向WPF应用程序发送窗口消息 [英] Send window message to WPF application from another WPF application

查看:675
本文介绍了从另一个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

这篇关于从另一个WPF应用程序向WPF应用程序发送窗口消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆