Its Gives Latest Tech News Updates

It gives latest mobiles updates laptops updates

It gives latest Teachnology updates

It will gives Latest Opreating System Updates

It will Provides Various materials

It will Provides Smaple Examples Programming Materials.

Showing posts with label VC. Show all posts
Showing posts with label VC. Show all posts

Saturday, 20 January 2018

Important Tips Visual C plus


Important Tips:-
AddString ( ): Adds string to a list box and for combo box this adds string to the end of the list in the list box of a combo box.
App wizard: this will write default code in our program for us.
Application Programming Interface(API): is an interface implemented by a software program to enable interaction with other software, similar to the way a user interface facilitates interaction between humans and computers. APIs are implemented by applications, libraries and operating systems.

DEMO ON FILE HANDLING


12.   DEMO ON FILE HANDLING

 DEMO ON FILE HANDLING
Step 1:-Create a SDI program with name writer to read data from key board.
Step 2:-Go to workspace window and select File view tab. Select Header files and click on WriterDoc.h, declare a string of text to hold data in MFC CString object.
                                    public:
                                                virtual ~CKeystrokesDoc();
                                                CString Strdata;
Step 3:-Double click on CKeyStrokes.Doc and in that select CWriterDoc() Constructor and initialize the Strdata to an empty string as follows
                                    CWriterDoc::CWriterDoc()
                                                {
                                                            Strdata = “ “;
                                                }
Step 4:-To read Key Strokes we have to add an event hanlder
Þ    Goto view menu and from that select Class Wizard.
Þ    Select CWriterView under class name menu and select WM_CHAR from messages menu and double click it this adds OnChar () event handler.
Step 5:-To store the character the user typed into Strdata, add code to OnChar() method from CWriterView in class view tab double click it.
            void CWriterView::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags)
                        {
                                    CWriterDoc* pDoc = Get Document();
                                    ASSERT_VALID(pDoc);
                                    pDoc->Strdata += nChar;
                                    Invalidate();
                                    CView::OnChar (nChar, nRepeat, nFlags);
                        }
Step 6:-Customize OnDraw() method from CKeystrokes view as follows:
                        void CWriterView::OnDraw(CDC *pDC)
                        {
                                    CWriter* pDoc = Get Document();
                                    ASSERT_VALID(pDoc);
                                    pDC-> TextOut(100, 100, pDoc->Strdata);

                        }
Step 7:-The file handling deals with the data that has to be send and retrieve from disk for that you are having Serialize() method in WriterDoc.cpp for sending data to disk.
                        void CWriterDoc::Serialize(CArchive& ar)
                        {
                                    if(ar.IsStoring())
                                    {
                                                ar<<Strdata;    //TODO: add storing code here
                                    }
                          else
                                    {
                                                ar>>Strdata;    //TODO: add loading code here
                                    }
                        }
Step 8:-When the user ads some more data to the Strdata object we have to let the document to know that the data has been modified, i.e,
     “save changes to document1”
            void CWriter1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
            {
                        //TODO: Add your message handler code here and/or call default
                          CWriter1Doc* pDoc = GetDocument();
                          ASSERT_VALID(pDoc);
                          pDoc -> StrData += nChar;
                          Invalidate();
                          pDoc -> SetModifiedFlag();
                          CView::OnChar( nChar, nRepCnt, nFlags);
            }
Step 9:-user can get the new document by adding following code in OnNewDocument() method of WritersDoc.cpp.
            BOOL CWriter1Doc::OnNewDocument()
            {
                        if (!CDocument::OnNewDocument())
                                                return FALSE;
                        Strdata = “ “;
                        UpdateAllViews(NULL);
                        return TRUE;
            }
Step 10:-Build………..Compile…………Execute.
Step 11:-Type the data in the window and select the files menus save as item in dialog box give document name as text1.dat and click on ok and user can use the file menu’s open item to open the saved document and he can made changes to that and can again save it using save item of the file menu.


