change component text

How can I change a component text?

For example, I have the search window from wordpad, and, from my application, I want to write there "test".

I can find the handler using a script tool named "FLUTE" (http://www.wtitle.demon.co.uk/flute.htm), but I couldn't do that in delphi.


Any suggestion?
feupAsked:
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.

edeyCommented:
If you know how to get the handle, then look up the WM_SETTEXT message

GL
Mike
0
intheCommented:
i have example of this unless you want to put one edey :-)
0
edeyCommented:
why I'd be happy too :)
In it's simplest form:

sendMessage(edit1.handle,WM_SETTEXT,0,integer(pchar('Edit Cleared!')));

will set the text of edit1 to 'Edit Cleared!', Hope this helps,

GL
Mike
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

feupAuthor Commented:
Thanks everyone, but I know the handler in my computer, but if I restart, I have to change it again, and that's not good.

Any idea?


thanks
0
intheCommented:
you are not using correct handle for this type of operation.you must use the windows class name using findwindow() and findwindowex() functions.

WordpadClass is the classname of  wordpads mainwindow,and RichEdit20A is the classname of the edit that holds wordpads text.so you should be doing  like open a instance of wordpad then do this:

Procedure WriteToWordpad(what:string);
var h:hwnd;
begin
h:=FindWindow('WordpadClass',nil);
h:=FindWindowex(h,0,'RichEdit20A',nil);
if h<>0 then SendMessage(h,wm_setText,0,Integer(what))
        else showmessage('Error writing to notepad!');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
WritetoWordpad('some text here');
end;

Regards Barry
0
edeyCommented:
Hmmm...
I am not sure what you're asking, could you, perhaps, give another go at explaining?


GL
Mike
0
intheCommented:
hi edey,
ya know if you use the apps handle (ie some numeral handle like 234233) this is just the handle windows assigns a control but it changes everytime the program or windows is re-started so tat is why to use classnames instead of window handles..
did that make sense :-)
0
edeyCommented:
sorry ~ the inthe, my previous comment was directed towards feup's last comment, I just wasn't fast enough :).  Though, given your comment, I guess fuep didn't have a good way of finding the handle, so your comment is very appropriate.

GL
Mike
0
feupAuthor Commented:
ok people, thanks for your comments. I'll try the examples, and then, I'll tell you something.


regards
0
feupAuthor Commented:
OK. That worked, but there are some problems :

- Some applications have their controls with the same name : Edit; Edit; Static; etc.. they are not numbered. How can I distinguish them?

- What abou if I have 2 windows of wordpad oppened. How can I choose between them?

- This is a little diffrent from my question, but I need it too (How can I click their button?)


Thanks
0
intheCommented:
the apps may have controls with same name but the order to get to them will be different because the parent(first) call is never going to be same.

ie:
h:=FindWindow('WordpadClass',nil);
h:=FindWindowex(h,0,'RichEdit20A',nil);

h:=FindWindow('grandpa_class',nil);
h:=FindWindow(h,0,'dad_class',nil);  
h:=FindWindowex(h,0,'RichEdit20A',nil);

if there are two windows open it will pick first window it finds which will be top one in z-order(the last one that had focus ).

to click a button find the window(class name as before)of it using findwindow/findwindowex then send  :

sendmessage(h,WM_LBUTTONDOWN,0,0);     sendmessage(h,WM_LBUTTONUP,0,0);

Regards Barry
0
feupAuthor Commented:
Thanks barry, but I couldn't understand.

Imagine I have a window with the classname 'WINDOW', and two edit boxes in a row : 'edit' and 'edit'.

How can I write 'Hello' in the first one and 'World' in the second.


By the way : I've found out that a program I'm now using to detect the classes of the components, and it shows the index, but not for all the components. Does it help?


regards
0
intheCommented:
what is the name of the program you are using to find classnames?and what is the program with two classes named "edit"
do you have Winsight?(comes with professional and c/s versions of delphi)
another one i like to use for program info is called sinfo.
http://212.187.198.142/software/free/utilities/win95/sw42.html

