Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 5-Sep-16 23:34pm
v2

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
SuperMiQi 5-Sep-16 16:47pm    
Hello Sir,
Thank you for your reply.
I have already a mechanism in place to invoke an action. The only unknown is which sendmessage event to invoke to close the menu open.
Do you have an idea?
Thank you very much in advance.
Best regards.
MiQi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900