Solved

Getting the handle of the active control

Posted on 1998-11-23
8
699 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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