How to identify and control Control in other Windows?

Posted on 2004-08-01
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.
Question by:kittichai
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 12

Expert Comment

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.
LVL 12

Expert Comment

ID: 11691344

Author Comment

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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 12

Expert Comment

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

Expert Comment

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

Author Comment

ID: 11712234
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?
LVL 34

Accepted Solution

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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