Solved

How to identify and control Control in other Windows?

Posted on 2004-08-01
10
169 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:kittichai
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

6 Experts available now in Live!

Get 1:1 Help Now