title: How to add submenu dynamically in mfc
body: <p>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.</p>
  
  <p>This is my <strong>Menu.h</strong> file</p>
  
  <h1>include</h1>
  
  <p>class CmainWn : public CFrameWnd</p>
  
  <p>{</p>
  
  <p>public :CmainWn();</p>
  
  <p>DECLARE_MESSAGE_MAP()</p>
  
  <p>afx_msg void OnAB();</p>
  
  <p>};</p>
  
  <p>class CApp : public CWinApp</p>
  
  <p>{</p>
  
  <p>public : BOOL InitInstance();</p>
  
  <p>};</p>
  
  <p>This is my <strong>Menu.cpp</strong></p>
  
  <h1>include"Menu.h"</h1>
  
  <h1>include"resource.h"</h1>
  
  <p>CmainWn ::CmainWn()</p>
  
  <p>{</p>
  
  <pre><code>Create(NULL,"Menu Testing",WS_OVERLAPPEDWINDOW,rectDefault,NULL,(LPCTSTR)IDR_MENU1);
  </code></pre>
  
  <p>}</p>
  
  <p>BOOL CApp :: InitInstance()</p>
  
  <p>{</p>
  
  <pre><code>m_pMainWnd=new CmainWn();
  
  m_pMainWnd-&gt;ShowWindow(m_nCmdShow);
  
  m_pMainWnd-&gt;UpdateWindow();
  
  return true;
  </code></pre>
  
  <p>}</p>
  
  <p>void CmainWn::OnAB()</p>
  
  <p>{</p>
  
  <pre><code>AfxMessageBox("Hello");
  </code></pre>
  
  <p>}</p>
  
  <p>BEGIN_MESSAGE_MAP(CmainWn,CFrameWnd)</p>
  
  <pre><code>ON_COMMAND(ID_A_B, &amp;CmainWn::OnAB)
  </code></pre>
  
  <p>END_MESSAGE_MAP()</p>
  
  <p>CApp App;</p>
  
  <p>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 ?</p>