DEMONSTRATION OF SLIDER CONTROL


11.      DEMONSTRATION OF SLIDER CONTROL

DEMONSTRATION OF SLIDER CONTROL
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 Sliders and click ok.
Step 3:-
Þ    MFC Application wizard window is appeared.
Þ    Select dialog based 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:-Add a slider, an edit box, two labels (static box) and label the controls.
Step 5:-Goto class wizard -> new member variable -> m_slider -> category control for Slider and for edit box add the member variables as m_text and click ok.
Step 6:-Initialize the slider control, i.e. the slider can take extreme left position and extreme right position. Set the range from 1 to 100 using the CSlider SetRangeMin() and SetRangeMax() methods. For that go to class view tab -> CSliderDlg -> OnInitDialog() method and write the following code:
                        BOOL CSliderDlg::OnInitDialog()
                        {
                                    CDialog::OnInitDialog();
                                    m_slider.SetRangeMin(1, false);
                                    m_slider.SetRangeMax(100, false);
                                    m_text = ‘1’;
                                    UpdateData (false);
                        }
Step 7:-Goto class wizard -> object ID’S -> CSliderDlg -> messages -> WM_HSCROLL double click it -> OnHScroll() -> ok.
            void CSliderDlg::OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
            {
                        if(nSBCode == SB_THUMBPOSITION)
                        {
                                    m_text.Format(“%ld”, nPos);
                                    UpdateData (false);
                        }
                        else
                        {
                                    CDialog::OnHScroll (nSBCode, nPos, pScrollBar);
                        }

            }

OUTPUT

PROGRAM TO DEMONSTRATE COMBOBOX


10.      PROGRAM TO DEMONSTRATE COMBOBOX

 PROGRAM TO DEMONSTRATE COMBOBOX
Step 1:-Select a NEW file.
Step 2:-Select a project tab from the new window and from that select MFC application wizard [exe] option and give a project name as combo box and click ok.
Step 3:-
Þ    MFC Application wizard window is appeared.
Þ    Select dialog based document 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:-Now place the following controls on the dialog editor two static boxes, one edit box, and one combo box.
Step 5:-Goto-> view-> class wizard-> select IDC_COMBO1-> add variables -> m_combo and category as control -> and another variable as m_text for edit box.
Step 6:-Goto -> class view -> select OnInitDialog() method -> add the following code.
                                    BOOL CCombo1Dlg::OnInitDialog()
                                    {
                                                CDialog::OnInitDialog();
                                                m_combo.AddString(“Item 1”);
                                                m_combo.AddString(“Item 2”);
                                                m_combo.AddString(“Item 3”);
                                                m_combo.AddString(“Item 4”);
                                    }
Step 7:-Goto -> view -> class wizard -> message maps -> IDC_COMBO1 -> CBN_SELCHANGE -> OnSelChange Combo() method -> ok.
Step 8:-Goto -> class view -> CComboDlg -> OnSelChange Combo() -> add the following code:
                                    void CComboboxDlg::OnSelChangeCombo1()
                                    {
                                                m_combo.GetLBText(m_combo.GetCursel(), m_text);
                                                UpdateData(false);
                                    }
Step 9:-Build…………Compile………..Execute.


DEMONSTRATION ON LIST BOXES


9.      DEMONSTRATION ON LIST BOXES

