You passed NULL instead of a valid handle as the uIdNewItem parameter.
uIDNewItem
Type: UINT_PTR
The identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, a handle to the drop-down menu or submenu.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
AppendMenu(hMenubar, MF_POPUP, NULL, "File");
You passed NULL instead of a valid handle as the uIdNewItem parameter.
uIDNewItem
Type: UINT_PTR
The identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, a handle to the drop-down menu or submenu.
In a Windows desktop application a handler was added for WM_CREATE to create and add menu items to the menubar when the main window is created-
Handler -
case WM_CREATE:
{
HMENU hMenuBar = GetMenu(hWnd);
// Create popup menu with code
HMENU hPopup = CreatePopupMenu();
AppendMenu(hPopup, MF_STRING, ID_DYNAMIC_ITEM1, _T("Code created Item 1"));
AppendMenu(hPopup, MF_STRING, ID_DYNAMIC_ITEM2, _T("Code created Item 2"));
AppendMenu(hMenuBar, MF_POPUP, reinterpret_cast<UINT_PTR>(hPopup), _T("Code Created"));
DestroyMenu(hPopup);
// Get popup menu from a menu resource
HMENU hDummy = LoadMenu(NULL, MAKEINTRESOURCE(IDR_MENU1));
AppendMenu(hMenuBar, MF_POPUP, reinterpret_cast<UINT_PTR>(GetSubMenu(hDummy, 0)), _T("Menu Resource"));
DestroyMenu(hDummy);
}
break;
Menu resource used -
Running application with added menu items -