您的位置:首页 > 其它

动态获取文件的关联扩展名

2009-03-24 23:31 344 查看
unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Buttons, ExtCtrls, shellapi;

type

TForm1 = class(TForm)

Image1: TImage;

BitBtn1: TBitBtn;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

function GetFileIconByExt(const ExtName: string; SmallIcon: boolean): HICON;

implementation

{$R *.dfm}

function GetFileIconByExt(const ExtName: string; SmallIcon: boolean): HICON;

var

sinfo: SHFILEINFO;

sFlag: INTEGER;

tempName: string;

begin

tempName := ExtName;

if Copy(tempName, 1, 1) <> '.' then tempName := '.' + tempName;

ZeroMemory(@sinfo, sizeof(sinfo));

if SmallIcon then

sFlag := (SHGFI_USEFILEATTRIBUTES or SHGFI_SMALLICON or SHGFI_ICON)

else

sFlag := (SHGFI_USEFILEATTRIBUTES or SHGFI_LARGEICON or SHGFI_ICON);

SHGetFileInfo(pchar(tempName), FILE_ATTRIBUTE_NORMAL, sinfo, sizeof(sinfo), sFlag);

Result := sinfo.HICON;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

Image1.picture.icon.handle := GetFileIconByExt('pdf', false);

end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: