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

时间:2016-02-27 13:59:46

标签: c# wpf

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

1 个答案:

答案 0 :(得分:0)

您可以为动词注册您的应用,然后使用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
    }
相关问题