-
_____ Create a new project in Visual studio and call it Test_3_YourName.
Make the project an MFC Application that is dialog based. (In the Advanced
Features uncheck "Active X controls" and "Common Control Manifest". Also
remember to right-click the project name, select Properties and set the
Character Set property to "Not Set".
-
_____ Open the main dialog in the resource editor and add the following widgets
in order to create a dialog window that looks like the one in the above image:
-
_____ Move the OK button and change the text to "Exit".
-
_____ Add three check boxes with the text set respectively to "Red",
"Green", and "Blue".
-
_____ Create BN_CLICKED event handlers for each of the check boxes in
the projectNameDlg class.
-
_____ Add a variable to each of the check boxes with which to
reference each.
-
_____ Add two buttons at the bottom of the dialog. Set the text
on the first to "All On". Set the text on the second to "All Off".
-
_____ Create BN_CLICKED event handlers for each of the buttons in
the projectNameDlg class.
-
_____ In the OnInitDialog() function of the projectNameDlg class do the following:
-
_____ Use the SetWindowText function to set the title of the dialog
to "Test 3 - Your Name".
-
_____ In each of the event handler functions for the three check boxes do the
following:
-
_____ Make an explicit call to the OnPaint() function to redraw the
dialog (See details below on the OnPaint() function.)
-
_____ In the event handler functions for the two buttons do the following:
-
_____ For the "All On" button use the CBVar.SetCheck(1) to set each
of the check boxes to selected.
-
_____ For the "All Off" button use the CBVar.SetCheck(0) to set each
of the check boxes to not selected.
-
_____ Make an explicit call to the OnPaint() function to redraw the
dialog (See details below on the OnPaint() function.)
-
_____ In the onPaint function do the following:
-
_____ Get a pointer to a CDC by calling the function this->GetDC().
-
_____ For each of the three check boxes. Use the GetCheck() function
to see if the checkbox is selected. If so use the
cdc->FillSolidRect(x, y, width, height, COLORREF) to fill a color
rectangle of the currently set color in the position shown in the
above image. If the checkbox is not selected color the rectangle a
dark dray. (Hint: In the sample image shown above the size parameters
were (150, 30, 150, 30) for the red rectangle, (150, 80, 150, 30) for
the green rectangle, and (150, 130, 150, 30) for the blue rectangle.
Colors can be set with Red = RGB(255, 0, 0), Green = RGB(0, 255, 0),
Blue = RGB(0, 0, 255), and Dark Gray = RGB(128, 128, 128).)
-
_____ Compile and run your program to be sure it works as it should.
-
_____ Copy your source files (all .cpp and .h) and executable file into a folder
with your name on it then copy this folder onto the K drive into the designated
folder (Labs/cs307/rcoleman).
|
Helpful Hints:
-
Remember to do all drawing in an MFC Dialog application in the else part
of the if statement in OnPaint.
-
To get the device context to paint with in an MFC Dialog application use the line:
CDC *cdc = this->GetDC();
-
To draw a solid rectangle or oval without having to define a pen or brush use code
like in the following example which draws a red rectangle:
cdc->FillSolidRect(10, 10, 100, 100, RGB(255, 0, 0));
-
Do your drawing after the call to CDialog::OnPaint();
|