How do I use sendmessage?

Asked

Viewed 98 times

0

I’m getting the list of resource classes from another application but I can’t find Button, edits or Abels classes and I see that the application has these features.

This is my code:

procedure TForm1.Button1Click(Sender: TObject);
var
hWindow : THandle;
hChild : THandle;
aTemp : array[0..5000] of Char;
sClassName : String;
sCaption : String;
Result: string;
begin
  Result := '';
  sCaption := 'Nome do Programa';
  hWindow := FindWindow(Nil,PChar(sCaption));

  if hWindow = 0 then
  begin
     ShowMessage('Could NOT find the other program');
    exit;
  end;

  hChild := GetWindow(hWindow, GW_HWNDFIRST);
  while hChild <> 0 do
     Begin
     if GetClassName(hChild, aTemp, SizeOf(aTemp)) > 0 then
        begin

        sClassName := StrPAS(aTemp);
        Memo1.Lines.Add(sClassName);
        if sClassName = 'Label' then
           begin
           SendMessage(hChild,WM_GETTEXT,SizeOf(aTemp),Integer(@aTemp));
           Result := StrPAS(aTemp);
           Memo1.Lines.Add('     '+Result);
        end;
     end;
  hChild := GetWindow(hChild, GW_HWNDNEXT);
  end;
end;   

So I get something like :

tooltips_class32
ForegroundStaging
IME
ForegroundStaging
tooltips_class32

I can’t find anything about this on the Internet, like I do to get resources like:

lblCalculado
edtValor
btnComprar
btnVender

or


I have tested with GW_CHILD, GW_OWNER, GW_HWNDPRIOR/NEXT/FIRST/LAST and I cannot.

Thank you

  • Search by Findcomponent, with it you can have a list of all the components of the form and manipulate it as needed.

1 answer

0

Declare in Uses Enumwindowutil; and try this function:

function PegaHandlesFilhos(h: HWnd): string;
var 
wlistChilds     : TWindowList;
begin
    try
        wlistChilds := TWindowList.Create;
        wlistChilds.AddClassname := True;
        wlistChilds.EnumChildWindows(h);
        result := wlistChilds.Text;
    except
    end;
end;

//EXEMPLO
Memo1.text:= PegaHandlesFilhos(0); //Altere o 0 pelo handle principal

Browser other questions tagged

You are not signed in. Login or sign up in order to post.