简体   繁体   English

发送WM_COPYDATA但在接收端获取WM_ACTIVATEAPP

[英]Sending WM_COPYDATA but getting WM_ACTIVATEAPP on the receiving side

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. 当用户尝试第二次运行该应用程序时,该过程将启动,检查内存中是否还有另一个应用程序,如果是,则将WM_COPYDATA消息与从命令行获取的数据一起发送给内存中的进程。退出。

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. 我需要从Microsoft Word 2003工具栏运行它,因此我为此使用了“加载项”。 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. 问题是,当我的应用程序从该加载项(使用Process类)启动时,似乎内存中已存在的进程收到WM_ACTIVATEAPP消息而不是WM_COPYDATA消息,因此我无法从加载项启动的进程。

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? 有人可以帮忙吗?

Getting a WM_ACTIVATEAPP message is quite normal, part of the usual notifications that Windows sends. 获取WM_ACTIVATEAPP消息很正常,这是Windows发送的常规通知的一部分。 Don't assume that the first message you'll get is WM_COPYDATA, keep looking. 不要以为您会收到的第一条消息是WM_COPYDATA,请继续查看。 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. .NET框架已经对可以从第二个实例检索命令行的单实例应用程序提供了很好的支持。 Consider using it instead. 考虑改用它。 Check this blog post . 检查此博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM