buenas , tengo este problema saque un codigo de aqui
[Enlace externo eliminado para invitados]

para obtener el handle
tambien use la funcion sedebug de seoane
pero en algunas ventanas abiertas me devuelve el valor 0
si alguien puede darme una mano se lo agradesco

Código: Seleccionar todo

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
// Ajustamos los privilegios   seoane
function EnablePrivilege(PrivilegeName: PChar; Enable: Boolean): Boolean;
var
  hToken: THandle;
  Tp: TOKEN_PRIVILEGES;
  Luid: TLargeInteger;
begin
  Result:= FALSE;
  if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or
    TOKEN_QUERY or TOKEN_READ, hToken) then
    if LookupPrivilegeValue(nil,PrivilegeName,Luid) then
    begin
      Tp.PrivilegeCount:= 1;
      Tp.Privileges[0].Luid:= Luid;
      if Enable then
        Tp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED
      else
        Tp.Privileges[0].Attributes:= 0;
      Result:= AdjustTokenPrivileges(hToken,FALSE,Tp,0,nil,PDWORD(nil)^);
      CloseHandle(hToken);
    end;
end;


// GET WINDOW HANDLE BY PROCESSID

function GetHWndByPID(const hPID: THandle): THandle;
    type
    PEnumInfo = ^TEnumInfo;
    TEnumInfo = record
    ProcessID: DWORD;
    HWND: THandle;
  end;

    function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
    var
        PID: DWORD;
    begin
        GetWindowThreadProcessID(Wnd, @PID);
        Result := (PID <> EI.ProcessID) or
                (not IsWindowVisible(WND)) or
                (not IsWindowEnabled(WND));

        if not Result then EI.HWND := WND; //break on return FALSE
    end;

    function FindMainWindow(PID: DWORD): DWORD;
    var
        EI: TEnumInfo;
    begin
        EI.ProcessID := PID;
        EI.HWND := 0;
        EnumWindows(@EnumWindowsProc, Integer(@EI));
        Result := EI.HWND;
    end;

begin
    if hPID<>0 then
        Result:=FindMainWindow(hPID)
    else
        Result:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if EnablePrivilege('SeDebugPrivilege', TRUE) then
    begin
    showmessage('ok');

edit2.text:=inttostr(GetHWndByPID(strtoint(edit1.text)));
end
else
begin
  showmessage('no ok');
  end;
 end;
end.
paresco malo ,pero soy bueno
sencillo y facil de comprender

[Enlace externo eliminado para invitados]

Código: Seleccionar todo

 function EnumProcess(hHwnd: HWND; lParam : integer): boolean; stdcall;
var
  pPid : DWORD;
  title, ClassName : string;
begin
  //if the returned value in null the 
  //callback has failed, so set to false and exit.
  if (hHwnd=NULL) then
  begin
    result := false;
  end
  else
  begin
    //additional functions to get more 
    //information about a process.
    //get the Process Identification number.
    GetWindowThreadProcessId(hHwnd,pPid);
    //set a memory area to receive 
    //the process class name
    SetLength(ClassName, 255);
    //get the class name and reset the 
    //memory area to the size of the name
    SetLength(ClassName,GetClassName(hHwnd,PChar(className),Length(className)));
    SetLength(title, 255);
    //get the process title; usually displayed 
    //on the top bar in visible process
    SetLength(title, GetWindowText(hHwnd, PChar(title), Length(title)));
    //Display the process information 
    //by adding it to a list box
Form1.ListBox1.Items.Add('Class Name = ' + className +
       '; Title = ' + title + 
       '; HWND = '+ IntToStr(hHwnd) +
       '; Pid = ' + IntToStr(pPid));
    Result := true;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//Clear any previous calls
if ListBox1.Count > 0 then
ListBox1.Clear;
//define the tag flag
lp := 0; //globally declared integer
//call the windows function with the address 
//of handling function and show an error message if it fails
if EnumWindows(@EnumProcess,lp) = false then
  ShowMessage('Error: Could not obtain process window hook from system.');

end;
paresco malo ,pero soy bueno
el primer ejemplo funciona bien no es necesario los privilegios
el problema es que solo muestra el handle de las ventanas activas
(si estan ocultas o minimizada no funciona)
pero ya encontre como hacerlo,
perdon por el soliloquio el tema ya esta resuelto .
paresco malo ,pero soy bueno
Responder

Volver a “Delphi”