Solved

Getting the handle of the active control

Posted on 1998-11-23
8
697 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

24 Experts available now in Live!

Get 1:1 Help Now