Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET .NET4 form
Hi
 
I am working on a project in which I am trying to get the handle of a control in another application. However I don't understand too well the System.Windows.Forms.Control.FromChildHandle(handle) function. What I'm doing is getting the handle of the main form and want to get all the childhandles into controls.
 
I have been looking online for examples but haven't found any and the msdn doesn't provide examples.
 
My code actually compiles, but the System.Windows.Forms.Control.FromChildHandle function does not return a control.
 
thank you
Posted 25-Aug-11 11:33am
Edited 25-Aug-11 11:35am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Control.FromChildHandle Method - MSDN entry[^]
According to the documentation Control.FromChildHandle walks up the parent chain and returns the control with the given handle, null if not found.
 
I am trying to get the handle of a control in another application
you have to look into
EnumWindows[^]
FindWindow[^]
FindWindowEx[^]
Or
UIAutomation[^]
 
In short you won't be able to get a Form and any kind of Control object which represents a form/control in another application. Thus Control.FromChildHandle returns null when you give it a handle that doesn't belong to the current application.
  Permalink  
Comments
nanomass at 25-Aug-11 16:55pm
   
I used FindWindow() to get the handle of the other application, I tried to use FindWindowEx() but the tabcontrol doesn't have caption, therefore it only works if the tabcontrol is the only control in the other application. is there any way to convert handles from another Window Form (aka application) into control objects?
SAKryukov at 25-Aug-11 19:35pm
   
My 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 25 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100