小弟在文件系统操作中遇到一个问题,就是被windows注册文件类型都有其标准的图标,那么在自己开发的系统中怎样使用windows图标显示文件?还有一个问题是怎样调用windows注册程序打开该文件。谢谢!

解决方案 »

  1.   

    ShellExecute(Handle, 'Open', PChar(FileName), nil, nil, SW_SHOW);
    FileName是带有路径的。这样就自动用相关程序打开文件了。
      

  2.   

    //以下提到的3个函数合理利用,一定能够达到你的目的。
    unit GraphicsExpand;interface
    uses
       Forms , Registry , Graphics , ShellAPI , Controls , SysUtils , Windows , Dialogs;//得到打开这个文件的Exe文件名 
    //如GetExeByOpenFile('xxx.DOC') = 'C:\WinWord\WinWord.Exe'
    Function GetExeByOpenFile(FileName:String):String;//得到设置的文件的图标号
    Function GetExeIcoByOpenFile(FileName:String):integer;//把一个文件对应的图标加到ImageList中
    Function AddFileIcoToImgLst(FileName : String ; ImageList : TImageList) : integer;implementationFunction AddFileIcoToImgLst(FileName : String ; ImageList : TImageList) : integer;
    var
      Count , IcoIndex : integer;
      Ico : Ticon;
      ExFile : String;
    begin
      Result := -1;
      ExFile := GetExeByOpenFile(FileName);
      IcoIndex := GetExeIcoByOpenFile(FileName);
      Count := ExtractIcon( Application.Handle, PChar(ExFile),$FFFFFFFF);
      Ico := Ticon.Create;
      if( IcoIndex < Count ) then begin
        Ico.Handle := ExtractIcon( Application.Handle, PChar(ExFile), IcoIndex );
        ImageList.AddIcon(Ico);
        Result := ImageList.Count -1;
      end;
      Ico.Free;
    end;Function GetStrByOpenFile(FileName:String):String;
    var
      Reg : Tregistry;
      FEName , RegNe: String;
    begin
      Result := '%SystemRoot%\System32\shell32.dll,0';
      FeName := ansiuppercase(Trim(extractfileext(FileName)));
      if FEName='.EXE' then Result := Trim(FileName)
      else if copy(Trim(FileName),Length(Trim(FileName)),1)='\' then Result := '%SystemRoot%\System32\shell32.dll,3'
      else if FEName='' then Result := '%SystemRoot%\System32\shell32.dll,0'
      else begin
        if copy(FEName,1,1)<>'.' then FEName := '.'+FEName;
        Reg := TRegistry.Create;
        Reg.RootKey := HKEY_CLASSES_ROOT;
        if Reg.OpenKey(FEName,True) then begin
          RegNE := Reg.ReadString('')+'\\DefaultIcon';
          Reg.CloseKey;
          if RegNe <> '\\DefaultIcon' then begin
            Reg.OpenKey(RegNE,True);
            Result := Reg.ReadString('');
            Reg.CloseKey;
          end;
        end;
        Reg.Free;
      end;
    end;Function GetExeIcoByOpenFile(FileName:String):integer;
    var
      Tmp , cStr : String;
    begin
      Result := 0;
      Tmp := '';
      cStr := GetStrByOpenFile(FileName);
      if cStr<>'' then
      while True do begin
        if pos(copy(cStr,Length(cStr),1),'-0123456789')>0 then
           begin
             Tmp := copy(cStr,Length(cStr),1) + Tmp;
             cStr := copy(cStr,1,Length(cStr)-1)
           end
        else begin
           if Tmp<>'' then Result := strtoint(Tmp);
           Break;
        end;
      end;
    end;Function GetExeByOpenFile(FileName:String):String;
    var
      cStr : String;
    begin
      cStr := GetStrByOpenFile(FileName);
      Result := cStr;
      if (cStr<>'') and (Pos(',',cStr)>0) then
      while True do begin
        if copy(cStr,Length(cStr),1)<>',' then
           cStr := copy(cStr,1,Length(cStr)-1)
        else begin
           Result := copy(cStr,1,Length(cStr)-1);
           Break;
        end;
      end;
    end;
    end.