Solved

Getting the handle of the active control

Posted on 1998-11-23
8
694 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
 
LVL 27

Accepted Solution

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

will you give me the points?

meikl
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

23 Experts available now in Live!

Get 1:1 Help Now