線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2469
推到 Plurk!
推到 Facebook!

請問一個問題.....有關TprogressBar的問題...

尚未結案
kevinhue
一般會員


發表:23
回覆:42
積分:13
註冊:2003-05-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-06 18:54:18 IP:218.160.xxx.xxx 未訂閱
請問TprogressBar要怎麼用阿...?? 不知道要怎麼設定......                             最粗的初學者
WhiteFang
一般會員


發表:9
回覆:23
積分:6
註冊:2002-11-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-06 20:04:20 IP:163.28.xxx.xxx 未訂閱
最基本的用法,設定最小值與最大值,以及目前值這三個數值即可 ProgressBar->Max=0; ProgressBar->Min=100; ProgressBar->Position ; 其他可以注意的幾項: ProgressBar->Smooth=true; 在成長時不會以塊狀呈現....
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-07 00:25:40 IP:61.221.xxx.xxx 未訂閱
引言: 請問TprogressBar要怎麼用阿...?? 不知道要怎麼設定......
kevinhue 你好: 補充一點,在 BCB 的開發環境中 還有一個 TCGauge 元件(在 Samples 裡面),也很好用的 < class="code"> CGauge1->ForeColor=clBlue; CGauge1->MinValue=0; CGauge1->MaxValue=100; for(int i=0; i<=100; i ) { CGauge1->Progress=i; Sleep(10); Application->ProcessMessages(); } -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
ys168
初階會員


發表:3
回覆:24
積分:25
註冊:2005-10-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-02-28 20:16:27 IP:218.161.xxx.xxx 訂閱
// 這是一個複製目錄檔案的程式有TprogressBar的進度條

//---------------------------------------------------------------------------
///////////////// 瀏覽資料夾標頭檔 //////////////////
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
#include <FileCtrl.hpp>
#include <WindowsX.h> // 為了使用 GlobalFreePtr()
/////////////////////////////////////////////////////
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop

#include "Unit1.h"
#define BIF_NEWDIALOGSTYLE 0x0040
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
char strA[MAX_PATH];
int TotalFile,nFile;
String SourDir,DestDir;
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lpData); //瀏覽資料夾使用

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
nFile=0;
TotalFile=0;
}
//---------------------------------------------------------------------------
//////////////////////// 以下是瀏覽資料夾使用函數 ///////////////////////////
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lpData)
{
if(uMsg == BFFM_INITIALIZED){
PCSTR prevDir = reinterpret_cast <PCSTR> (lpData);
if(DirectoryExists(prevDir)) SendMessage(hwnd, BFFM_SETSELECTION, static_cast <LPARAM> (1L), lpData);
}
return 0;
}
//-------------------------------------------------------------------------------------
bool __fastcall SetDirectory(AnsiString StartDir, AnsiString *selDir, AnsiString *dirName)
{
auto bool rc = true;

BROWSEINFO bi;
char PathStr[MAX_PATH];
char FolderName[MAX_PATH];
LPITEMIDLIST ItemID;
memset(&bi, 0, sizeof(BROWSEINFO));
memset(PathStr, 0, MAX_PATH);
bi.hwndOwner = Application->Handle;
bi.pszDisplayName = FolderName;
bi.lpszTitle = "請選擇資料夾:";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN | BIF_NEWDIALOGSTYLE;
bi.lpfn = reinterpret_cast <BFFCALLBACK>(BrowseCallbackProc);
bi.lParam = reinterpret_cast <LPARAM> (StartDir.c_str());

CoInitialize(NULL);
ItemID = SHBrowseForFolder(&bi);
if(ItemID == NULL){
rc = false;
}else{
SHGetPathFromIDList(ItemID, PathStr);
}
GlobalFreePtr(ItemID);
CoUninitialize();

*selDir = PathStr;
*dirName = FolderName;

return rc;
}
//-----------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄
AnsiString DestDirectory; // 儲存被選擇目錄的路徑字串
AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串
if(SetDirectory(StartDirectory, &DestDirectory, &DirectoryName))
{
Edit1->Text=DestDirectory;

}
}
//--------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄
AnsiString DestDirectory; // 儲存被選擇目錄的路徑字串
AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串
if(SetDirectory(StartDirectory, &DestDirectory, &DirectoryName))
{
Edit2->Text=DestDirectory;

}
}
//---------------------------------------------------------------------------
// 取得目錄檔案數量函數

