我想问问如何使自己程序的特有的文件对应这相应的自己的特有的图标,比如winzip的.zip文件就有自己的图标!谢谢了!

解决方案 »

  1.   

    //给你个函数,实现你要的功能!
    ///////////////////////////
    function SetFileAssociation(Ext:string;
                                OpenApp:string;
                                FileTypeDescription:string='';
                                OpenMenuCaption:string='';
                                IconFile:string='';
                                IconIndex:integer=0;
                                Notify:boolean=true):boolean;
    var
    reg:tregistry;
    key:string;
    label
    final;
    begin
    result:=false;
    if ext='' then exit;
    if ext[1]<>'.' then ext:='.'+ext;
    //if openmenucaption='' then openmenucaption:='&Open';
    if IconFile='' then IconFile:=openapp;
    key:=copy(ext,2,length(ext))+' File';
    if filetypedescription='' then filetypedescription:=key;//////////////////////////////////////////
    try
      reg:=tregistry.Create;
      reg.RootKey:=hkey_classes_root;
      if reg.OpenKey(ext,true) then
      begin
        reg.WriteString('',key);
        reg.CloseKey;
      end
      else
        goto final;
      if reg.OpenKey(key,true) then
      begin
        reg.WriteString('',filetypedescription);
        reg.CloseKey;
      end
      else
        goto final;
      if reg.OpenKey(key+'\DefaultIcon',true) then
      begin
        reg.WriteString('',openapp+','+inttostr(iconindex));
        reg.CloseKey;
      end
      else
        goto final;
      if (OpenMenuCaption<>'') and (reg.OpenKey(key+'\Shell\Open',true)) then
      begin
        reg.WriteString('',openmenucaption);
        reg.CloseKey;
      end
      else
        goto final;
      if reg.OpenKey(key+'\Shell\Open\Command',true) then
      begin
        reg.WriteString('','"'+openapp+'" "%1"');
        reg.CloseKey;
      end
      else
        goto final;
      if notify then  
        notifyassociationchange;
      result:=true;
    final:
    finally
    reg.Free;
    end;
    end;
      

  2.   

    procedure NotifyAssociationChange;
    begin
      SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
    end;
      

  3.   

    在注册表的HKEY_CLASSES_ROOT下新建一个项(假设你的文件名的后缀为.my,则新建.my项),它的“默认”键的键值为My.File,再在HKEY_CLASSES_ROOT下新建一个项My.File,其下新建一个子项DefaultIcon,它的“默认”键的键值为你的icon图标。如果你的exe里面包含了图标,则键值为exe以及图标的序号
      

  4.   

    明白了,可不可以再问一个问题,就是我写的程序使用delphi写的,可是我不想让我的程序一直用delphi的那个特有的图表,我想换成我自己的,如何做呢!?
    谢谢了1
      

  5.   

    菜单:Project -> Options
    Application页 Load Icon...按钮