H
hcnet
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Gauges, ComCtrls;
type
TForm1 = class(TForm)
Gauge1: TGauge;
Timer1: TTimer;
StatusBar1: TStatusBar;
procedure Timer1Timer(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure WinExecAndWait(CommandLine:String);
var ComLineBuffer: array[0..512] of char;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Re:Cardinal;
begin
StrPCopy(ComLineBuffer,CommandLine);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil,
ComLineBuffer, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
True, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Re);
CloseHandle(ProcessInfo.hProcess);
{ to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
end;
end;
// 等待EXE 执行完毕 函数....
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
begin
gauge1.BoundsRect := Rect ;
//进度条..坐标范围...
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if gauge1.Progress = 100 then
begin
gauge1.Progress := 0;
end
else
gauge1.Progress :=gauge1.Progress +1 ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
gauge1.Parent:=StatusBar1 ;
WinExecAndWait('cmd /c move d:/bak/*.* e:/bak/');
//这个只是打个比方.调用的员外部程序
end;
end.
不知有哪兄弟..有做过此类的,例子......................调用外部程序运行...进度条....跟随程序同步.........
现在目前 进度条 在程序开始运行的时候..无法进行同步....可有函数
可以做到吗.??
看来这个例子..没有朋友会的了.........
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Gauges, ComCtrls;
type
TForm1 = class(TForm)
Gauge1: TGauge;
Timer1: TTimer;
StatusBar1: TStatusBar;
procedure Timer1Timer(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure WinExecAndWait(CommandLine:String);
var ComLineBuffer: array[0..512] of char;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Re:Cardinal;
begin
StrPCopy(ComLineBuffer,CommandLine);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil,
ComLineBuffer, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
True, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Re);
CloseHandle(ProcessInfo.hProcess);
{ to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
end;
end;
// 等待EXE 执行完毕 函数....
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel;
const Rect: TRect);
begin
gauge1.BoundsRect := Rect ;
//进度条..坐标范围...
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if gauge1.Progress = 100 then
begin
gauge1.Progress := 0;
end
else
gauge1.Progress :=gauge1.Progress +1 ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
gauge1.Parent:=StatusBar1 ;
WinExecAndWait('cmd /c move d:/bak/*.* e:/bak/');
//这个只是打个比方.调用的员外部程序
end;
end.
不知有哪兄弟..有做过此类的,例子......................调用外部程序运行...进度条....跟随程序同步.........
现在目前 进度条 在程序开始运行的时候..无法进行同步....可有函数
可以做到吗.??
看来这个例子..没有朋友会的了.........