DEMONSTRATION ON LIST 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 list box and click ok.
Step 3:-
Þ    MFC Application Wizard window is appeared.
Þ    Select dialog based default settings in step 1, click next.
Þ    Select default settings from step2 to step6 and click finish.
Þ    New projects information on window will appear and click ok.
Step 4:-Drag and following controls on to the dialog box a list box, edit box, and two static text, the static text box used to display the text.
Step 5:-Add a member variable to the list box, for that class wizard-> member variable tab-> IDC_LIST1-> click on add variable-> connect the member variable m_list to the list box, and make sure that you select control in the category box and add variable m_text to IDC_EDIT1 click ok.
Step 6:-To initialize data in dialog box we add code to OnInitDialog() method. So under class view click on CListboxDlg, in that select OnInitDialog() method and add the following code.
                        BOOL CListboxDlg::OnInitDialog()
                        {
                                    CDialog::OnInitDialog();
                                    m_list.Addstring (“Item 1”);
                                    m_list.Addstring(“Item 2”);
                                    m_list.Addstring(“Item 3”);
                                    m_list.Addstring(“Item 4”);
                                    m_list.Addstring(“Item 5”);
                                    m_list.Addstring(“Item 10”);
                        }
Step 7:-To handle the list box, connect a member variable m_text to the text in the text box and class wizard->message maps->IDC_LIST1->double click on LBN_DBCLK in the message box-> OnDblClkList1()-> click ok.
                        void CListboxDlg::OnDblclkList1()
                        {
                                    m_list.GetText(m_list.GetCursel(),m_text);
                                    UpdateData(false);
                        }

Step 8:-Build………….Compile…………Execute.

A SMALL PROJECT USING CHECK BOXES AND RADIO BUTTONS


8.      A SMALL PROJECT USING CHECK BOXES AND RADIO BUTTONS

A SMALL PROJECT USING CHECK BOXES AND RADIO BUTTONS
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 Flowers and click ok.
Step3:-
Þ    MFC Application Wizard window is appeared.
Þ    Select dialog based settings in step1, click next.
Þ    Select default settings from step2 to step6 and click finish.
Þ    New projects information on window will appear and click ok.
Step 4:-Add controls to the dialog editor, add two group boxes and name one has arrangements and the other has flowers. The default ID, IDC_STATIC will be given by the dialog editor.
Step 5:-Add four radio buttons in the arrangement group box and align them, name the radio buttons as type1, type2, type3, type4. The default ID provided for the radio buttons are IDC_RADIO1…….IDC_RADIO2 and add 4 check boxes in the flowers group box, name them with different flowers names.
Step 6:-The default ID provided for check boxes IDC_CHECK1……….IDC_CHECK4.
Step 7:- Drag and drop static text control(label) and one edit box, name the static text control as price.
Step 8:-view->class wizard->member variables->add variable->click IDC_CHECK1->add variable give name as m_check1 and make sure, the category is value and variable is bool. Make this same for other boxes with their respective names as m_check2……m_check4 and add a member variable m_text to the text in a text box.
Step 9:-view-> class wizard->message maps, under class name(CFlowersDlg) select the object ID’S IDC_RADIO1->BN_CLICKED-> OnRadio1()->ok. Do the same for remaining three radio buttons.
Step 10:-under class view or flowersDlg.cpp file, under on radio1 method, write the following code.
                        void CFlowersDlg::OnRadio1()
                        {
                                    m_check1 = true;
                                    m_check2 = true;
                                    m_check3 = true;
                                    m_check4 = true;
                                    m_text = “$4.36”;
                                    UpdateData(false);

                        }
void CFlowersDlg::OnRadio2()
                        {
                                    m_check1 = false;
                                    m_check2 = false;
                                    m_check3 = true;
                                    m_check4 = true;
                                    m_text = “$5.22”;
                                    UpdateData(false);
                        }
                        void CFlowersDlg::OnRadio3()
                        {
m_check1 = true;
                                    m_check2 = false;
                                    m_check3 = true;
                                    m_check4 = false;
                                    m_text = “$2.26”;
                                    UpdateData(false);
                        }
                        void CFlowersDlg::OnRadio4()
                        {
                                    m_check1 = true;
                                    m_check2 = false;
                                    m_check3 = false;
                                    m_check4 = true;
                                    m_text = “$4.36”;
                                    UpdateData(false);
                        }
Step 11:-Build………..Compile………….Execute.