Autor Beitrag
boontec
Hält's aus hier
Beiträge: 15

Win XP Professional
Delphi 2005 Prof.
BeitragVerfasst: Do 15.12.05 18:03 
moinsen ich bins wieder

meine frage nun:
wie kann ich einem waitforsingleobject eine progressbar hinzufügen ?

ich habe diesmal die suche benutzt nur find ich nichts :(



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
unction WinExec32AndWait(const Cmd: string; const CmdShow: Integer): Cardinal;
var
  sui : TStartupInfo;
  pi : TProcessInformation;
begin

  Result := Cardinal($FFFFFFFF);
  ZeroMemory(@sui,sizeof(TStartupInfo)); sui.cb := SizeOf(TStartupInfo);
                                         sui.dwFlags := STARTF_USESHOWWINDOW;
                                         sui.wShowWindow := CmdShow;

  if(CreateProcess(nil,pchar(Cmd),nil,nil,False,NORMAL_PRIORITY_CLASS,nil,nil,sui,pi)) then
    begin
      WaitForInputIdle(pi.hProcess, INFINITE);
      if(WaitForSingleObject(pi.hProcess, INFINITE) = WAIT_OBJECT_0) then
        begin
          {$IFDEF DELPHI3}
          if not GetExitCodeProcess(pi.hProcess, Integer(Result)) then
          {$ELSE}
          if not GetExitCodeProcess(pi.hProcess, Result) then
          {$ENDIF DELPHI3}
            Result := Cardinal($FFFFFFFF);
        end;
      CloseHandle(pi.hThread);
      CloseHandle(pi.hProcess);
    end;
end;


Thx

MfG

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 15.12.2005 um 18:04
Moderiert von user profile iconTino: Titel geändert.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Fr 16.12.05 17:09 
Du wartest mit WaitForSingleObject nicht ewig, sondern übergibst eine Wartezeit. Wenn die überschrittenist, ohne das der überwachte Prozess beendet wurde, kommt WaitForSingleObject mit WAIT_TIMEOUT zurück. Dann kannst du deinen ProgressBar inkrementieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
    repeat
      Application.ProcessMessages;
      ProgressBar.StepIt;
      Result := WaitForSingleObject(processInfo.hProcess, 100);
    until Result <> WAIT_TIMEOUT;


Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
boontec Threadstarter
Hält's aus hier
Beiträge: 15

Win XP Professional
Delphi 2005 Prof.
BeitragVerfasst: So 18.12.05 21:13 
danke dir habe diesen thread hier fast schon aufgegeben ..
ich werde es mal versuchen ob es klappt
boontec Threadstarter
Hält's aus hier
Beiträge: 15

Win XP Professional
Delphi 2005 Prof.
BeitragVerfasst: Mo 19.12.05 13:01 
So ich habe diese progressbar nun eingebaut

aber nun geht die progressbar nich komplett durch sondern nur ein stück weit, wenn ich nochmal auf einen button klicke geht die bar ein stück weiter usw (step)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
function WinExec32AndWait(const Cmd: string; const CmdShow: Integer): Cardinal;
var

  sui : TStartupInfo;
  pi : TProcessInformation;


begin

  Result := Cardinal($FFFFFFFF);
  ZeroMemory(@sui,sizeof(TStartupInfo)); sui.cb := SizeOf(TStartupInfo);
                                         sui.dwFlags := STARTF_USESHOWWINDOW;
                                         sui.wShowWindow := CmdShow;

  if(CreateProcess(nil,pchar(Cmd),nil,nil,False,NORMAL_PRIORITY_CLASS,nil,nil,sui,pi)) then
    begin

      WaitForInputIdle(pi.hProcess, INFINITE);

      if(WaitForSingleObject(pi.hProcess, INFINITE) = WAIT_OBJECT_0) then
        begin


          {$IFDEF DELPHI3}
          if not GetExitCodeProcess(pi.hProcess, Integer(Result)) then
          {$ELSE}
          if not GetExitCodeProcess(pi.hProcess, Result) then
          {$ENDIF DELPHI3}
            Result := Cardinal($FFFFFFFF);
        end;
      CloseHandle(pi.hThread);
      CloseHandle(pi.hProcess);
 //progressbar
     repeat
      Application.ProcessMessages;
      Form1.ProgressBar1.StepIt;
      Result := WaitForSingleObject(pi.hProcess, 100);
    until Result <> WAIT_TIMEOUT;
    end;
//progressbar
end;
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mo 19.12.05 13:30 
SO geht es natürlich nicht - du hast ja zuerst ein WaitForSingleObject, das du mit einer Wartezeit von INFINITE aufrufst, das also erst zurückkommt, wenn das aufgerufene Programm beendet ist. Dann schliesst du die Handles und hast danach erst die Schleife, die WaitForSingleObject mit einem Timeout aufruft - und dabei das mittlerweise geschlossene, also ungültige Handle verwendet. Das ist natürlich Quatsch - die Schleife muss anstelle des ersten WaitForSingleObject eingesetzt werden.

Ausserdem kann dein Programm nicht wissen, wie lange das aufrufende Programm braucht. Der wird sich also um ein paar Stellen bewegen und dann irgendwo stoppen. Um das exakt zu steuern, muss das aufgerufene Programm dem Aufrufer schon irgendwie mitteilen, wie weit es mit seiner Arbeit ist.

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
boontec Threadstarter
Hält's aus hier
Beiträge: 15

Win XP Professional
Delphi 2005 Prof.
BeitragVerfasst: Mo 19.12.05 13:50 
hmm kannst du mal n kleines beispiel machen ?? nur wenns nicht zuviel ist :oops:

Thx
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mo 19.12.05 16:01 
So müsste es funktionieren:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
function WinExec32AndWait(const Cmd: string; const CmdShow: Integer): Cardinal;  
var  
  sui : TStartupInfo;  
  pi : TProcessInformation;  
begin  
  Result := Cardinal($FFFFFFFF);  
  ZeroMemory(@sui,sizeof(TStartupInfo)); 
  sui.cb := SizeOf(TStartupInfo);  
  sui.dwFlags := STARTF_USESHOWWINDOW;  
  sui.wShowWindow := CmdShow;  
  if(CreateProcess(nil, pchar(Cmd), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, sui, pi)) then  
  begin  
    WaitForInputIdle(pi.hProcess, INFINITE);
    
    // auf Prozessende warten, jede Zehntelsekunde Progressbar animieren
    repeat  
      Application.ProcessMessages;  
      Form1.ProgressBar1.StepIt;  
      Result := WaitForSingleObject(pi.hProcess, 100);  
    until Result <> WAIT_TIMEOUT;

    // Exit-Code abholen
    {$IFDEF DELPHI3}  
    if not GetExitCodeProcess(pi.hProcess, Integer(Result)) then  
    {$ELSE}  
    if not GetExitCodeProcess(pi.hProcess, Result) then  
    {$ENDIF DELPHI3}  
      Result := Cardinal($FFFFFFFF);  

    // Handles schliessen
    CloseHandle(pi.hThread);  
    CloseHandle(pi.hProcess);
  
    // Progress-Bar auf Endposition setzen
    Form1.ProgressBar1.Position := Form1.ProgressBar1.Maximum;
  end;  
end;


Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
boontec Threadstarter
Hält's aus hier
Beiträge: 15

Win XP Professional
Delphi 2005 Prof.
BeitragVerfasst: Mo 19.12.05 16:22 
super klasse danke es klappt dank deiner hilfe echt top jetzt noch n paar feineinstellungen ;)

nochmal vielen vielen dank :)