unit dosjanel;
interface
uses winprocs, wintypes, windos, dvcrt, dvwin, strings,
     dosgeral, dosmsg;

procedure vaiParaJanela;

implementation

{--------------------------------------------------------}
{           converte nomes para fala mais rapida
{--------------------------------------------------------}

function simplifica (s: string): string;
var final, palavra: string;
    p: integer;
    c: char;
begin
    final := '';
    while s <> '' do
        begin
             while (s <> '') and (s[1] = ' ') do
                 delete (s, 1, 1);

             if s <> '' then
                 begin
                     palavra := '';
                     while (s <> '') and (s[1] <> ' ') do
                         begin
                             palavra := palavra + copy (s, 1, 1);
                             delete (s, 1, 1);
                        end;

                    repeat
                        p := pos ('\', palavra);
                        if (p <> 0) and (p <> length (palavra)) then
                            delete (palavra, 1, p);

                    until (p = 0) or (p = length (palavra));

                    final := final + palavra + ' ';
                 end;

        end;

    while (length (final) > 0) and (final [length (final)] = ' ') do
        delete (final, length(final), 1);
    while (length (final) > 0) and (final [length (final)] = ']') do
        delete (final, length(final), 1);

    simplifica := final;
end;

{--------------------------------------------------------}
{                 vai para outra janela
{--------------------------------------------------------}

procedure vaiParaJanela;
type
    INFORM_JANELA = record
        jan: hwnd;
        visivel, iconica: boolean;
        titulo: string;
    end;

var
    currWnd: hwnd;
    ret: word;
    txt: array [0..144] of char;
    njan: integer;
    infoJan: array [1..100] of ^INFORM_JANELA;
    i, numSelec: integer;
    c, c2: char;
    modoFala: integer;

label fim;

begin
    CurrWnd := GetWindow(crtWindow, GW_HWNDFIRST);

    njan := 0;
    While CurrWnd <> 0 do
        begin
            if isWindowEnabled (currWnd) then
                begin
                    njan := njan + 1;
                    new (infoJan[njan]);
                    with infoJan[njan]^ do
                        begin
                            jan := currWnd;
                            visivel := isWindowVisible (currWnd);
                            iconica := isIconic (currWnd);
                            GetWindowText(CurrWnd, txt, 144);
                            titulo := strPas (txt);
                            if not ((visivel or iconica) and (length (titulo) <> 0)) then
                                 begin
                                     dispose (infoJan[njan]);
                                     njan := njan - 1;
                                 end;
                        end;
                end;

           CurrWnd := GetWindow(CurrWnd, GW_HWNDNEXT);
        end;

    mensagem (DVSELJAN, 0);   {Selecione a janela com as setas depois ENTER}

    numSelec := 0;
    c := 'x';
    while c <> ENTER do
        begin
            modoFala := 0;
            pegaTeclado (c, c2);
            if wherex <> 1 then writeln;

            if c = ESC then
                goto fim;

            if (c = #0) then
            case c2 of
                HOME:   numSelec := 0;
                TEND:   numSelec := njan + 1;
                PGUP, CIMA:
                        begin
                            numSelec := numSelec - 1;
                            if numSelec <= 0 then numSelec := 0;
                        end;
                PGDN, BAIX:
                        begin
                            numSelec := numSelec + 1;
                            if numSelec > njan then  numSelec := njan + 1;
                        end;
                DIR:    modoFala := 1;
                ESQ:    modoFala := 2;

                GOTFOCUS:
                    mensagem (DVSELJAN, 0);   {Selecione a nova janela com as setas depois ENTER}
            end;

            if (numSelec < 1) or (numSelec > njan) then
                sintClek
            else
                if c = #$0 then
                  case modoFala of
                    0: sintWrite (simplifica (infoJan[numSelec]^.titulo));
                    1: sintWrite (infoJan[numSelec]^.titulo);
                    2: begin
                           write (infoJan[numSelec]^.titulo);
                           sintSoletra (infoJan[numSelec]^.titulo);
                        end;
                end;
        end;

    if (numSelec >= 1) and (numSelec <= njan) then
        begin
            mensagem (DVOK, 0);    {'OK'}
            calaboca;
            ShowWindow(infoJan[numSelec]^.jan, SW_SHOWNORMAL);
            setActiveWindow (infoJan[numSelec]^.jan);
        end;

fim:
    for i := 1 to njan do
        dispose (infoJan [i]);

    repeat
        delay (1000);
    until getActiveWindow = crtWindow;
    writeln;
end;

end.
