Solved

Getting the handle of the active control

Posted on 1998-11-23
8
704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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