warning when using createEx for window creation in VC++

1

I am getting waring "Warning: Window creation failed: GetLastError returns 0x00000579" when using below code

CWnd* m_pWndStatic = new CWnd;
m_pWndStatic->CreateEx(0, _T("STATIC"),
                      _T("Hi"), WS_CHILD | WS_VISIBLE | WS_POPUP,
                      CRect(0, 0, 20, 20), this, 1234);

It works fine if i call it without PopUp i.e. WS_POPUP. I am using VS2010.

visual-studio-2010
visual-c++
asked on Stack Overflow Apr 27, 2012 by programmer108 • edited Apr 15, 2013 by paddy

1 Answer

4
//
// MessageId: ERROR_INVALID_MENU_HANDLE
//
// MessageText:
//
// Invalid menu handle.
//
#define ERROR_INVALID_MENU_HANDLE        1401L

Which puts you on the wrong track, the real problem is that you can't create a child window that's also a popup window. Only top level windows can be popups. The diagnostic is generated because for a popup window, it interprets the "1234" argument you pass as a menu handle instead of a child window ID.

Remove the WS_POPUP style flag.

answered on Stack Overflow Apr 27, 2012 by Hans Passant

User contributions licensed under CC BY-SA 3.0