Programming with Microsoft Visual C++.NET 6ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming with Microsoft Visual C++.NET 6ed [Electronic resources] - نسخه متنی

George Shepherd, David Kruglinski

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید








The Ex13c Example: Using Rebars


Let's get familiar with the rebar by jumping into an example. This example creates an SDI application that has a rebar with two bands: a familiar toolbar band and a dialog bar band. Figure 13-6 shows the example in action.


Figure 13-6: Ex13c rebar example.

Here are the steps required to create the Ex13c example:



  1. Run the MFC Application Wizard to generate a project named Ex13c. Choose New Project from Visual Studio's File menu. In the New Project dialog box, select the MFC Application template, type the name Ex13c, and click OK. In the MFC Application Wizard, accept all the defaults but two: On the Application Type page, select Single Document, and on the User Interface Features page under Toolbars, select Standard Docking and Browser Style.



  2. Compile and run the application. When you run the application, you'll see that the MFC Application Wizard has automatically created a rebar with two bands. One band contains a conventional toolbar and the other contains the text TODO: layout dialog bar in the band.


    Open the

    MainFrm.h header file and see the code below, which declares the CReBar data member m_ndReBar.

    protected:  // control bar embedded members
    CStatusBar m_wndStatusBar;
    CToolBar m_wndToolBar;
    CReBar m_wndReBar;
    CDialogBar m_wndDlgBar;

    In the

    MainFrm.cpp file, you can see the code that adds the toolbar and the dialog bar to the CReBar object:

        if (!m_wndReBar.Create(this) ||
    !m_wndReBar.AddBar(&m_wndToolBar) ||
    !m_wndReBar.AddBar(&m_wndDlgBar))
    {
    TRACE0("Failed to create rebar\n");
    return -1; // fail to create
    }



  3. Lay out the dialog bar. In Resource View, under the Dialog node, you'll find a dialog resource for the dialog bar with the ID IDR_MAINFRAME. Open IDR_MAINFRAME, and you'll see the dialog bar with the text TODO: layout dialog bar. Let's put some real controls onto the dialog bar. First, delete the static control with the TODO text in it. Then place a combo box on the dialog bar and use the Properties window to enter the following default data items in the Data property: One;Two;Buckle;My;Shoe!;. Now place a button on the dialog bar and change the button's Caption property to Increment. Place a progress control on the dialog bar and set the Smooth property to True. Finally, place another button on the dialog bar and change the Caption property to Decrement. When you're done laying out out the dialog bar, it should look similar to this.




  4. Edit the

    MainFrm.h file. Visual Studio doesn't understand how to connect the controls on the dialog bar with handlers in the CMainFrame class. We need to add them by hand. Open up

    MainFrm.h and add the following prototypes to CMainFrame.


    afx_msg void OnButton1();
    afx_msg void OnButton2();



  5. Edit the

    MainFrm.cpp file. Open

    MainFrm.cpp and add the following message maps for Button1 and Button2:

    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    ON_WM_CREATE()
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
    END_MESSAGE_MAP()

    Add the following OnButton1 and OnButton2 methods to CMainFrame.cpp:


    void CMainFrame::OnButton1()
    {
    CProgressCtrl * pProgress =
    (CProgressCtrl*)m_wndDlgBar.GetDlgItem(IDC_PROGRESS1);
    pProgress->StepIt();
    }
    void CMainFrame::OnButton2()
    {
    CProgressCtrl * pProgress =
    (CProgressCtrl*)m_wndDlgBar.GetDlgItem(IDC_PROGRESS1);
    int nCurrentPos = pProgress->GetPos();
    pProgress->SetPos(nCurrentPos-10);
    }

    The OnButton1 handler first gets a pointer to the progress control and then calls StepIt to increment the progress control. OnButton2 decrements the current progress position by 10.



  6. Compile and test the Ex13c application. Now you can compile and run Ex13c to see your custom rebar in action. The Increment button increases the progress bar and the Decrement button decreases it.




/ 319