SETTEXT, GETTEXT Question.

Hey,

Buffer : array[0..100] of Char;
SendMessage(hwndxyz, WM_GETTEXT, 100, integer(@Buffer));

hwndxyz is a textbox.
Buffer will now be the first 100 chars of that texbox.

Question 1: I need a way to get all the text from the textbox, and not just 100 chars.
Question 2: How do you get the last 100 chars from a textbox?
Question 3: How do you get the length of the textbox text.

Thnx!
TonyJizAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hi,

Use this:

function ReadFromWindowText(h:HWND) : string;
var
 buf : string;
 len : integer;
begin
 try
   len := SendMessage(h,wm_getTextLength,0,0);
   SetLength(buf,len);
   SendMessage(h,wm_getText,len+1,Integer(buf));
   result := buf;
 except
   result := '';
 end;
end;

// usage:
var s: string;
begin
  // all the text
  s := ReadFromWindowText(hwndxyz);
  // last 100 chars
  s := Copy(s, Length(s) - 100, Length(s));
end;

Regards, Geo
0
TonyJizAuthor Commented:
Hey, then do also know why this won't do:

var xyz: string;
SendMessage(hwndxyz, WM_SETTEXT, length(xyz), integer(xyz));

If I don't set xyz as a string, but instead: xyz = array[0..100] of Char;
then it will do, but I dont know how long xyz is going to be and it could be way more than 100 chars so I want to use a string instead. There's probably another solution, do you know this, I will give you the points then.

I thought that with the previous question this would also be solved.

Thnx!
0
geobulCommented:
SendMessage(hwndxyz, WM_SETTEXT, 0, integer(xyz));
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

TonyJizAuthor Commented:
Hey let me rephrase that.

The following lines don't do the job (xyz returns '')

var
i: Integer;
xyz: string;
begin
i := SendMessage(hwndxyz,wm_getTextLength,0,0);
SetLength(xyz,i);
SendMessage(hwndxyz,WM_GETTEXT,i,Integer(xyz));

The following lines do the job:

var
Buffer : array[0..255] of Char;
begin
SendMessage(hwndedit2,WM_GETTEXT,255,Integer(@buffer));
xyz := Buffer;

But the problem with the last one is the maxiumum of 255 chars.

Any ideas?
Thnx!
0
geobulCommented:
>SendMessage(hwndxyz,WM_GETTEXT,i,Integer(xyz));
should be
SendMessage(hwndxyz,WM_GETTEXT,i+1,Integer(xyz));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geobulCommented:
Why don't you simply use the function above?
0
geobulCommented:
BTW your code works fine here:

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  xyz: string;
begin
  i := SendMessage(Memo1.Handle,wm_getTextLength,0,0);
  SetLength(xyz,i);
  SendMessage(Memo1.Handle,WM_GETTEXT,i+1,Integer(xyz));
  Memo2.Lines.Text := xyz;
end;

Memo1 contains more than 5000 chars.
0
TonyJizAuthor Commented:
Yup indeed. Thnx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.