// 外部宣告: int nFile;
void __fastcall TForm1::Get_DirFileNum(String DirPath)
{
if (DirPath[DirPath.Length()] != '\\')
DirPath = String("\\");

String mask = (DirPath "*.*");
WIN32_FIND_DATA fd = {0};
HANDLE h = FindFirstFile(mask.c_str(), &fd); //Win32 API

if(h != INVALID_HANDLE_VALUE)
{
while(FindNextFile(h, &fd) ) //Win32 API
{
String File = fd.cFileName;

if(File == "." || File == "..")
continue;
Application->ProcessMessages();
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
String SourceDir = DirPath File "\\";
Get_DirFileNum(SourceDir);
Application->ProcessMessages();
}
else
{
TotalFile ; // 外部宣告: int nFile;
Application->ProcessMessages();
}
}
FindClose(h); // Win 32 API
}
}
//-----------------------------------------------------------------------------
// 複製目錄檔案函數
void __fastcall TForm1::Copy_Subdirectory(String PathSource, String PathDest)
{
if (PathSource[PathSource.Length()] != '\\')
PathSource = String("\\");

if (PathDest[PathDest.Length()] != '\\')
PathDest = String("\\");

String mask = (PathSource "*.*");
WIN32_FIND_DATA fd = {0};
HANDLE h = FindFirstFile(mask.c_str(), &fd); //Win32 API

if(h != INVALID_HANDLE_VALUE)
{
while(FindNextFile(h, &fd) ) //Win32 API
{
String File = fd.cFileName;

if(File == "." || File == "..")
continue;
Application->ProcessMessages();
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
SourDir = ExtractFileDir(PathSource File);
if(SourDir.Length() == 3)
SourDir = SourDir.UpperCase();
else
{
SourDir = SourDir.SubString(SourDir.LastDelimiter("\\") 1,SourDir.Length());
int lenth=SourDir.Length();
if(lenth>25)
{
SourDir=SourDir.SubString(1,24);
SourDir ="~";
}
}

DestDir = ExtractFileDir(PathDest File);
if(DestDir.Length() == 3)
DestDir= DestDir.UpperCase();
else
{
DestDir = DestDir.SubString(DestDir.LastDelimiter("\\") 1,DestDir.Length());
int lenth2=DestDir.Length();
if(lenth2>25)
{
DestDir=DestDir.SubString(1,24);
DestDir ="~";
}
}
lbl2->Caption = "從【" SourDir "】到【" DestDir "】";

////////////////////////////////////////////////////////////////
if (!CreateDir(PathDest File)) //VCL function
// ShowMessage("Cannot create directory :" PathDest File);
;
String SourceDir = PathSource File "\\";
String DestDir = PathDest File "\\";

Copy_Subdirectory(SourceDir, DestDir);
Application->ProcessMessages();
}
else
{
/////////////////////////////////////////////////////
sprintf(strA,"%s%s",PathSource.c_str(),File.c_str());
lbl1->Caption = ExtractFileName(strA);

nFile ; // 檔案數累進變數,外部宣告
/////////////////////////////////////////////////////

if (!CopyFile((PathSource File).c_str(),
(PathDest File).c_str(), FALSE)) //Win32 API
{
void* vpBuffer;

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM,NULL,
GetLastError(),MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(char*) &vpBuffer,0, NULL);

LocalFree(vpBuffer);
}
Application->ProcessMessages();

}
ProgressBar1->Position = nFile; // 使用進度條設定
}

FindClose(h); // Win 32 API
}
}
//-----------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Get_DirFileNum(Edit1->Text); // 取得目錄檔案的數量 TotalFile
Animate1->Visible=true;
Animate1->Active = true;
ProgressBar1->Visible=true;
ProgressBar1->Min=0;
ProgressBar1->Max=TotalFile;
Copy_Subdirectory(Edit1->Text, Edit2->Text);
Animate1->Active = false;
Animate1->Visible=false;
ShowMessage("檔案複製完成...");
}
//---------------------------------------------------------------------------


------
yangshuh
系統時間:2024-05-07 6:57:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!