| Previous | Next |
| ERROR_SCREEN_ALREADY_LOCKED | ERROR_NOT_CHILD_WINDOW |
ERROR_HWNDS_HAVE_DIFF_PARENT
The deferred window batch mixes different parent windows.
ERROR_HWNDS_HAVE_DIFF_PARENT is Win32 error 1441 (0x5A1). It is associated with the multiple-window positioning sequence built by BeginDeferWindowPos, DeferWindowPos, and EndDeferWindowPos. Every window recorded in one deferred-position handle must have the same parent. A mixture of top-level windows, child windows from different containers, or a child whose parent changed during the batch makes the collected operation invalid.
Where the mismatch usually enters
- a layout loop enumerates controls from more than one dialog or property page
- an
HWNDfor a top-level owner is confused with a child parent - a control is reparented after the batch begins but before it is committed
- a stale cached handle now refers to a different window hierarchy
- the code groups windows by visual region rather than by the value returned from
GetParent
Evidence that makes the failure reproducible
Log the deferred-position handle, every target HWND, its class name, thread ID, process ID, and current parent immediately before each DeferWindowPos call. Preserve the order of additions and note whether any callback, docking operation, tab switch, or DPI-change handler can destroy or reparent controls during the sequence. A screenshot cannot reveal the parent relationship used by USER32.
Diagnostic sequence
Check the return value after every call rather than only after EndDeferWindowPos; a failed DeferWindowPos call invalidates the working handle returned to the caller. Query GetParent for the first window and compare that exact handle with the parent of each later target. Do not infer common parentage from identical coordinates or from windows being displayed inside the same application frame.
Review lifetime rules as well. A child can be destroyed and recreated during layout, causing the numeric handle stored in a vector to become stale. If the interface supports detachable panes or MDI children, split the operation whenever the hierarchy can change.
Corrective design
Create one deferred-position batch per parent window. Filter destroyed handles before starting, prevent reparenting while the batch is assembled, and stop immediately if DeferWindowPos returns NULL. For independent top-level windows, use separate SetWindowPos calls or separate batches instead of forcing them into one structure.
Difference from nearby GUI errors
ERROR_NOT_CHILD_WINDOW says a specific parent-child relationship required by an operation is absent. Error 1441 is narrower: the individual windows may all be valid children, but they do not belong to one common parent required by the deferred layout object.
Example
A settings host lays out controls from the active page and a status bar owned by the main frame. Both are visible in the same rectangle, but their parents differ. The second DeferWindowPos fails with 1441. Moving the status bar in a separate batch fixes the layout without changing z-order behavior.
References
Looking for a different code? Search another status or error code.
