📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BitBtn1Click(TObject *Sender)
{
if(ZipFileNameT1 == "")
{
Application->MessageBox("ZipFileName for Thread 1 not defined","ThreadDemo",
MB_OK | MB_ICONERROR);
return;
}
if(ZipFileNameT2 == "")
{
Application->MessageBox("ZipFileName for Thread 2 not defined","ThreadDemo",
MB_OK | MB_ICONERROR);
return;
}
if(ZipFileNameT1 == ZipFileNameT2)
{
Application->MessageBox("Threads have to be for different files","ThreadDemo",
MB_OK | MB_ICONERROR);
return;
}
if(PathT1 == "")
{
Application->MessageBox("Source Path for Thread 1 not defined","ThreadDemo",
MB_OK | MB_ICONERROR);
return;
}
if(PathT2 == "")
{
Application->MessageBox("Source Path for Thread 2 not defined","ThreadDemo",
MB_OK | MB_ICONERROR);
return;
}
T1 = new TMyThread(PathT1,ZipFileNameT1,LblOkT1,LblErrT1,false);
T2 = new TMyThread(PathT2,ZipFileNameT2,LblOkT2,LblErrT2,false);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
static AnsiString FirstDir = "";
if(FirstDir == "") GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, FirstDir);
OpenDialog1->InitialDir = FirstDir;
OpenDialog1->FileName = "";
OpenDialog1->Filter = "ZIP Files (*.ZIP)|*.zip";
OpenDialog1->DefaultExt = "Zip";
OpenDialog1->Title = "Create New ZIP File";
OpenDialog1->Options << ofHideReadOnly << ofShareAware;
OpenDialog1->Options >> ofPathMustExist >> ofFileMustExist;
if(OpenDialog1->Execute())
{
FirstDir = ExtractFilePath(OpenDialog1->FileName);
if(FileExists(OpenDialog1->FileName))
{
bool Ans = MessageDlg( "Overwrite Existing File: " + OpenDialog1->FileName + "?",
mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes;
if(Ans) DeleteFile(OpenDialog1->FileName);
else return; // Don't use the new name.
}
TButton *Btn = dynamic_cast<TButton*>(Sender);
if(Btn->Tag == 1)
{
ZipFileNameT1 = OpenDialog1->FileName;
LblFnameT1->Caption = MinimizeName(ZipFileNameT1 ,LblFnameT1->Canvas,
LblFnameT1->Width - 5);
}
else
{
ZipFileNameT2 = OpenDialog1->FileName;
LblFnameT2->Caption = MinimizeName(ZipFileNameT2 ,LblFnameT2->Canvas,
LblFnameT2->Width - 5);
}
}
}
//---------------------------------------------------------------------------
long TMainForm::GetSpecialFolder( int aFolder, String &Location )
{
long FolderErr = 0; // No error.
char RealPath[MAX_PATH];
ITEMIDLIST *pidl;
HRESULT hRes = SHGetSpecialFolderLocation( Handle, aFolder, &pidl );
if(hRes == NOERROR)
{
if(SHGetPathFromIDList(pidl, RealPath)) Location = RealPath + AnsiString("\\");
else FolderErr = E_UNEXPECTED;
}
else FolderErr = hRes;
return FolderErr;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
char DisplayBuf[MAX_PATH];
BROWSEINFO BrowseInfo = {0};
ITEMIDLIST *ItemID;
BrowseInfo.hwndOwner = Handle;
BrowseInfo.pszDisplayName = DisplayBuf;
BrowseInfo.lpszTitle = "ThreadDemo";
BrowseInfo.ulFlags = BIF_USENEWUI | BIF_NONEWFOLDERBUTTON;
ItemID = SHBrowseForFolder(&BrowseInfo);
if(ItemID)
{
char DirPath[MAX_PATH] = "";
SHGetPathFromIDList(ItemID, DirPath);
TButton *Btn = dynamic_cast<TButton*>(Sender);
if(Btn->Tag == 1)
{
PathT1 = DirPath + AnsiString("\\");
LblPath1->Caption = MinimizeName(PathT1 ,LblPath1->Canvas, LblPath1->Width - 5);
}
else
{
PathT2 = DirPath + AnsiString("\\");;
LblPath2->Caption = MinimizeName(PathT2 ,LblPath2->Canvas, LblPath2->Width - 5);
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -