简体   繁体   English

如何防止从 Windows 上下文菜单打开应用程序

[英]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.

相关问题 从 Windows 上下文菜单运行 Java 应用程序 - Running a Java Application from the Windows Context Menu 如何在Windows XP的上下文菜单中更改“编辑”和“打印”操作的默认应用程序? - How change the default application for “Edit” and “Print” actions from context menu in Windows XP? 如何为Java应用程序向Windows资源管理器添加上下文菜单? - How can I add a context menu to the Windows Explorer for a Java application? 如何使用 Python 在 Windows 应用程序中获得右键单击上下文菜单? - How to get right click context menu in Windows application using Python? 涵盖Windows资源管理器上下文菜单应用程序! - Getting Coverage for Windows Explorer Context Menu Application! 如何避免上下文菜单处理程序应用程序阻止浏览器? - How to avoid context menu handler application from blocking the explorer? 从Windows上下文菜单接收参数 - Receiving arguments from Windows Context menu 如何为 Java 应用程序自定义 Windows 任务栏的沉浸式上下文菜单(跳转列表) - How to customise Windows Taskbar's Immersive Context Menu (Jump List) for Java application 如何让 Windows 11 上下文菜单项与我的 PyQt6 应用程序一起使用 - How can I get a Windows 11 Context Menu item to work with my PyQt6 application 如何在 windows 上的上下文菜单中为新应用程序添加新命令 11 文件资源管理器 - How to add a new command for a new application in context menu on windows 11 File Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM