Getting a Handle on Handles

Finally, there are three uppercase identifiers for various types of ”handles“:

Identifier Meaning

HANDLE Generic handle
HWND Handle to a window
HDC Handle to a device context

Handles are used quite frequently in Windows. Before the chapter is over, you also encounter HICON (a handle to an icon), HCURSOR (a handle to a mouse cursor), and HBRUSH (a handle to a graphics brush).

A handle is simply a 16-bit number that refers to an object. The handles in Windows are similar to file handles used in conventional C or MS-DOS programming. A program almost always obtains a handle by calling a Windows function. The program uses the handle in other Windows functions to refer to the object. The actual value of the handle is unimportant to your program, but the Windows module that gives your program the handle knows how to use it to reference the object.