[英]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".对于创建 Windows 上下文菜单,我们执行以下操作: Computer\\HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\myapp\\command 默认值将设置为“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.如果 myapp 正在运行,我不想再运行一个实例,我只想将数据传递给现有实例。
How can we prevent to open a new instance and send data to existing one?我们如何防止打开一个新实例并将数据发送到现有实例?
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.在过去,您会使用 DDE,但不再推荐使用。 The best method is perhaps the COM server approach, you can find an example implementation of thathere .最好的方法可能是 COM 服务器方法,您可以在此处找到该方法的示例实现。 This uses IDropTarget
and works all the way back to XP.这使用IDropTarget
并一直工作到 XP。 IExecuteCommand
can also be used and works on Windows 7 and later. IExecuteCommand
也可以在 Windows 7 及更高版本上使用和工作。
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.一种更简单的方法是使用FindWindow
并在WinMain
向自己发送WM_COPYDATA
消息,但这里有一个小的竞争条件,可能会导致多个打开的应用程序。 You can work around that with a named mutex.您可以使用命名的互斥锁来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.