注册文件类型,设置文件图标
2006-02-04 13:50:14 来源:WEB开发网{-------------------------------------------------------------------------------
@过程名: 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;
更多精彩
赞助商链接