unit dosProc;

interface
uses dvCrt, dvWin, dosMsg,
     winProcs, winTypes, strings, shellApi;

function executaProg (nomeProg, nomeDir, nomeArq: string; showCmd: integer): boolean;
procedure esperaProgVoltar;

implementation

var meuNome: array [0..101] of char;

function executaProg (nomeProg, nomeDir, nomeArq: string; showCmd: integer): boolean;
var
    pprog, pdir, pparam: array [0..145] of char;
    erro: tHandle;
begin
    executaProg := true;
    strPcopy (pprog, nomeProg);
    strPCopy (pdir, nomeDir);
    strPcopy (pparam, nomeArq);

    while sintFalando do;
    GetWindowText(crtWindow, meuNome, 100);

    erro := ShellExecute(crtWindow, 'open', pprog, pparam, pdir, showCmd);

    if erro < 32 then
        begin
            if erro = 2 then
                mensagem (DVPRGNAO, 0)
            else
                begin
                    mensagem (DVERRPRG, 0);
                    sintWriteInt (erro);
                end;
            writeln;
            executaProg := false;
        end;
end;

{--------------------------------------------------------}
{        espera o titulo da janela ficar o mesmo
{--------------------------------------------------------}

procedure esperaProgVoltar;
var
    nomeNovo: array [0..100] of char;
    i: integer;
begin
    i := 0;
    repeat
        GetWindowText (getFocus, nomeNovo, 100);
        i := i + 1;
    until (strComp (meuNome, nomeNovo) <> 0) or (i > 5);

    repeat
        delay (500);
        GetWindowText (getFocus, nomeNovo, 100);
    until strComp (meuNome, nomeNovo) = 0;
    while sintFalando do;
    delay (500);
end;

end.