Fix ERROR_CHILD_WINDOW_MENU (0x0000059C) Fast
This Windows error means a child window tried to get a menu it can't have. The fix is marking the window as a popup or removing the menu call.
Yeah, I've seen this one plenty. You're building a Windows app, and suddenly you hit 0x0000059C — "Child windows cannot have menus." It's frustrating because the compiler doesn't catch it. But the culprit here is almost always a window style mismatch or a misplaced menu assignment.
Quick Fix: Change the Window Style
The error fires when you try to attach a menu to a child window (WS_CHILD style). Windows simply doesn't allow it — child windows can't have their own menus. The real fix is one of two things:
Option 1: Use WS_POPUP instead of WS_CHILD
If the window doesn't need to be a true child, just make it a popup. In your CreateWindowEx call, replace WS_CHILD with WS_POPUP. Example:
HWND hWnd = CreateWindowEx(0, "MyWindowClass", "Title",
WS_POPUP | WS_CAPTION | WS_SYSMENU,
100, 100, 400, 300,
hParent, NULL, hInstance, NULL);
Popups can have menus and float above the parent. No more error.
Option 2: Keep WS_CHILD, Remove the Menu
If you really need it as a child (e.g., docked inside a parent), you can't give it a menu. Remove the hMenu parameter — pass NULL. Then handle any menu-like behavior from the parent window instead. Like this:
HWND hWnd = CreateWindowEx(0, "MyChildClass", "Title",
WS_CHILD | WS_VISIBLE | WS_BORDER,
0, 0, 200, 100,
hParent, NULL, hInstance, NULL);
// Notice: NULL for hMenu
Why This Happens
Under the hood, Windows UI architecture separates menu ownership from child windows. Child windows are meant to be nested inside a parent, sharing the parent's menu bar. Giving a child its own menu would break that hierarchy — the OS doesn't know where to draw it, and menu routing gets weird. The error code literally says "Child windows cannot have menus." Microsoft made that choice back in the Win32 days, and it hasn't changed.
So if you see 0x0000059C, it's always a code design issue. You're either doing something that was never supported, or you're misreading a legacy app's expectations.
Less Common Variations
Sometimes the error pops up in other scenarios:
- MFC Apps: If you're using
CMenu::Attachon a child window created viaCChildFrame, you'll get this. The fix is overridingOnUpdateFrameMenuto not attach a menu, or switching the frame style toWS_POPUP. - Dialog Child Windows: You might see it when creating a modeless dialog with a child style. Don't set
DS_CHILDif you also want a menu. UseDS_SYSMODALorWS_POPUPinstead. - Older Win32 Samples: Some vintage code samples used
WS_CHILDwith a menu handle by accident. They probably compiled fine on Windows 95, but modern Windows (Vista+) enforces this stricter and throws the error. The fix is always the same — ditch the menu or change the style.
Prevention for Future Apps
Stop this before it starts:
- Design your window hierarchy first. Decide which windows are children and which are popups before writing a line of code.
- Use resource files (.rc) with menus. Attach menus only to popup or overlapped windows in your resource definitions. Never assign a menu resource to a child dialog.
- Assert in debug builds. Add a check like this early in your code:
#ifdef _DEBUG
HWND hWnd = CreateWindowEx(...);
LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE);
if ((style & WS_CHILD) && GetMenu(hWnd) != NULL) {
DebugBreak(); // You'll catch it before the error
}
#endif
That debug check alone saves me hours when I'm refactoring old code. Put it in your project template.
Bottom line: child windows can't have menus. It's a hard rule in Windows. The moment you see 0x0000059C, look at the window style and the menu handle. Change one of them, and you're done.
Was this solution helpful?