gpt4 book ai didi

对正在运行的程序的 Windows URL 方案调用

转载 作者:可可西里 更新时间:2023-11-01 10:32:42 26 4
gpt4 key购买 nike

我想在我正在运行的应用程序中触发一个事件,并通过调用 Windows 10 中的 URL 方案传递参数。我创建了以下注册表项:

HKEY_CLASSES_ROOT
alert
(Default) = "URL:Alert Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "alert.exe,1"
shell
open
command
(Default) = "C:\Program Files\Alert\alert.exe" "%1"

显然,当调用“alert:arg1”时,这总是会启动一个带参数的应用程序新实例。但我希望 Windows 调用我已经运行的实例。

在 Mac 上,这个 URL scheme 的调用会触发一个事件,我可以捕捉到。没错,如我所愿。为此,我将以下部分添加到 alert.app/Contents/Info.plist:

<array>
<dict>
<key>CFBundleURLName</key>
<string>Alert</string>
<key>CFBundleURLSchemes</key>
<array>
<string>alert</string>
</array>
</dict>
</array>

那么我如何在 Windows 上实现这一点呢?我正在使用面向对象的 BASIC 在 XOJO 中编写此应用程序,但我会很高兴有一个通用的解决方案。

最佳答案

好吧,在阅读了 Alex 的回答后,我搜索了如何用代码实现这一点,并找到了一个很好解释和工作的 solution来自用 C# 编写的 Brad Smith。

上面的注册表项可以保持原样,但程序还需要:

  • A service class (which is exposed by the application instance
    via .NET remoting)
  • A modified entry point (which will either communicate with the service and then terminate, or start the application normally)

阅读他的文章并查看他的代码以获得进一步的解释。

关于对正在运行的程序的 Windows URL 方案调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com