sexta-feira, 17 de fevereiro de 2017

DELPHI - Pegar Handle de uma janela através do nome do executável - Catch Handle from a window via executable name

Para esse resultado, utilize as duas função publicado aqui no blog. Seguem elas:



Função 1 Função 2

DELPHI - Pegar Handle através do PID do executável - Catch Handle through the PID of the executable

Essa função retorna o Handle de uma janela, passando o PID do executável como parametro.



function GetHWNDFromPID(const PID: Cardinal): HWND;
var
  MHandle: HWND;
  MProcPID: Cardinal; 
begin
  Result := 0;
  MHandle := GetTopWindow( 0 );

  while Boolean( MHandle ) do
  begin
    { ** O retorno do método não é necessário. Apenas o seu Handle ** }
    GetWindowThreadProcessId( MHandle, MProcPid );

    if MProcPid = PID then
    begin
      Result := MHandle;
      Break;
    end;
    { ** Recuperando a próxima janela ** }
    MHandle := GetNextWindow( MHandle, GW_HWNDNEXT );
  end;
end;


Retirado do ActiveDelphi

DELPHI - Pegar PID através do nome do executável - Catch PID via executable name

DELPHI - Pegar PID através do nome do executável - Catch PID via executable name

Essa função retorna o PID do executável, passando o nome do mesmo como parametro.



Add Uses TlHelp32

function GetPIDExecutavel(const ANomeExe: String):Cardinal;
var
  MContinueLoop: BOOL;
  MHandle: THandle;
  MProcList: TProcessEntry32;
  MLocated: Boolean;
begin
  Result := 0;

  MHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  MProcList.dwSize := SizeOf(MProcList);
  MContinueLoop := Process32First(MHandle, MProcList);

  while Integer(MContinueLoop) <> 0 do
  begin
    MLocated := ((UpperCase(ExtractFileName(MProcList.szExeFile)) =
      UpperCase(ANomeExe)) or (UpperCase(MProcList.szExeFile) = UpperCase(ANomeExe)));

    if MLocated then
    begin
      Result := MProcList.th32ProcessID;
      Break;
    end;
    MContinueLoop := Process32Next( MHandle, MProcList );
  end;
  CloseHandle(MHandle);
end;


Retirado do ActiveDelphi

terça-feira, 7 de fevereiro de 2017

DELPHI - Download Delphi and C++Builder 10.1 Berlin ISO (includes Update 2)

Site oficial: http://cc.embarcadero.com/item/30652
ID: 30652, Delphi and C++Builder 10.1 Berlin ISO (includes Update 2)
v24.2
Size=7,340,716,032 bytes
MD5: 920F0ACF67122BB04ED55EDD7A1C7579

Download Aqui

DELPHI - Pegar título da janela ativa no Windows - Take title from active window without Windows

Segue abaixo uma função que retornar o título da janela ativa.



function GetTituloAtivo: 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;