[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

change component text

Posted on 1999-12-21
19
Medium Priority
?
267 Views
Last Modified: 2010-04-06
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?
0
Comment
Question by:feup
  • 8
  • 7
  • 4
19 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2299584
If you know how to get the handle, then look up the WM_SETTEXT message

GL
Mike
0
 
LVL 17

Expert Comment

by:inthe
ID: 2299608
i have example of this unless you want to put one edey :-)
0
 
LVL 6

Expert Comment

by:edey
ID: 2300716
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

Author Comment

by:feup
ID: 2301399
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
 
LVL 17

Expert Comment

by:inthe
ID: 2301454
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
 
LVL 6

Expert Comment

by:edey
ID: 2301456
Hmmm...
I am not sure what you're asking, could you, perhaps, give another go at explaining?


GL
Mike
0
 
LVL 17

Expert Comment

by:inthe
ID: 2301477
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
 
LVL 6

Expert Comment

by:edey
ID: 2301563
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
 

Author Comment

by:feup
ID: 2301579
ok people, thanks for your comments. I'll try the examples, and then, I'll tell you something.


regards
0
 

Author Comment

by:feup
ID: 2304616
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
 
LVL 17

Expert Comment

by:inthe
ID: 2305192
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
 

Author Comment

by:feup
ID: 2305290
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
 
LVL 17

Expert Comment

by:inthe
ID: 2305349
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
 
LVL 17

Expert Comment

by:inthe
ID: 2305481
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
 

Author Comment

by:feup
ID: 2305504
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
 
LVL 17

Expert Comment

by:inthe
ID: 2305566
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
 

Author Comment

by:feup
ID: 2305646
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
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2306058
ok cheers
0
 

Author Comment

by:feup
ID: 2306081
Please, check the other question, because is very important.


regards
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question