delphi SHGetFileInfo函数  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi SHGetFileInfo函数


// 确认在USES分句中包含'ShellApi'

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellApi, FileCtrl;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
Label5: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{局部声明}
public
{公共声明}
end;

var
Form1: TForm1;
FileInfo : SHFILEINFO;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var filename : string;
attrs : string;
attributes : integer;
begin
form1.repaint;
if filelistbox1.ItemIndex <> - 1 then
begin
filename := FileListBox1.FileName;
end
else
begin
filename := DirectoryListBox1.Directory;
end;
edit1.text := filename;
//获取显示名
SHGetFileInfo(PChar(FileName),0,FileInfo,SizeOf(FileInfo),SHGFI_DISPLAYNAME);
edit2.text := FileInfo.szDisplayName;
//获取类型名
SHGetFileInfo(PChar(FileName),0,FileInfo,SizeOf(FileInfo),SHGFI_TYPENAME);
edit3.text := FileInfo.szTypeName;
//获取文件的图标
SHGetFileInfo(PChar(FileName),0,FileInfo,SizeOf(FileInfo),SHGFI_ICON);
Drawicon(canvas.handle,5,170,FileInfo.hIcon);
form1.repaint;
//获取文件属性
attributes := GetFileAttributes(PChar(FileName));
attrs := '';
If Bool(attributes and FILE_ATTRIBUTE_READONLY) then attrs := attrs + 'R';
If Bool(attributes and FILE_ATTRIBUTE_HIDDEN) then attrs := attrs + 'H';
If Bool(attributes and FILE_ATTRIBUTE_SYSTEM) then attrs := attrs + 'S';
If Bool(attributes and FILE_ATTRIBUTE_ARCHIVE) then attrs := attrs + 'A';
edit4.text := attrs;
// 获取文件最后修改日期和时间
try
edit5.text := DateTimeToSTr(FileDateToDateTime(FileAge(FileName)));
except
// 如果你不是选择文件(如目录或驱动器)
on EConvertError do
edit5.text := 'Not Available';
end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
//当你在屏幕上移动窗体时,重画图标
Drawicon(canvas.handle,5,170,FileInfo.hIcon);
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043219089508057 seconds