发送 WM_COPYDATA 但在接收端获取 WM_ACTIVATEAPP

发布于 2024-10-08 07:29:54 字数 465 浏览 3 评论 0原文

我有以下场景:

我的应用程序从命令行获取一些数据。

第一次执行后,我的应用程序始终运行一个实例,并且该实例将保留在内存中,直到用户明确告诉它关闭,而不是在不需要时隐藏表单。

当用户尝试第二次运行该应用程序时,该进程启动,检查内存中是否有另一个进程,如果是的话,它会向内存中的进程发送一条 WM_COPYDATA 消息,其中包含从命令行获取的数据,退出。

当运行应用程序的用户是用户时,这一切都会很好地工作。

我需要从 Microsoft Word 2003 工具栏运行它,因此我使用了“插件”。问题是,当我的应用程序从该加载项(使用 Process 类)启动时,似乎内存中已有的进程收到 WM_ACTIVATEAPP 消息而不是 WM_COPYDATA 消息,因此我无法获取从由加载项启动的进程。

我不知道为什么会发生这种情况以及如何解决它。我用谷歌搜索了几个小时,但没有任何帮助...

有人可以帮忙吗?

I have the following scenario:

My app gets some data from the command line.

After getting executed by the first time, my app runs always one instance and that instance will be in memory until the use explicitly tells it to shutdown instead of just hiding the form when not needed.

When the user tries to run the app a second time, the process starts, checks if there is another one in memory and if that is true, it sends a WM_COPYDATA message to the process in memory with the data it got from the command line and exits.

That all works well when the it«s the user who runs the app.

I needed to ran it from the Microsoft Word 2003 toolbar so i used a "Add-in" for that. The problem is that when my app is started from that Add-In (using Process class), it seems that the process already in memory gets a WM_ACTIVATEAPP message instead of a WM_COPYDATA one, so i can't get the needed data sent from the process started by the Add-In.

I have no idea on why is that happening and how to fix it. I've googled for hours and nothing helped...

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟柳画桥 2024-10-15 07:29:54

获取 WM_ACTIVATEAPP 消息是很正常的,是 Windows 发送的常见通知的一部分。不要假设您收到的第一条消息是 WM_COPYDATA,继续查找。如果你根本没有得到它,那么你用来发送消息的窗口句柄是错误的。这是一个很常见的问题,准确地找到窗口后面并不是那么容易。

.NET 框架已经对单实例应用程序提供了很好的支持,可以从第二个实例检索命令行。考虑使用它来代替。查看此博客文章

Getting a WM_ACTIVATEAPP message is quite normal, part of the usual notifications that Windows sends. Don't assume that the first message you'll get is WM_COPYDATA, keep looking. If you don't get it at all then the window handle that you used to send the message was wrong. Which is a very common problem, it is not that easy to accurately find a window back.

The .NET framework already has very good support for single-instance apps that can retrieve the command line from a second instance. Consider using it instead. Check this blog post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文