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 tserversocket 发送消息之前检查客户端是否仍处于连接状态

Delphi经常用到的公共代码(tools.pas)

Delphi xe5 android 发短信以及目录

Delphi根据进程pid等待进程结束或者结束进程

Delphi utf8乱码问题

Delphi自有的md5函��

Delphi winapi: getwindowthreadprocessid - 获取指定窗口的进程 id 或线程 id

Delphi xe7实现获取程序是否已管理员模式运行以及运行的windows用户名

Delphi bmp jpg 转换保存

Delphi 根据ip获取局域网mac

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



打赏

取消

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

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

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

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

评论

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