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 检查字符串是不是 包含 中文和获取中文字符个数

Delphi runasadmin 运行程序并申请管理员权限

Delphi xe更改ttrayicon系统任务栏图标(无模糊)

Delphi pagecontrol不�@示tab方式

Delphi获取控件界面图像“新招”

Delphi 手机号码库段号地区查询

Delphi 任务栏显示进度条 createcomobject(clsid_taskbarlist) as itaskbarlist4

Delphi 相对路径

Delphi setwindowshookex - 设置钩子 unhookwindowshookex - 卸掉钩子

Delphi下cpu getcpuid实现(x86和x64)

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



打赏

取消

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

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

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

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

评论

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