Tuesday, 14 February 2017

Code to create a menu using CreateMenu(), InsertMenu(), AppendMenu()Option

#include "afxwin.h"
classFrame:publicCFrameWnd
{
public:
                 Frame()
                 {
                   Create(NULL,"Menu Design");
                 }
                 intOnCreate(LPCREATESTRUCT l)
                 {
                   CMenu s1;
                   s1.CreateMenu();
                   s1.AppendMenu(MF_STRING,301,"&Menu1");
                   s1.AppendMenu(MF_STRING,302,"&Menu2");
                   SetMenu(&s1);
                   return 1;
                 }
                 void menu1()
                 {
                   MessageBox("Menu 1 is Selected","Menu 1");
                 }
                 void menu2()
                 {
                   MessageBox("Menu 2 is Selected","Menu 2");
                 }
                 DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(Frame,CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(301,menu1)
ON_COMMAND(302,menu2)
END_MESSAGE_MAP()
classMain:publicCWinApp
{
public:
                 intInitInstance()
                 {
                   Frame *p=new Frame();
                   p->ShowWindow(1);
                   m_pMainWnd=p;
                   return 1;
                 }
};

Main s;

No comments:
Write comments