User Objects

User interface objects support only one handle per object. Processes cannot inherit or duplicate handles to user objects. Processes in one session cannot reference a user handle in another session.

There is a theoretical limit of 65,536 user handles per session. However, the maximum number of user handles that can be opened per session is usually lower, since it is affected by available memory. There is also a default per-process limit of user handles. To change this limit, set the following registry value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota

This value can be set to a number between 200 and 18,000.

Handles to User Objects

Handles to user objects are public to all processes. That is, any process can use the user object handle, provided that the process has security access to the object.

In the following illustration, an application creates a window object. The CreateWindow function creates the window object and returns an object handle.

application creating a window object

After the window object has been created, the application can use the window handle to display or change the window. The handle remains valid until the window object is destroyed.

In the next illustration, the application destroys the window object. The DestroyWindow function removes the window object from memory, which invalidates the window handle.

destroying a window object

Managing User Objects

The following table lists the user objects, along with each object's creator and destroyer functions. The creator functions either create the object and an object handle or simply return the existing object handle. The destroyer functions remove the object from memory, which invalidates the object handle.

User object Creator function Destroyer function
Accelerator table CreateAcceleratorTable DestroyAcceleratorTable
Caret CreateCaret DestroyCaret
Cursor CreateCursor, LoadCursor, LoadImage DestroyCursor
DDE conversation DdeConnect, DdeConnectList DdeDisconnect, DdeDisconnectList
Hook SetWindowsHookEx UnhookWindowsHookEx
Icon CreateIconIndirect, LoadIcon, LoadImage DestroyIcon
Menu CreateMenu, CreatePopupMenu, LoadMenu, LoadMenuIndirect DestroyMenu
Window CreateWindow, CreateWindowEx, CreateDialogParam, CreateDialogIndirectParam, CreateMDIWindow DestroyWindow
Window position BeginDeferWindowPos EndDeferWindowPos