| Previous | Next |
| ERROR_HWNDS_HAVE_DIFF_PARENT | ERROR_INVALID_GW_COMMAND |
ERROR_NOT_CHILD_WINDOW
The required parent-child relationship is not present.
ERROR_NOT_CHILD_WINDOW is Win32 error 1442 (0x5A2). USER32 returns it when an operation is defined for a child window and the supplied HWND is top-level, belongs to another parent, or no longer exists in the hierarchy the caller assumes. Ownership of a top-level window is not the same relationship as parentage of a WS_CHILD window.
Typical causes
- passing an owned dialog or popup where an API requires a child control
- using the wrong container handle after a tab, docking, or MDI transition
- calling child-coordinate or child-enumeration logic with a top-level window
- retaining a control handle after the control was destroyed and recreated
- checking
GetWindowownership and treating it as proof thatIsChildwill succeed
What to record
Capture the API name, candidate child handle, expected parent handle, window classes, styles, owning threads, and the results of GetParent and IsChild at the moment of failure. Also record the creation and destruction sequence for dynamically rebuilt controls. The relationship can change between an earlier validation and the failing call.
How to diagnose it
Verify first that both handles identify live windows. Then call IsChild(expectedParent, candidate); it recognizes descendants, not merely direct children. If the API requires a direct child, compare GetParent(candidate) with the expected parent as well. Inspect the WS_CHILD style and distinguish an owner set for a popup from a parent set for a child.
Pay attention to cross-thread UI designs. A valid child can be recreated by its owner thread while a worker still holds the old handle. Move hierarchy-sensitive work to the UI thread or use a generation token so queued operations are rejected after reconstruction.
Recovery and prevention
Reacquire the control from its current container, route the request to the actual parent, or redesign the operation for a top-level window. Do not repair the problem by blindly calling SetParent; reparenting changes coordinate systems, clipping, focus navigation, DPI behavior, and sometimes thread-input relationships.
Related values
ERROR_INVALID_WINDOW_HANDLE means the handle itself is invalid. ERROR_HWNDS_HAVE_DIFF_PARENT concerns a batch of otherwise valid windows that fail a common-parent requirement. Error 1442 focuses on one expected child relationship.
Example
A plug-in caches the handle of a property-page control. The host replaces the page when the user changes mode, but the plug-in later tries to scroll the old control relative to the new page. USER32 reports 1442. Resolving the control from the active page before each operation removes the stale relationship.
References
Looking for a different code? Search another status or error code.