Andy V
Andy V

Reputation: 1

How to prevent opening application from windows context menu

For create Windows context menu we do : Computer\HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\myapp\command Default value would be set to "c:\path\to\myapp.exe" "%1".

If myapp is running I don't want to run one more instance, I just want to pass data to existing one.

How can we prevent to open a new instance and send data to existing one?

Upvotes: 0

Views: 140

Answers (1)

Anders
Anders

Reputation: 101616

You need to communicate with the other instance of your running application. In the old days you would use DDE but that is no longer recommended. The best method is perhaps the COM server approach, you can find an example implementation of that here. This uses IDropTarget and works all the way back to XP. IExecuteCommand can also be used and works on Windows 7 and later.

A simpler method is to use FindWindow and send yourself a WM_COPYDATA message in WinMain but there is a small race condition here that might lead to multiple open applications. You can work around that with a named mutex.

Upvotes: 1

Related Questions