Reputation: 36649
How can I check if a Win32 Window pointer is a valid .Net Control?
Upvotes: 3
Views: 401
Reputation: 3002
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
}
Upvotes: 4