i never came accross a situation where there would be 2 class names the same on same control(usually always slightly different parent etc)and wondered if you were getting correct information.
i will make an example to put text into wordpads find edit and press find button.
back later.
0
intheCommented:
note using the findwindow fiunctions you can also passthe window caption.
the find dialog in wordpad for instance has a classname of #32770 and a window caprion of "find" ,so we can call:
h:=FindWindow('#32770','Find')
or leave one of the parameters as 0;
here is an example ,start wordpad with a document then call this:

Procedure Find_in_Wordpad;
var
 h,he,hc:hwnd;
   s : string;
  b : boolean;
 begin
b:=InputQuery('CustomSearchBox','Enter a word to search for...', s); //get a search feild
if s = '' then
 showmessage('no text')   //ends proc if no text entered
 else begin
h:=FindWindow('WordpadClass',nil); //find wordpad instance
if h <> 0 then
setforegroundwindow(h)   //bring wordpad to fromt so we can use keybd_Event()
else showmessage('run wordpad');
SetFocus(h);
keybd_Event(VK_CONTROL,0,0,0);  //ctrl - f is the find dialogs shortcut
keybd_Event(ord('F'),0,0,0);
keybd_Event(ord('F'),0,KEYEVENTF_KEYUP, 0);
keybd_Event(VK_CONTROL,0,KEYEVENTF_KEYUP, 0);
h := 0; //reset h;
repeat
h:=FindWindow('#32770','Find')//wait for find window to appear
until h <> 0;
he:=FindWindowex(h,0,'Button','&Find Next'); //find button
hc:=FindWindowex(h,0,'Button','Cancel');    //cancel button
h:=FindWindowex(h,0,'Edit',nil);           //text feild
if h<>0 then SendMessage(h,wm_setText,0,Integer(s))
        else showmessage('Error sending text!');
sendmessage(he,WM_LBUTTONDOWN,0,0);
sendmessage(he,WM_LBUTTONUP,0,0);     //do the find and close dialog
sendmessage(hc,WM_LBUTTONDOWN,0,0);
sendmessage(hc,WM_LBUTTONUP,0,0);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Find_in_Wordpad;
end;

if you have a specific program that you are trying to do this stuff in let me know i may have it too and be able to help more.
Regards Barry
0
feupAuthor Commented:
Hi!

The application I'm trying to use is "SPY" from Wintask ... www.wintask.com

and the application that hat the two edit boxes class named "edit" is "Spedia" ... www.spedia.net


I wish to make an automated way to make the login.


Thanks

Note : In your example, the find dialog has only one edit box, so it doesn't solve my problem
0
intheCommented:
hi,
ok got it ,we have to first use findwindow() to get first "edit" then use getnextwindow() to get the second(password edit),here is tested example:


Procedure Speedia_Login;
var
 h,h1,h2,he:hwnd;
s1,s2:string;
begin
s1 := 'username';
s2 := 'somepassword';
h:=FindWindow('#32770','Spedia - Authentication');
he := FindWindowex(h,0,'Button','&Login');
h1:=FindWindowex(h,0,'Edit',nil);
if h1<>0 then SendMessage(h1,wm_setText,0,Integer(s1))
        else showmessage('Error writing username');
h2:=getnextWindow(h1,GW_HWNDNEXT);
if h2<>0 then SendMessage(h2,wm_setText,0,Integer(s2))
        else showmessage('Error writing password');
sendmessage(he,WM_LBUTTONDOWN,0,0);
sendmessage(he,WM_LBUTTONUP,0,0);     //do the find and close dialog
sendmessage(he,WM_LBUTTONDOWN,0,0);
sendmessage(he,WM_LBUTTONUP,0,0);
 end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Speedia_Login;
end;


hope that what you needed
Regards Barry
0
feupAuthor Commented:
Great. Thanks.

Could you please help me on a question you've answerd before, because I'm having a little problem?

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10248589 

Make an answer on this one to give you the points.


Thanks
0
intheCommented:
ok cheers
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
feupAuthor Commented:
Please, check the other question, because is very important.


regards
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.