📄 mainattr.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainAttr.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ReadButtonClick(TObject *Sender)
{
filename=Edit1->Text;
if(filename=="*.*") return;
//文件名称
FileName->Caption=filename;
//文件目录
FilePathName->Caption=DirectoryListBox1->Directory;
//文件的大小
HFILE hFile;
char *str;
unsigned int size;
str=filename.c_str();
hFile=_lopen(str,OF_READ);
size=GetFileSize((HANDLE*)hFile,0);
FileSize->Caption=IntToStr(size)+" Byte";
//文件的创建时间
if(GetFileTime((HANDLE*)hFile,CreationTime,
LastAccessTime,LastWriteTime)==false)
return;
FileTimeToSystemTime(CreationTime,STime);
CreateDate->Caption=TimeToString(STime);
//文件的访问时间
FileTimeToSystemTime(LastAccessTime,STime);
AccessDate->Caption=TimeToString(STime);
//取文件的修改时间
FileTimeToSystemTime(LastWriteTime,STime);
ChangeDate->Caption=TimeToString(STime);
//取文件属性
AttrByte=FileGetAttr(filename);
if ((AttrByte & faReadOnly)==faReadOnly) {
CheckBox1->Checked=True;
} else {
CheckBox1->Checked=False;
}
if ((AttrByte & faHidden)==faHidden) {
CheckBox2->Checked=True;
} else {
CheckBox2->Checked=False;
}
if ((AttrByte & faSysFile)==faSysFile) {
CheckBox3->Checked=True;
} else {
CheckBox3->Checked=False;
}
if ((AttrByte & faArchive)==faArchive) {
CheckBox4->Checked=True;
} else {
CheckBox4->Checked=False;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ModifyButtonClick(TObject *Sender)
{
AttrByte=0;
if (CheckBox1->Checked) AttrByte=(AttrByte | faReadOnly);
if (CheckBox2->Checked) AttrByte=(AttrByte | faHidden);
if (CheckBox3->Checked) AttrByte=(AttrByte | faSysFile);
if (CheckBox4->Checked) AttrByte=(AttrByte | faArchive);
FileSetAttr( filename, AttrByte );
//设定文件属性
ShowMessage("文件属性修改完成!");
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExitButtonClick(TObject *Sender)
{
Close();
}
AnsiString __fastcall TMainForm::TimeToString(SYSTEMTIME *Time)
{
AnsiString string1;
string1=IntToStr(Time->wYear)+"年";
string1+=IntToStr(Time->wMonth)+"月";
string1+=IntToStr(Time->wDay)+"日";
string1+=IntToStr(Time->wHour)+"时";
string1+=IntToStr(Time->wMinute)+"分";
string1+=IntToStr(Time->wSecond)+"秒";
return string1;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
delete CreationTime;
delete LastAccessTime;
delete LastWriteTime;
delete STime;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
CreationTime=new FILETIME;
LastAccessTime=new FILETIME;
LastWriteTime=new FILETIME;
STime=new SYSTEMTIME;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -