-2

I have added a menu in my windows program using resource editor now I want to add a submenu under some specific condition. Below is piece of my code.

This is my Menu.h file

include

class CmainWn : public CFrameWnd

{

public :CmainWn();

DECLARE_MESSAGE_MAP()

afx_msg void OnAB();

};

class CApp : public CWinApp

{

public : BOOL InitInstance();

};

This is my Menu.cpp

include"Menu.h"

include"resource.h"

CmainWn ::CmainWn()

{

Create(NULL,"Menu Testing",WS_OVERLAPPEDWINDOW,rectDefault,NULL,(LPCTSTR)IDR_MENU1);

}

BOOL CApp :: InitInstance()

{

m_pMainWnd=new CmainWn();

m_pMainWnd->ShowWindow(m_nCmdShow);

m_pMainWnd->UpdateWindow();

return true;

}

void CmainWn::OnAB()

{

AfxMessageBox("Hello");

}

BEGIN_MESSAGE_MAP(CmainWn,CFrameWnd)

ON_COMMAND(ID_A_B, &CmainWn::OnAB)

END_MESSAGE_MAP()

CApp App;

As you can see the code I have created main menu named A and one submenu named B. I want to add one menu dynamically under B. How to do it ?

JAI SINGH
  • 27
  • 6
  • 1
    Your question is a poorly formatted version of [this question](http://stackoverflow.com/q/28690886/1889329) (asked 4 hours ago). – IInspectable Feb 24 '15 at 13:02
  • did you check http://stackoverflow.com/questions/3673546/dynamic-menu-using-mfc – GingerJack Feb 24 '15 at 14:53
  • @GingerJack yes I have gone through that and able to create dynamic menu at run time but not able to append as submenu item in my main menu. – JAI SINGH Feb 25 '15 at 05:06
  • I recommend you to read the `OnInitMenuPopup` documentation. – sergiol Sep 30 '16 at 19:13
  • @IInspectable: Your comment does not make sense anymore, as«s its link became dead. – sergiol Sep 30 '16 at 19:15
  • 1
    @sergiol: It's dead, unless you have [enough reputation to see deleted content](http://stackoverflow.com/help/privileges/moderator-tools). I can still see the question very well by following the link. – IInspectable Sep 30 '16 at 19:31

1 Answers1

-2

Sample code that has to be added to your windows resource file (projectname.rc)

IDR_MENU1 MENU 
BEGIN
      POPUP "Main menu"
       BEGIN
           MENUITEM "Menu Item 1", ID_WINDOWS_TEST
           POPUP "Sub Menu"
        BEGIN
            MENUITEM "Sub Menu item 1",ID_WIN_TEXT
        END
    END
END 

Viewing this in resource view would display something like this enter image description here

GingerJack
  • 3,044
  • 1
  • 17
  • 19