Bom, nesse tutorial, eu vo mostrar como utilizar o FindWindow() do windows,que serve para Encontrar as janelas que estao abertas no seu computador, e também a como pegar o Caption Name (nome da janela) e o Class Name de um programa.
1° Como funciona o FindWindow?
Simples, ele sempre eh dessa forma:
''Well, in this tutorial, I show how to use the vo FindWindow () windows, which serves to find who are the windows open on your computer, and also how to get the Caption Name (name of the window) and the Class Name of a program.
1 ° How does FindWindow?
Simple, eh it always that way:''
Mas assim ele não serve pra nada, pois os dois parametros dele estão nil :/
o 1° Nil, pode ser substituido pela Class Name e o 2° Nil pode ser substituido pelo Caption.
''But so it is for nothing, because the two parameters are nil it :/
1 ° Nil, can be replaced by Class Name and 2 ° Nil can be replaced by Caption.''
FindWindow('WMplayerapp', nil) // Class Name do Windows Media Player.
FindWindow(nil,'Windows Media Player'); // Caption do windows Media Player.
Mas usando assim, ele tbm nao serve pra nada ¬¬
Um exemplo de uso.
''But using so it does not serve for anything tbm ¬ ¬
An example usage.''
ClassName:
if FindWindow('WMplayerapp', nil) then
Label1.Caption:= 'Windows Media Player Encontrado.' ;
Caption:
if FindWindow(nil,'
Windows Media Player'); then
Label1.Caption:= '
Windows Media Player Encontrado.' ;
Mas qual a diferença entre utilizar a ClassName e a CaptionBar ?
Simples, alguem poderia usar SetWindowsText , para modificar a CaptionBar, de algum programa, e voce tera de usar o ClassName...Mas porem usar o captionbar sempre é mais prático, porque é só olhar o nome na barra do programa
°Mas então como eu pego o ClassName de alguma aplicação?
Abra seu delphi, e declare em Private :
''But what's the difference between using the ClassName and CaptionBar?
Simple, someone could use SetWindowsText to modify CaptionBar in any program, and you will have to use the ClassName ... But however captionbar always use the most practical, because just look at the name on the bar of the program
° But then how do I get the ClassName in any application?
Open your Delphi, and declare in Private:''
private
procedure ShowHwndAndClassName(CrPos: TPoint);
Depois Adicione um timer,com um interval de 50 Milisegundos, e declare:
''Then Add a timer with an interval of 50 Milliseconds, and state ::''
Spoiler
procedure TForm1.Timer1Timer(Sender: TObject);
var
rPos: TPoint;
begin
if Boolean(GetCursorPos(rPos)) then ShowHwndAndClassName(rPos);
end;
E logo abaxo do timer, declare a seguinte Procedure:
''And then underneath: timer, declare the following Procedure:''
Spoiler
procedure TForm1.ShowHwndAndClassName(CrPos: TPoint);
var
hWnd: THandle;
aName: array [0..255] of Char;
begin
hWnd := WindowFromPoint(CrPos);
if Boolean(GetClassName(hWnd, aName, 256)) then
Label2.Caption := 'ClassName da janela é : ' + string(aName)
else
Label2.Caption := 'ClassName : Não Encontrada';
end;
Assim , o timer vai ficar procurando as janelas em que seu mouse esta em cima e mostrando no label, o ClassName da janela.
°E como eu pego o Caption?
''Thus, the timer will be looking in the windows that your mouse is over and showing the label, the classname of the window.
° And as I get the Caption?''
''Pode parece uma pergunta besta,porque voce vai dize, há é só olha pra janelinha de cima do programa.Mas e se tive um caracter especial? Um que voce nao saiba fazer?
Eu jah cai nisso, precisava do caption de um jogo, e o nome da janela era uns 10921029102 caracters especiais --''
Bom, primeiro declare em Var :
''Well, first declare in Var:''
sJanelaAtiva,sJanelaOld : string;
Depois declare a seguinte Function:
''Then declare the following Function:''
Spoiler
function JanelaAtiva: String;
var
Handle:THandle;
Len:LongInt;
Title: String;
begin
Handle:=GetForegroundWindow;
Len:=GetWindowTextLength(Handle) + 1;
SetLength(Title,Len);
GetWindowText(Handle,PChar(Title),Len);
JanelaAtiva:=TrimRight(Title);
end;
E depois declare em um timer o seguinte code, com um interval , de 50~100 ;
''And then declare a timer in the following code with an interval of 50 ~ 100;''
Spoiler
procedure TForm1.Timer1Timer(Sender: TObject);
begin
sJanelaOld:=sJanelaAtiva;
sJanelaAtiva := JanelaAtiva;
if sJanelaAtiva <> sJanelaOld then
Edit1.Text:=JanelaAtiva;
end;