delphi 在windows右键菜单中加上关联


本文整理自网络,侵删。

 

 

uses Registry;

function RegisterFileTypeCommand(fileExtension, menuItemText, target: string) : boolean;
var
  reg: TRegistry;
  fileType: string;
begin
  result := false;
  reg := TRegistry.Create;
  with reg do
  try
    RootKey := HKEY_CLASSES_ROOT;
    if OpenKey('.' + fileExtension, True) then
    begin
      fileType := ReadString('') ;
      if fileType = '' then
      begin
        fileType := fileExtension + 'file';
        WriteString('', fileType) ;
      end;
      CloseKey;
      if OpenKey(fileType + '/shell/' + menuItemText + '/command', True) then
      begin
        WriteString('', target + ' "%1"') ;
        CloseKey;
        result := true;
      end;
    end;
  finally
    Free;
  end;
end;

function UnRegisterFileTypeCommand(fileExtension, menuItemText: string) : boolean;
var
  reg: TRegistry;
  fileType: string;
begin
  result := false;
  reg := TRegistry.Create;
  with reg do
  try
    RootKey := HKEY_CLASSES_ROOT;
    if OpenKey('.' + fileExtension, True) then
    begin
      fileType := ReadString('') ;
      CloseKey;
    end;
    if OpenKey(fileType + '/shell', True) then
    begin
      DeleteKey(menuItemText) ;
      CloseKey;
      result := true;
    end;
  finally
    Free;
  end;
end;

相关阅读 >>

Delphi 将listview保存为txt

Delphi xe 无法编译apk提示sdk路径问题时?sdk路径配置方法

Delphi datasnap 初步入门使用总结

Delphi 在listview控件中绘底图

Delphi从trichedit获得rtf格式文本

Delphi第三方控件通用安装方法

Delphi读取和写入utf-8编码格式的文件

Delphi base64单元encddecd的修改

Delphi 给gmail发送邮件

Delphi getexplorerpid获取系统explorer.exe进程id

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...