Solved

How to identify and control Control in other Windows?

Posted on 2004-08-01
10
174 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
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 259
ddeman not working in activex 3 103
Firemonkey android show image from resource ? 1 41
Delphi and Access based Enumeration 9 59
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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