Link to home
Start Free TrialLog in
Avatar of jeurk
jeurk

asked on

[D3 winAPI] Get the text from another's app memo

Hello,
I'd like to read the contain of the memo
that is in another app.
Using windows messages.
I already have the handle of that
memo.

Let's say I have a memo. Help me read
another memo and fill mine with it's
text.

I tryed
  var
     p:TPoint;
     WinHandle: THandle;
     Buffer: array[0..50] of Char;
begin
     ReleaseCapture;
     GetCursorPos(p);
     WinHandle:=WindowFromPoint(p);
     GetClassName(WinHandle, Buffer, SizeOf(Buffer) - 1);
     edit1.Text:=Buffer;
     GetWindowText(WinHandle, Buffer, SizeOf(Buffer) - 1);
     edit2.Text:=Buffer;

but getwindowtext cannot get the text of another app.
Thanks to submit working code please. Thanks.
Avatar of Madshi
Madshi

Hi John!!   :-)

This should work:

var i1 : integer;
    s1 : string;
begin
  i1 := SendMessage(WinHandle, WM_GETTEXTLENGTH, 0, 0);
  SetLength(s1, i1 + 1);
  SetLength(s1, SendMessage(WinHandle, WM_GETTEXT, i1 + 1, integer(s1)));
  memo1.text := s1;

Regards, Madshi.
Avatar of jeurk

ASKER

this is working perfectly.
but I do not understand what the
line SetLength(s1, SendMessage(WinHandle, WM_GETTEXT, i1 + 1, integer(s1)));
does and how it is working.
does not setlenght change the size of the given string ?
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeurk

ASKER

Hello,
thanks for your help.
and for the crystal clear comments.

About memo1.text := Window(WinHandle).Text;

are your doing more then GetWindowText(WinHandle, Buffer, SizeOf(Buffer) - 1);
?
I hope so. Anyway I'm gonna like your stuff life always.

CU
I don't use GetWindowText, because it doesn't work alright. In my stuff I'm doing exactly what I've posted here (in fact the code I've posted here is just a slightly changed copy from my stuff)...   :-)
Avatar of jeurk

ASKER

Anyway I believe you.
Look I have another question
(just give me five minutes to type it;)