Solved

How to identify and control Control in other Windows?

Posted on 2004-08-01
10
170 Views
Last Modified: 2010-04-05
My problem is, I have to write a program, using Delphi, that can automatically fill-in the form on other application, that application that I'm not the one who wrote. I have clarify the step like this:

1. I have to be able to identify the active form, to ensure that I fill-in the data on the right form. It's simple to get application's title, but how can i know which form is active? I can now get the handle & class of activeform, but handle may not be the same everytime and class may be duplicate. Is there any suggestion? If you can answer the other 2 questions, it might help solving this one as well. I get an idea that if I can get the list of all control in the form, I may be able to compare the list of all control to identify the form.

2. I have to be able to identify all controls in other windows. So, I can select the right control to fill-in data. I can get the active Control's handle & class, but there's no way I can distinguish 2 controls of the same classes (for example, if there're 2 editbox on the form, I don't know which is which.)
3. I have to be able to send data to that particular control. (I think SendKeys can be used, but first, i have to be able to setfocus on that specific control. Is there any more reliable way to setfocus on control rather than generate Mouseclick event? on specific spot?)

Sorry that my question seems to have sub-question, but I can't distinguish them otherwise you may not understand the whole picture.
0
Comment
Question by:kittichai
  • 3
  • 2
  • 2
10 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11691338
download a program called Greatis WinDowse. Run the other application that was not written by you and point with the cursor on the Edit (for e.g.) you want to change. With WinDowse use see the name of the control, it's class and parents etc.

Then using FindWindow and FindWindowEx you can find the control and using WM_CHAR sent the data you want to write inside.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11691344
0
 

Author Comment

by:kittichai
ID: 11695243
Ivanov_G, my problem is, I have to create the same program as Greatis WinDowse. I have to create the designer that user can design the form filling on any application. I don't want a tool, I want code. My program should do what Greatis Windowse do transparently from the user.

Thank you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11701030
sorry, I didn't understood what exactly you need. I can not help with code that will be helpful for you.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 11712154
hello  kittichai , ,  you ask
"if there're 2 editbox on the form, I don't know which is which?"
if you have the Handle of a windows control, and want to furthur distingish it from another control of the same class (like EDIT), , I would do in one of two ways, I think that you can get the location of the control with GetWindowRect(HandleOfControl,  ARect);, , so get the location of both edits and then pick the one below the other ot to the left of the other, for the most part  controls in most apps stay in the same relative position, even during resizing, another  way would be to get the text in the control with   GetWindowText( ) and then choose the control from that, but that may be unreliable for an EDIT control,
and some controls have an ID number, which may could help you
0
 

Author Comment

by:kittichai
ID: 11712234
Slick812,
I want the way to identify and distinguish eash contol. The rectangle you suggest is already one of my solution, but it is too unreliable since many windows application may adjust its position when the form resizing. (i.e. any form with splitter may change the position oftenly) It's too unreliable, also the same for your GetWindowText. Isn't any other way to uniquely distinguish & recognize each control?
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 11719620
if you are out side of that application running process (as you describe) then you can get the stadard  API functions Information for a control windows Handle, and some of these you have already used. . But the process that is useing those controls will just use the Creation returned  HANDLE  for that control to "Identify" it, so many times there is NO OTHER identifier set up for that control, since that program's code does not need any furthur way than the Handle to use and change that control. As I have mentiond before, , some programmers (like me) will give all of their control a number control ID, since thare id a number used for the windows ID (if control) in all of the creation functions (this programming is outside of the Delphi VCL, which does not include any way to set the ID of a control)

you can use the   GetWindowLong( ) functio to get an ID number from a window that has one. .

. . . something else. .  I believe that the findwindowEX will cycle through the controls in the order that they were created in that window, so I would guess that you can just get the "Order" of the controls handle in the FindWindowEx search, in other words, the first edit in that search will always be the same edit, and the second edit in that search will be the same edit control, for any search that is done, but I could be wrong in how I remember that asspect of this for FindWindowEX
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now