How do I convert a handle acquired from a form/control's Handle property, to a IWin32Window^ ?
+2
A:
This appears to be exactly what you are asking for. I've never done it myself, but it appears to be relatively straightforward:
Creating a IWin32Window from a Win32 Handle
Good luck!
Morinar
2010-03-20 03:54:54
+3
A:
(That gets you the Control object, which implements the IWin32Window interface.)
Eg.
IntPtr myWindowHandle = new IntPtr(someVal);
IWin32Window w = Control.FromHandle(myWindowHandle);
Note that this relies on the handle being "acquired from a form/control's Handle property." You cannot use this technique with an arbitrary Win32 window handle.
James D
2010-03-20 03:59:34
James, I edited a qualification into your answer because people coming here from a more general search on `IntPtr` and `IWin32Window` might only read the question title and not appreciate the constraint in the question detail. Hope this is okay.
itowlson
2010-03-20 04:21:21
No, it's a good edit. You probably saved some hapless future programmer from hours of head-scratching wondering why he can't magically create a Control/IWin32Window object from a raw HWND. :)
James D
2010-03-20 07:54:28