DEMO ON DIALOG BOXES

5.      DEMO ON DIALOG BOXES

DEMO ON DIALOG BOXES
Step 1:-Select a NEW file.
Step 2:-Select a project tab from new window and from that select MFC application wizard [exe] option and give a project name as dialog and click ok.
Step 3:-
Þ    MFC Application Wizard window is appeared.
Þ    Select single document default settings in step 1, click next
Þ    Select default settings from step 2 to step 6 and click finish.
Þ    New projects information on window will appear and click ok
Step 4:-Open menu editor by clicking the Resource tab in the VC++ Viewer window, this opens the menu program’s resources folder, find the folder marked menus and open it. Double click on the folder, IDR_MAINFRAME, opening the menu editor.

Step 5:-Add a new menu item SHOW DIALOG, by clicking the File Menu in the menu editor. The new menu editor will go below the save menu item, so click that menu item and press the insert key to insert new, blank menu item.
Step 6:-Double click this new menu, and then Menu item Properties Box will appear in that give caption as Show Dialog and make sure the ID is ID_FILE_SHOWDIALOG and close the box.
Step 7:-Connect the Menu Item to code, for that open Class Wizard in the View menu and click ID_FILE_SHOWDIALOG under object IDs in the CDialogView class and click the items Command entry in the Messages box. This makes Class Wizard suggest a name for the event-handler of OnFileShowDialog() and click on OK.
Step 8:-Goto Insert menu and click on Resource and from that select dialog then, a new dialog box and a tool bar will be appeared. Drag one button and one edit box from the tool bar and label the button as click me.
Step 9:- Create a class for dialog box, select class wizard and select new class and give calss name as Dlg and click ok.
Step 10:-Now connect the methods to the dialog box, for that select IDC_BUTTON1 in class wizard and under messages double click on BN_CLICKED and a menu will be displayed showing the member function name OnButton1(), click ok.
Step 11:-Now connect variables to dialog box controls, click member variables tab in class wizard, select class name as Dlg and select IDC_EDIT1 and double click on it, a menu will be displayed and add member variable as m_text, and click ok.
Step 12:-Now add the class Dlg by clicking File View-> Source file-> program name dialogview.cpp
                       #include “stdafx.h”;
                        #include “dialogDoc.h”;
                        #include “dialogView.h”;
                        #include “Dlg.h”;
Step 13:-Click on File View tab -> Header file -> dialogDoc.h and write the following code
                        public:
                                    virtual ~CDialogDoc();
                                    CString Strdata;
Step 14:-Go to -> class view -> click on CDialogDoc-> and click on CDialogDoc() method, and initialize the Strdata
                                    Strdata = “ “;
Step 15:-Click Dlg in class view and add code for following options in Dlg
                                    void Dlg::OnButton1()
                                    {
                                                m_text = “Welcome to Dialogue Box”;
                                                UpdateData(false);
                                    }
Step 16:-Click on OnOk() method and write the following code
                                    void Dlg::OnOk()
                                    {
                                                UpdateData(true);
                                                CShow::OnOk();
                                    }
Step 17:-Click CDialogView in class view and click OnFilesshowdialog and write the following code:
                                    void CDialogView::OnFileshowdialog()
                                    {
                                                Dlg dlg;
                                                int result = dlg.DoModal();
                                                if(result = = IDOK)
                                                {
                                                            CDialogDoc* pDoc = GetDocument();
                                                            ASSERT_VALID(pDoc);
                                                            pDoc->Strdata = dlg.m_text;
                                                            Invalidate();
                        }
                                    }
Step 18:-Click OnDraw() method and write the following code
                        void CDialogView::OnDraw(CDC* pDC)
                        {
                                    CDialogDoc* pDoc = Get Document();
                                    ASSERT_VALID(pDoc);
                                    pDC->TextOut(20,20,PDoc->Strdata);
                        }
Step 19:-Build………….Compile…………..Execute.

OUTPUT:-

No comments:

Post a Comment