DTUI Booksite

Project 8: Visual C++ Dialog Boxes

[Project 7] [Projects Menu] [Project 9]



Team Size:
Duration:

Document Contents

What This Assignment Is About

This assignment focuses on dialog boxes. It explores the different types of controls you can place in a dialog box with the App Studio, Dialog Data Exchange, and Dialog Data Validation. As in the previous assignment, the program you are asked to produce is not too complex, but getting it working will require you to use many different parts of Visual C++.
 
 

When This Assignment Is Due

Friday, November 8, 1996
 
 

What You Are To Do

Implement and then modify Kruglinski’s EX06A program, "The Dialog Box That Ate Cincinnati" detailed in Chapter 6 of the text. Once you have the current program up and running, you are to modify it as much as you like to test and demonstrate knowledge of dialog box features.

Ambitious students should try to implement a basic version of Assignment No. 1 we did in Visual Basic. Some parts of that are quite a challenge, while others are easy. Document your program above and beyond the documentation inserted by Visual C++ to show that you understand what it’s doing.

Change the icon in the About dialog box to something other than the default. Change the code to display your name and your program's title and perhaps some other information that one sees in typical About dialog boxes.

Add any original features that you can. Be sure to make me aware of these via a note when you hand in your program or e-mail so that I look for them and give you the credit you deserve. There are a number of interesting controls that are new with Windows 95 in Kruglinski's Example EX06B.

Like the last assignment, this assignment will be graded in a criterion-referenced manner. That is, you get points for each feature that your program implements with little subjective grading on my part. See the grading information sheet for a list of the things I’m looking for.

Adding Graphics to a Dialog Box

Adding icons to a dialog box is pretty straightforward, and Kruglinski explains how to draw in a dialog box on p. 131. Adding bitmap graphics is considerably more complex and I will discuss this in class. Heather Ehrlich and I worked out the following function over the summer, and I present it for you to use as a template.

Note that this technique draws pictures on static controls (labels in Visual Basic). You must first create a static control in AppStudio as Kruglinski does on p. 131. Then replace parts of the code you’ll find there with what you see below. If you want to draw directly on the dialog box background, you have to do even more work.

void CEx06aDialog::OnPaint()

{

    CPaintDC dc(this); // device context for painting

    

    // TODO: Add your message handler code here  

    

////////////////////////////////////////////////////////////////////////////////

// added by JMH 10/24/95, devised by JMH and HE, 7/95

// the following code displays a bitmap in a static control

// ref. Kruglinski pp. 132 and 183



        // get a pointer to the dialog box static (label) control 

        // created in App Studio -- this is the control that will 

        // contain the bitmap

    CWnd* pWnd = GetDlgItem(IDC_BITMAP_JESSE);

    

        // get a device context for the control into which we will 

        // draw

    CDC* pControlDC = pWnd->GetDC() ;

    

        // invalidate the control and update its window so that it 

        // will be redrawn 

    pWnd->Invalidate() ;

    pWnd->UpdateWindow() ;

    

        // create a new device context for the display memory that 

        // will hold the bitmap and a new bitmap item into which 

        // we will load the bitmap we created in App Studio

    CDC* pDisplayMemDC = new CDC ;

    CBitmap* pBitmap = new CBitmap ;

    

        // load the bitmap into memory

    pBitmap->LoadBitmap(IDB_BITMAP_JESSE) ;

    

        // make the device context of the display memory compatible 

        // with that of the control in which the bitmap will be 

        // displayed

    pDisplayMemDC->CreateCompatibleDC(pControlDC) ;

    

        // select the bitmap as an object so that it can be copied 

        // into the control

    pDisplayMemDC->SelectObject(pBitmap) ;

    

        // copy the bitmap bit by bit into the control's display 

        // memory

    pControlDC->BitBlt(0,0, 100,100, pDisplayMemDC, 0,0, SRCCOPY) ;

    

        // destruct and deallocate the memory for the items created 

        // with "new"

    delete pDisplayMemDC;

    delete pBitmap;

    

        // release the control's device context - this is critical 

        // to avoid memory leaks!

    pWnd->ReleaseDC(pControlDC) ;



////////////////////////////////////////////////////////////////////////////////

    

    // Do not call CDialog::OnPaint() for painting messages



}  // void CEx06aDialog::OnPaint()
 

What You Are To Hand In

Copy or zip to a diskette that you will hand in: Important Note: I will not recompile your program, so make sure that your EXE file will run if I copy it to my hard drive and run it. You should test this by doing it yourself on a system other than the one on which you built the program.

Mark your name clearly on the diskette and label it "91.353 Assignment No. 4."

Hand in your diskette at the beginning of class on the day it is due.
 
 

How You Will Be Graded

This assignment will be graded on a 20-point system with points awarded as follows:
Criteria Possible
Points
Your
Score
Documentation and Formatting
          added by you, not inserted by VC++!
      2  
Functionality
     - contains Kruglinski’s controls
     - contains additional controls
     - initializes dialog box data
          beyond Kruglinski
     - retrieves dialog box data
     - performs data validation
          beyond Kruglinski
     - has new icon in about box
     - view responds to other events
          other than OnLButtonDown
     - implements a second dialog box
     - has additional original features
          point these out so I notice them

      1
      2
      2

      2
      3

      1
      2

      3
      2

 

 
Jesse Heines

Contributors Page

Please send comments and suggestions to the Booksite Director
Last Updated: 12 March 2000