Solved

Getting the handle of the active control

Posted on 1998-11-23
8
701 Views
Last Modified: 2010-08-05
Hi Experts

How do i get the handle of the active control (editbox) in the active app? (not a Delphi app)

What i want is this: If the user presses a certain key combination, my app shall select the text in the edit box and copy it to the clipboard.

What API call should i use? (A little piece of code would be nice)

Thanks in advance

Rene_Moeller

0
Comment
Question by:rene_moeller
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347703
hi rene_moeller,

see matveys comment at question:

http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10095005

meikl
0
 
LVL 1

Author Comment

by:rene_moeller
ID: 1347704
Thanks kretzschmar

it looks like thats what i was looking for.

Rene_Moeller
0
 
LVL 3

Expert Comment

by:williams2
ID: 1347705
Mon ikke det var en god idé at fjerne spørgsmålet fra din brugerprofil, hvis ikke der kan svares på det hr. Møller!?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 1347706
hi rene_moeller,

will you give me the points?

meikl
0
 
LVL 1

Author Comment

by:rene_moeller
ID: 1347707
Sorry Guys,
I've been busy, so I forgot all about this question.

You'll get the points kretzschmar.
Thanks for the reminder Williams.

Rene_Moeller
0
 
LVL 1

Author Comment

by:rene_moeller
ID: 1347708
Sorry Guys,
I've been busy, so I forgot all about this question.

You'll get the points kretzschmar.
Thanks for the reminder Williams.

Rene_Moeller
0
 

Expert Comment

by:mvsilva
ID: 4738644
I paid 5 points and I not be able to access http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10095005 !  Anybody can help me about this ? How can I get the handle of an active control in a non delphi app ?
Thank's.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 4738940
msilva,

pasted here matveys comments from the q above:

--- paste begin

Hi guys. I wrote these two, and they work quite well. They are on the same principle as the first sugestions:



                     function FindByIndex(ControlClass: String; ControlIndex: Integer; ParentW: THandle): THandle;
                     var ch1: THandle;
                         CurIndex: Integer;
                     begin
                       Result := 0;
                       CurIndex := 0;
                       ch1 := GetWindow(ParentW, GW_Child);
                       while not(ch1=0) do begin
                         if LowerCase(ClassName(ch1)) = LowerCase(ControlClass) then begin
                           inc(CurIndex);
                           if CurIndex=ControlIndex then begin
                             Result := ch1;
                             exit;
                           end;
                         end;
                         ch1 := GetNextWindow(ch1, GW_HWNDNEXT);
                       end;
                       ch1 := GetWindow(ParentW, GW_Child);
                       while not(ch1=0) do begin
                         if GetWindow(ch1, GW_Child)<>0 then Result := FindByIndex(ControlClass, ControlIndex - CurIndex, ch1);
                         if Result<>0 then exit
                         else ch1 := GetNextWindow(ch1, GW_HWNDNEXT);
                       end;
                     end;

                     function FindByCaption(ControlClass: String; Caption: String; ParentW: THandle): THandle;
                     var ch1: THandle;
                     begin
                       Result := 0;
                       ch1 := GetWindow(ParentW, GW_Child);
                       while not(ch1=0) do begin
                         if(LowerCase(ClassName(ch1))=LowerCase(ControlClass))and(LowerCase(ControlCaption(ch1))=LowerCase(Caption))
                     then begin
                             Result := ch1;
                             exit;
                         end;
                         ch1 := GetNextWindow(ch1, GW_HWNDNEXT);
                       end;
                       ch1 := GetWindow(ParentW, GW_Child);
                       while not(ch1=0) do begin
                         if GetWindow(ch1, GW_Child)<>0 then Result := FindByCaption(ControlClass, Caption, ch1);
                         if Result<>0 then exit
                         else ch1 := GetNextWindow(ch1, GW_HWNDNEXT);
                       end;
                     end;



                     The parameter names speak for themselvs: the window class, it's index or caption, and the parent window to search in.

                     Good luck!



                     Comment

                     From: Matvey
                                                   Date: Wednesday, November 04 1998 - 03:28PM CET

                     An example:

                     FindByCaption('button', '&OK', hWindow)
                     FindByIndex('edit', 3, hWindow)

                     -which find the OK button and the 3-d edit in the Z order.
                     NOTE: the functions search recursively, so you don't have to worry if the window is inside another window which is inside
                     another wind...


.... paste end

hope this helps you

meikl
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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