Olá galera, nesta dica irei mostrar como pegar o título de uma janela aberta no Windows.

 

Vamos montar o exemplo:

1 Timer

1 ListBox

 



Criaremos agora uma function para poder pegar o caption de todas as janelas abertas.

 

function TFrmPrincipal.TituloAtivo: string;

var

Handle: THandle;

Len: LongInt;

Title: string;

begin

  Result := '';

  Handle := GetForegroundWindow;

if Handle <> 0 then

begin

Len := GetWindowTextLength(Handle) + 1;

SetLength(Title, Len);

GetWindowText(Handle, PChar(Title), Len);

Result := TrimRight(Title);

end;

end;

 

No Evento onTimer do Timer1

 

procedure TFrmPrincipal.Timer1Timer(Sender: TObject);

begin

  ListBox1.Items.Add(TituloAtivo);

end;

 

Fico por aqui ate à próxima Quick Tips.

 

Um abraço

 

Wesley Y

wyamazack@rwsolution.com.br