How can I check if a Win32 Window pointer is a valid .Net Control?
+2
A:
I'm going to assume that, by "Win32 Window pointer", you mean an hWnd.
You can call Control.FromChildHandle() supplying your hWnd as a parameter. If the hWnd is associated with a .NET Control, then you will receive, as a return value, a reference to the .NET Control representing the control. If the hWnd is not associated with a .NET Control, then you will receive, as a return value, a value of null.
Pseudocode is as follows:
Control AssociatedDotNetControl = Control.FromChildHandle(Win32WindowPointerAshWnd);
if(AssociatedDotNetControl != null)
{
// this is a .NET control
}
else
{
// this is not a .NET control
}
JeffFerguson
2009-09-02 13:44:17
short and smart!
Thomas Maierhofer
2009-09-02 15:10:40
Does this work if the hWnd is from another program?
Matthew Scharley
2009-09-03 00:49:03
Matt, I haven't tried that specifically, but I am guessing that it would indeed work.
JeffFerguson
2009-09-03 20:23:06