注册文件类型,设置文件图标

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhangguanshi 的 blog

{-------------------------------------------------------------------------------
  @过程名:    slpert -> tfm_main.setassociatedexec
  @作者:      gavin
  @日期:      2004.09.08
  @功能描述:
  @参数:      fileext, filetype, filedescription, mimetype, execname: string
  @返回值:    boolean
-------------------------------------------------------------------------------}

function tfm_main.setassociatedexec(fileext, filetype, filedescription,
  mimetype, execname: string): boolean; {修改成功,返回true,否则false}
var
  reg: tregistry;
  shfileinfo: tshfileinfo;
  iconindex: integer;
begin

  result := false; {}
  // shgetfileinfo(pchar(execname), 0, shfileinfo,sizeof(shfileinfo), shgfi_largeicon or shgfi_sysiconindex or shgfi_typename or shgfi_smallicon);
   //iconindex:=shfileinfo.iicon;
   //showmessage(inttostr(iconindex));
  if (fileext = '') or (execname = '') then
    exit; {如果文件类型为空或者没有定义执行程序就退出,fileext必须带″.″,如.bmp}
  reg := tregistry.create;
  try
    reg.rootkey := hkey_classes_root;
    if not reg.openkey(fileext, true) then
      exit; {当不能正确找到或创建fileext键时退出,这种情况一般是注册表有错误,以下同}
    reg.writestring('', filetype);
    if mimetype <> '' then
    begin
      reg.writestring('content type', mimetype);
    end;
    reg.closekey;
    if not reg.openkey(filetype, true) then
      exit;
    reg.writestring('', filedescription);
    if not reg.openkey('shell\open\command', true) then
      exit;
    reg.writestring('', execname + ' "%1"');
    {执行程序一般都有参数,例如winzip的“winzip32.exe ″%1″”,″%1″参数指zip文件的文件名。因此execname应视情况加入参数}
    reg.closekey;
    if not reg.openkey(filetype + '\defaulticon', true) then
      exit;
    reg.writestring('',execname+' ,1');   ///extractfilepath(
    reg.closekey;
    result := true;
  finally
    reg.free;
  end;
end;

本文关键:注册文件类型,设置文件图标
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top