Hola ecfisa.
Muy bien para localizar los controles, estaria bien obtener sus nombres ademas del THandle.
Pero...no me va el leer texto con TfrBusca.btnAppToREClick(Sender: TObject);
Código Delphi
[-]
repeat
R:= GetClassName(TClassNfo(Items.Objects[ItemIndex]).Handle,
Buffer, SizeOf(Buffer));
SendMessage(TClassNfo(Items.Objects[ItemIndex]).Handle,
WM_GETTEXT, SizeOf(Buffer), Integer(@Buffer));
RichEdit1.Text:= Buffer;
until (Buffer = Items[ItemIndex])or(R <> 0);
R siempre devuelve 0 (cero) y se queda en el repeat; tambien pasa en la funcion TfrBusca.btnREToAppClick(Sender: TObject);
Lo he hecho de otra forma (mas simple) y me mete en un listbox, la aplicacion(proceso), sus formularios y sus respectivos controles
Añadir un listbox y un richedit
Código Delphi
[-]
procedure ListWinInfoFromPId(PId: longword; strings: TStrings);
type
TWinParam = record
PId: longword;
S: TStrings;
end;
PWinParam = ^TWinParam;
var
WinParam: TWinParam;
function CallbackFn(handle: Thandle; strings: TStrings): longbool; stdcall;
var
buffer: array[0..255] of char;
begin
Result := True;
if GetClassName(handle, buffer, 256) <> 0 then
strings.Add(IntToStr(handle) + ' ' + buffer);
end;
function EnumWindowsProc(handle: Thandle; lPar: LPARAM): boolean; stdcall;
var
PId: longword;
buffer: array [0..255] of char;
begin
Result := True;
PId := 0;
GetWindowThreadProcessId(handle, PId);
if PWinParam(lPar).PId = PId then
begin
PWinParam(lPar).S.Add('hWnd: ' + IntToHex(handle, 8) + 'h');
GetWindowText(handle, @buffer, 255);
PWinParam(lPar).S.Add('Caption: ' + buffer);
GetClassName(handle, @buffer, 255);
PWinParam(lPar).S.Add('Clase: ' + buffer);
EnumChildWindows(handle, @CallbackFn, LPARAM(PWinParam(lPar).S));
PWinParam(lPar).S.Add(StringOfChar('-', 40));
end;
end;
begin
WinParam.PId := PId;
WinParam.S := strings;
EnumWindows(@EnumWindowsProc, LPARAM(@WinParam));
end;
function EnumWinProc(handle: Thandle; param: pointer): boolean; stdcall; export;
var
nombre: array[0..255] of char;
PId: longword;
begin
Result := True;
GetWindowText(handle, nombre, 255);
if (nombre <> '')
and (IsWindowVisible(handle))
and (GetWindow(handle, gw_Owner) = 0)
then
begin
GetWindowThreadProcessId(handle, PId);
FormMain.ListBox1.Items.Add(IntToStr(PId) + ' ' + nombre);
FormMain.ListBox1.Items.Add(StringOfChar('-', 80));
ListWinInfoFromPId(PId, FormMain.ListBox1.Items);
end;
end;
y apara usarlo
Código Delphi
[-]
procedure TFormMain.Create(Sender: TObject);
EnumWindows(@EnumWinProc, LongInt(Self));
end;
procedure TFormMain.ListBox1Click(Sender: TObject);
var
buffer: array[0..8192] of Char;
p: integer;
handle: HWND;
s: string;
begin
s := ListBox1.Items[ListBox1.ItemIndex];
p := Pos(' ' , s);
s := Copy(s, 1, p - 1);
handle := StrToIntDef(s, 0);
if handle = 0 then
Exit;
SendMessage(handle, WM_GETTEXT, SizeOf(Buffer), Integer(@Buffer));
RichEdit1.Text := Buffer; end;
Teniendo el handle del control ¿Como podemos obtener su clase, Tedit, Tcombox, etc, si no me funciona GetClassName? Uso Delphi 2010 y windows 7 64.
¿Se te ocurre algo?
Gracias
Edito: Lo mejor seria obtener el objeto ¿Se puede? asi seria mas facil, se podria usar richedit1.text := Trichedit(TObject).Text