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.不知可有此类的,例子......................调用外部程序运行...进度条....跟随程序同步.........现在目前 进度条 在程序开始运行的时候..无法进行同步....请教多指教....
2、把你的WinExecAndWait放到一个线程里执行,执行完毕后给主程序发送一个消息,告诉主程序停止更新进度条。
3、把你的WinExecAndWait放到一个线程里执行,然后在定时器里每次都判断这个线程的Terminated参数来选择是更新进度条还是停止更新进度条。
begin
//这里更新进度条
end;
可否........把给示例代码................这个问题..困扰.N天了..........
最好有完整的代码...给个..演示...Thanks for you !!!!!
begin
//这里写更新进度条代码(自己添加) Application.ProcessMessage;
Sleep(1);
end;
// WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Re);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
代码已修改....进度条........还是无法.............进行同步进行............ 楼上的兄弟做能做个 示例能发到 Thanks !!!
begin
if gauge1.Progress = 100 then
begin
gauge1.Progress := 0;
end
else
gauge1.Progress :=gauge1.Progress +1 ;
Self.Invalidate;
self.update;
Application.ProcessMessage;
end;
GetExitCodeProcess(ProcessInfo.hProcess, Re);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
begin
if gauge1.Progress = 100 then
begin
gauge1.Progress := 0;
end
else
gauge1.Progress :=gauge1.Progress +1 ;
Self.Invalidate;
self.update;
Application.ProcessMessage;
end;
GetExitCodeProcess(ProcessInfo.hProcess, Re);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread); 经过修改后...procedure TForm1.FormCreate(Sender: TObject);
begin
gauge1.Parent:=StatusBar1 ; WinExecAndWait('cmd /c move d:\bak\*.* e:\bak\');
运行这里就报错了.....
Thanks everyone !!!!!!!
就是那个 启动 停止 我自己添加进去的服务。不也是可以。。实现进度条吗????csdn 上的。。牛人可能。。都忙得休息去了。。看来这里是没人能真正搞定了。