Possible Duplicates:
What is a Windows Handle?
What exactly is “handle” ?
I see references to window handles, controls which have a reference to a window handle, etc. But I don't know what a handle is.
I especially would like to know what it is, and any relevant details, as it pertains to .NET.
A handle is a reference for the operating system. It does not have the semantics of a programming reference but what it does do is allow the system resources to know what you are referring to when it is passed in an API call.
Usually, the HANDLE is wrapped in an instance of a class. CWnd is a good example, it contains an HWND which is a handle to a window.
You can do this. CWnd *pWnd = CWnd::FromHandle(hWnd) Note: that CWnd::FromHandle(hWnd) is static and does not require an instance.
It will pass you back the wrapper that the hWnd is wrapped by. Well not quite! If the handle is not actually wrapped by an object it will create one AND IT WILL ONLY BE TEMPORARY.So use it once then throw it away. It can create the instance because the hWnd has enough information in its struct for windows to instantiate a CWnd object. It does not add it to the handle v object table, so it is only temporary.
The HWND is in fact a kernel object and there's more?
I am not sure if all of these would pass back a temporary object if required. GetDC(hWnd) will get you a hDC from a hWnd but it will be temporary, probably better to use the CDC class.
Read more: http://wiki.answers.com/Q/What_is_a_handle_in_Windows_Programming#ixzz1JBmoF0lv