Saturday 20 January 2018

DEMO ON ADDING NEW MENU ITEM

4.      DEMO ON ADDING NEW MENU ITEM

DEMO ON ADDING NEW MENU ITEM
Step 1:-Select a NEW file.
Step 2:-Select project tab from new window and from that select MFC application wizard [exe] option and give a project name as menu item and click ok.
Step 3:-
Þ    MFC Application Wizard Application Window is appeared.
Þ    Select single Document default settings in step1, click next.
Þ    Select default settings from step2 to step6 and click finish.
Þ    New projects information will appear and click ok.
Step 4:-Select resources tab and from it select menu and double click on IDR_MAINFRAME and a menu is displayed with default menu’s such as File, Edit, View and Help.
Step 5:-In that menu select File and in the blank space double click on it, and a sub menu will be displayed, in that change the ID column as ID_FILE_PRINTWELCOME and caption as Print Welcome and close that window.
Step 6:-Now goto view menu and click Class Wizard and in that under class name select CMenuitemView and from oject ID’s select ID_FILE_PRINTWELCOME and in the message box double click the COMMAND option, this suggests the name of the member function as OnFilePrintWelcome() and click ok and close class wizard by Clicking ok.
Step 7:-Goto File view tab->Header Files-> click on menuitemDoc.h and write the following.
                        public:
                                    virtual ~CMenuitemDoc();
                                    CString Strdata;
Step 8:-Goto Class View-> CMenuitemDoc-> CMenuitemDoc() constructor, initialize the Strdata
                        CMenuitemDoc::CMenuitemDoc()
                        {
                                    Strdata = “ “;
                        }
Step 8:-To display a message when user clicks on the menu item Print welcome add code to the method OnFilePrintWelcome(), in CMenuitemview class.
 void CMenuitemView::OnFilePrintWelcome()
                        {
                                                CMenuitemDoc* pDoc = GetDocument();
                                                ASSERT_VALID(pDoc);
                                                pDoc->Strdata = “Welcome to menu”;
                                                Invalidate();
                        }
Step 9:-Now double click on OnDraw() method and write the following code:
                        CMenuitemView::OnDraw(CDC* pDC)
                                    {
                                                CMenuitemDoc* pDoc = GetDocument();
                                                ASSERT_VALID(pDoc);
                                                pDC->TextOut(20,20,pDoc->Strdata);
                                    }
Step 10:-Build……….compile…………..Execute.


0 comments:

Post a Comment