如何以编程方式关闭另一个应用程序的主菜单。 [英] How to programmatically close the main menu of another application.

查看:96
本文介绍了如何以编程方式关闭另一个应用程序的主菜单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我想看看是否有办法通过我的应用程序中打开的主菜单关闭另一个应用程序。



从另一个应用程序关闭菜单有什么神奇的事件?

非常感谢您提前。

Best问候。

MiQi。



我的尝试:



我试图在大型机上应用SetFocus或WM_EXITMENULOOP消息但当前没有运气。

我甚至已经应用了一个刷新窗口,但主菜单处于打开状态。

Hello Everyone.

I would like to see if there would be a way to close via another application the main menu open in my application.

What could be the magic event to close the menu from another application?
Thank you very much in advance.
Best regards.
MiQi.

What I have tried:

I have tried to apply a SetFocus on the mainframe or a WM_EXITMENULOOP message but no luck currently.
I even have applied a refreshwindow but the main menu resides open.

推荐答案

您将问题标记为C ++和C#。所以我只给出一般答案。



虽然有很多IPC(进程间通信)方法,但在这里使用Windows消息似乎是合适的。



要使用此功能,发件人必须知道要将哪个消息发送到哪个窗口句柄。常用方法是定义消息并在接收应用程序的主窗口中实现处理。该处理程序然后可以启动进一步的操作,如关闭菜单。



要发送消息,您可以使用发送消息功能(Windows) [ ^ ]或PostMessage功能(Windows) [ ^ ]。但是您必须知道处理消息的接收应用程序的窗口句柄。你可以使用 FindWindow函数(Windows)来实现这一点/ a> [ ^ ]具有注册的窗口类名称和/或标题。或者使用 BroadcastSystemMessage功能(Windows) [ ^ ]将消息发送到所有应用程序(收件人 BSM_APPLICATIONS 并标记 BSF_IGNORECURRENTTASK )。然后你不需要一个窗口句柄,但应该确保消息是唯一的(见下文)。



对于消息你可以使用 WMP_APP 基于标识符(不推荐 WM_USER )。更好的解决方案是使用注册消息来确保唯一标识符(请参阅 RegisterWindowMessage函数(Windows) [ ^ ])。另请参阅关于消息和消息队列(Windows) [ ^ ]。



所有上述功能也可以通过P / Invoke与C#一起使用。
You tagged your question as C++ and C#. So I will give only a general answer.

While there are many methods for IPC (Inter Process Communication) it looks like using Windows messages is appropriate here.

To use this the sender must know which message to be send to which window handle. The common method is to define a message and implement the handling in the main window of the receiving application. That handler can then initiate further actions like closing the menu.

To send a message you can use the SendMessage function (Windows)[^] or the PostMessage function (Windows)[^]. But you must know the window handle of the receiving application that handles the message. You can get that by using the FindWindow function (Windows)[^] with a registered window class name and/or title. Alternatively use the BroadcastSystemMessage function (Windows)[^] to send the message to all applications (recipient BSM_APPLICATIONS and flag BSF_IGNORECURRENTTASK). Then you don't need a window handle but should ensure that the message is unique (see below).

For the message you can use a WMP_APP based identifier (WM_USER is not recommended). A better solution would be using a registered message that ensures a unique identifier (see RegisterWindowMessage function (Windows)[^]). See also About Messages and Message Queues (Windows)[^].

All the above functions can be also used with C# by using P/Invoke.


现在我不知道你的问题的解决方案。但是......你可以做的一件事(不是那么专业)是创建一个外部文件(例如在AppData中),并且菜单需要关闭的应用程序将检查那里的条件。如果它符合要求,它将关闭菜单。如果不是......它将保持开放状态。从其他应用程序..你将实际控制文件的条件。
Now i am not aware of a solution for your question. But..one (not so pro) thing you could do... is to create an external file(for example in AppData), and the application whose menu needs to be close.. will check for a condition there. If it meets the "requirements", it will close the menu. If not... it will keep it open. And from the other application.. you will actually control the "condition" of the file.


这篇关于如何以编程方式关闭另一个应用程序的主菜单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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