检测用于在我的应用程序中打开文件的谓词

本文关键字:文件 谓词 用于 我的 应用程序 检测 | 更新日期: 2023-09-27 18:36:26

我有一个与我的应用程序关联的扩展,它可以很好地打开它,但我也想检测正在使用什么动词,因为我打算让我的应用程序以不同的方式处理打开和编辑。如何在 c# 中检测调用的谓词?

检测用于在我的应用程序中打开文件的谓词

可以为应用注册谓词,然后在 Main(string[] args) 方法中检查参数。

这是来自 https://msdn.microsoft.com/en-us/library/windows/desktop/cc144175(v=vs.85) 的注册表项的修改示例.aspx:

HKEY_CLASSES_ROOT
   MyProgram.exe
      shell
         open
            command
               (Default) = C:'MyDir'MyProgram.exe /open "%1"
         print
            command
               (Default) = C:'MyDir'MyProgram.exe /print "%1"
         printto
            command
               (Default) = C:'MyDir'MyProgram.exe /printto "%1" "%2"

因此,您的Main方法可能如下所示:

    static void Main(string[] args) {
        if (args.Length > 0)
            if (args[0] == "/print")
                // do print stuff
            else
                // etc.
        // rest of the program
    }