Dans un topic précédent on m'a proposé ca
.........
procedure RunDosInMemo(DosApp:String;AMemo:TMemo);
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Security do begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT);
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil);
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer);
AMemo.Text := AMemo.text + String(Buffer);
until (BytesRead < ReadBuffer);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Color:=clblack;
Memo1.Font.Color:=clwhite;
RunDosInMemo('cmd /C DIR *.*',Memo1);
end;
et cela :
procedure TForm1.Button1Click(Sender: TObject);
var
pc:array [0..max_path-1] of char;
h:HWND;
FileMSDos:PChar;
unite:string;
begin
h:=0;
GetWindowsDirectory(pc,max_path-1);
unite:=copy(StrPas(pc),1,3);//ça donne "C:" par exemple
FileMSDos:=PChar(StrPas(pc)+'\System32\cmd.exe');
Shellexecute(handle,'open',FileMSDos,'',PChar(unite),SW_HIDE);
while h=0 do h:=findwindow('ConsoleWindowClass',FileMSDos);
Windows.SetParent(h,form1.handle);//tu peux mettre sur un panel càd panel1.handle par exemple
SetWindowPos(h,HWND_TOP,0,0,0,0,SWP_NOSIZE or SWP_SHOWWINDOW);
end;
Je n'ai rien compris à la première proposition (je ne sais meme pas ou il faut mettre la source ptdrrrrrrr) et la deuxième bloque mon pc (pas de réponse de l'executable en faisant cont alt supp).
Tu penses quoi de ces 2 sources et peut tu sois m'aider pour la première soit me dire pourquoi la seconde beug.