Thread: Mkvextract GUI
View Single Post
Old 5th April 2004, 06:07   #10  |  Link
Blkbird
Registered User
 
Join Date: Sep 2002
Posts: 32
I have a few comments about the interface. First, why the permanent "warning" box there? Why not check the existence of the files required (in current dir and in PATH) at program start and bring a *modal* warning dialog if not found?

Second, the three "options" are not really options, they are actions. The "option" box is not really necessary.

And you may want to use a monospace font for the command lines.

Finally, the code you use to excute the commandline programs are somewhat problematic. Maybe the following sample could inspire you a bit:

Code:
function ExecConsoleApp(CommandLine: string; var Output: string): Cardinal;
const
  BufferSize = $4000;
var
  SecurityAttr: TSecurityAttributes;
  ReadHandle, WriteHandle: THandle;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  ReadBuffer: PChar;
  BytesRead: DWord;
begin
  SecurityAttr.nLength := SizeOf(TSecurityAttributes);
  SecurityAttr.bInherithandle := True;
  SecurityAttr.lpSecurityDescriptor := nil;
  if CreatePipe (ReadHandle, WriteHandle, @SecurityAttr, 0) then
  begin
    FillChar(StartupInfo, Sizeof(StartupInfo), 0);
    ReadBuffer := AllocMem(BufferSize + 1);
    StartupInfo.cb := SizeOf(StartupInfo);
    StartupInfo.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
    StartupInfo.hStdInput := ReadHandle;
    StartupInfo.hStdOutput := WriteHandle;
    StartupInfo.hStdError := WriteHandle;
    StartupInfo.wShowWindow := SW_HIDE;
    if CreateProcess(nil, PChar(CommandLine), @SecurityAttr, @SecurityAttr,
      True, DETACHED_PROCESS or NORMAL_PRIORITY_CLASS, nil, nil,
      StartupInfo, ProcessInfo)
    then begin
      WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
      (* If you want to do a running update of the output of the console app,
      you would not block here. Instead you could loop while GetExitCodeProcess
      returned STILL_ACTIVE all the while calling ReadFile on the pipe. *)
      // Output := '';
      // Without clearing Output before, its content will be expanded.
      repeat
        BytesRead := 0;
        ReadFile(ReadHandle, ReadBuffer[0], BufferSize, BytesRead, nil);
        ReadBuffer[BytesRead] := #0;
        Output := Output + ReadBuffer;
      until (BytesRead < BufferSize);
      // OemToAnsi(Output, Output);
      // OemToAnsi only works for PChar.
      GetExitCodeProcess(ProcessInfo.hProcess, Result);
    end
    else Result := Cardinal(-1);
    FreeMem(ReadBuffer);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ReadHandle);
    CloseHandle(WriteHandle);
  end;
end;
Blkbird is offline   Reply With Quote