Share via

What wrong with the code?

建林 刘 1 Reputation point
2020-10-11T12:22:27.21+00:00

AppendMenu(hMenubar, MF_POPUP, NULL, "File");

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

2 answers

Sort by: Most helpful
  1. RLWA32 52,571 Reputation points
    2020-10-11T17:38:14.767+00:00

    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 -
    31457-idrmenu1.png

    Running application with added menu items -
    31458-codecreated.png
    31390-menucreated.png

    Was this answer helpful?

    0 comments No comments

  2. RLWA32 52,571 Reputation points
    2020-10-11T13:06:00.677+00:00

    You passed NULL instead of a valid handle as the uIdNewItem parameter.

    From nf-winuser-appendmenua

    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.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.