发送短消息在C# [英] Send Message in C#

查看:93
本文介绍了发送短消息在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用被连接到几个不同的DLL的主项目的应用程序。从一个DLL的窗口,我需要能够在另一个但DLL的不能互相引用打开一个窗口。

有人建议我使用SendMessage函数的第一个DLL,有一个监听器,指示该消息到相应的DLL来打开它的窗口主程序。

不过我不熟悉所有的SendMessage函数和我有很多的diffculty拼凑在一起的东西从信息我在线上找到。

如果有人可以请告诉我正确的方法(如果有的话)来使用SendMessage函数,也许听众如何捕获消息,将是惊人的。下面是一些code我已经走到这一步,我不知道如果我在正确的方向也得走的。

 函数[DllImport(user32.dll中)]
    公共静态外部INT FindWindow函数(字符串lpClassName,字符串lpWindowName);
    函数[DllImport(user32.dll中)]
    公共静态外部INT SendMessage函数(IntPtr的的HWND,INT WMSG,IntPtr的的wParam,lParam的IntPtr的);    公共无效的button1_Click(对象发件人,EventArgs的发送)
    {
        INT WindowToFind = FindWindow函数(NULL,Form1的);
    }


解决方案

您不需要发送消息。

添加事件以一形式和事件处理程序等。然后你可以使用第三个项目,该项目引用另外两个事件处理程序附加到事件。该两个DLL不需要互相引用此工作。

I'm creating an application that uses a main project that is connected to several different DLLs. From one DLL window I need to be able to open a window in another but the DLL's can't reference each other.

It was suggested to me to use the sendmessage function in the first DLL and have a listener in the main program that directs that message to the appropriate DLL to open it's window.

However I'm not familiar at all with the sendmessage function and am having a lot of diffculty piecing things together from information I'm finding online.

If someone could please show me the correct way (if there is any) to use the sendmessage function and maybe how a listener captures that message that would be amazing. Here is some of the code I've got so far I'm not sure if I'm heading in the right direction.

    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, String lpWindowName);
    [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

    public void button1_Click(object sender, EventArgs e)
    {
        int WindowToFind = FindWindow(null, "Form1");
    }

解决方案

You don't need to send messages.

Add an event to the one form and an event handler to the other. Then you can use a third project which references the other two to attach the event handler to the event. The two DLLs don't need to reference each other for this to work.

这篇关于发送短消息在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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