feup
asked on
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?
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?
i have example of this unless you want to put one edey :-)
why I'd be happy too :)
In it's simplest form:
sendMessage(edit1.handle,W M_SETTEXT, 0,integer( pchar('Edi t Cleared!')));
will set the text of edit1 to 'Edit Cleared!', Hope this helps,
GL
Mike
In it's simplest form:
sendMessage(edit1.handle,W
will set the text of edit1 to 'Edit Cleared!', Hope this helps,
GL
Mike
ASKER
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
Any idea?
thanks
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('WordpadClas s',nil);
h:=FindWindowex(h,0,'RichE dit20A',ni l);
if h<>0 then SendMessage(h,wm_setText,0 ,Integer(w hat))
else showmessage('Error writing to notepad!');
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
WritetoWordpad('some text here');
end;
Regards Barry
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('WordpadClas
h:=FindWindowex(h,0,'RichE
if h<>0 then SendMessage(h,wm_setText,0
else showmessage('Error writing to notepad!');
end;
procedure TForm1.Button1Click(Sender
begin
WritetoWordpad('some text here');
end;
Regards Barry
Hmmm...
I am not sure what you're asking, could you, perhaps, give another go at explaining?
GL
Mike
I am not sure what you're asking, could you, perhaps, give another go at explaining?
GL
Mike
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 :-)
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 :-)
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
GL
Mike
ASKER
ok people, thanks for your comments. I'll try the examples, and then, I'll tell you something.
regards
regards
ASKER
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
- 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
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('WordpadClas s',nil);
h:=FindWindowex(h,0,'RichE dit20A',ni l);
h:=FindWindow('grandpa_cla ss',nil);
h:=FindWindow(h,0,'dad_cla ss',nil);
h:=FindWindowex(h,0,'RichE dit20A',ni l);
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_LBUTTONDO WN,0,0); sendmessage(h,WM_LBUTTONUP ,0,0);
Regards Barry
ie:
h:=FindWindow('WordpadClas
h:=FindWindowex(h,0,'RichE
h:=FindWindow('grandpa_cla
h:=FindWindow(h,0,'dad_cla
h:=FindWindowex(h,0,'RichE
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_LBUTTONDO
Regards Barry
ASKER
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
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
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.
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.
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','Fi nd')
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('CustomSearc hBox','Ent er 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('WordpadClas s',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,KEY EVENTF_KEY UP, 0);
keybd_Event(VK_CONTROL,0,K EYEVENTF_K EYUP, 0);
h := 0; //reset h;
repeat
h:=FindWindow('#32770','Fi nd')//wait for find window to appear
until h <> 0;
he:=FindWindowex(h,0,'Butt on','&Find Next'); //find button
hc:=FindWindowex(h,0,'Butt on','Cance l'); //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_LBUTTOND OWN,0,0);
sendmessage(he,WM_LBUTTONU P,0,0); //do the find and close dialog
sendmessage(hc,WM_LBUTTOND OWN,0,0);
sendmessage(hc,WM_LBUTTONU P,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
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','Fi
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('CustomSearc
if s = '' then
showmessage('no text') //ends proc if no text entered
else begin
h:=FindWindow('WordpadClas
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
keybd_Event(ord('F'),0,0,0
keybd_Event(ord('F'),0,KEY
keybd_Event(VK_CONTROL,0,K
h := 0; //reset h;
repeat
h:=FindWindow('#32770','Fi
until h <> 0;
he:=FindWindowex(h,0,'Butt
hc:=FindWindowex(h,0,'Butt
h:=FindWindowex(h,0,'Edit'
if h<>0 then SendMessage(h,wm_setText,0
else showmessage('Error sending text!');
sendmessage(he,WM_LBUTTOND
sendmessage(he,WM_LBUTTONU
sendmessage(hc,WM_LBUTTOND
sendmessage(hc,WM_LBUTTONU
end;
end;
procedure TForm1.Button1Click(Sender
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
ASKER
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
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
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','Sp edia - 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_HW NDNEXT);
if h2<>0 then SendMessage(h2,wm_setText, 0,Integer( s2))
else showmessage('Error writing password');
sendmessage(he,WM_LBUTTOND OWN,0,0);
sendmessage(he,WM_LBUTTONU P,0,0); //do the find and close dialog
sendmessage(he,WM_LBUTTOND OWN,0,0);
sendmessage(he,WM_LBUTTONU P,0,0);
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Speedia_Login;
end;
hope that what you needed
Regards Barry
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','Sp
he := FindWindowex(h,0,'Button',
h1:=FindWindowex(h,0,'Edit
if h1<>0 then SendMessage(h1,wm_setText,
else showmessage('Error writing username');
h2:=getnextWindow(h1,GW_HW
if h2<>0 then SendMessage(h2,wm_setText,
else showmessage('Error writing password');
sendmessage(he,WM_LBUTTOND
sendmessage(he,WM_LBUTTONU
sendmessage(he,WM_LBUTTOND
sendmessage(he,WM_LBUTTONU
end;
procedure TForm1.Button1Click(Sender
begin
Speedia_Login;
end;
hope that what you needed
Regards Barry
ASKER
Great. Thanks.
Could you please help me on a question you've answerd before, because I'm having a little problem?
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10248589
Make an answer on this one to give you the points.
Thanks
Could you please help me on a question you've answerd before, because I'm having a little problem?
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10248589
Make an answer on this one to give you the points.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Please, check the other question, because is very important.
regards
regards
GL
Mike