• Delphi 让自己的软件实现双击打开文件 转


     

    unit shjAssociateFileType;


    interface

    uses Windows, Registry;

    {将文件类型strFileExtension与程序strExeFileName相关联,strDiscription为文件类型说明}
    function AssignToProgram(const strFileExtension, strDiscription, strExeFileName: string ): boolean;

    implementation

    {将文件类型strFileExtension与程序strExeFileName相关联,strDiscription为文件类型说明}
    function AssignToProgram(const strFileExtension, strDiscription, strExeFileName: string ): boolean;
    var
      regFile: TRegistry;
    begin
      //建立一个Registry实例
      regFile := TRegistry.Create;

      with regFile do
      begin
        //设置根键值为HKEY_CLASSES_ROOT
        RootKey := HKEY_CLASSES_ROOT;

        //创建或者打开扩展名自动关联注册键
        OpenKey( '.' + strFileExtension, true);

        //设置扩展名自动关联
        WriteString('', strFileExtension + '_Auto_File');

        //关闭键
        CloseKey;

        //创建或者打开打开自动关联键
        OpenKey(strFileExtension + '_Auto_File', true);

        //设置文件类型说明
        WriteString('', strDiscription);

        //关闭键
        CloseKey;

        //创建或打开关联程序键
        OpenKey(strFileExtension + '_Auto_Fileshellopencommand', true);

        //设置关联程序(注意:%1加上双引号,可以解决文件路径中含空格的问题)
        WriteString('',strExeFileName + ' "%1"');

        //关闭键
        CloseKey;

        //打开默认图标键
        OpenKey(strFileExtension + '_Auto_Filedefaulticon',true);

        //关联默认图标
        WriteString('', strExeFileName + ',0');

        //释放
        Free;

        Result := True;
      end;
    end;

    end.

  • 相关阅读:
    零基础学习Java Web开发(一)
    域名的定义
    MyEclipse使用(一)
    VB与C#语言部分不用的地方Part1
    使用XmlWriter创建XML文件
    Spring源码
    Websocket原理
    阿里云
    CSS中position属性( absolute | relative | static | fixed )详解
    C#UDP广域网,局域网通信-原理分析
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/5264844.html
Copyright © 2020-2023  润新知