当“打开方式”时,操作系统如何知道如何处理文件?选项被选中? [英] How does the OS know what to do with a file when the "Open With..." option is selected?

查看:143
本文介绍了当“打开方式”时,操作系统如何知道如何处理文件?选项被选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解释:
我不记得有关Linux,我不知道OS X,但在Windows中,您可以右键单击一个文件并选择一个程序来打开它。但是操作系统如何知道如何让程序打开呢?它是否跟踪程序具有的打开文件对话框?开发人员是否必须指定一个特殊的事件处理程序或这些情况下的东西?

解决方案

操作系统运行指定的程序发送参数是要打开的文件的路径。例如,在C#中,如果您想知道操作系统希望打开哪个文件,则需要执行以下操作:


$ $ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
if(args.Length == 1)//操作系统要我打开文件
openSomeFileJustBecauseTheOSWantsIt(args [0]);
}
}


Explanation: I don't remember about Linux and I don't know about OS X, but in Windows you can right-click a file and select a program to open it. But how does the OS know exactly how to make the program open it? Does it keep track of the "Open file" dialogs the program has? Does the developer have to specify a special event handler or something for these cases?

解决方案

The operating system runs the specified program sending as parameter the path of the file to open.

For example, in C#, if you want to know which file the operating system wants you to open you'll need to do:

class Program
{
    static void Main(string[] args)
    {
        if (args.Length == 1) //The OS wants me to open a file
            openSomeFileJustBecauseTheOSWantsIt(args[0]);
    }
}

这篇关于当“打开方式”时,操作系统如何知道如何处理文件?选项被选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