11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7. Common Dialog Boxes<br />

the custom dialog template, we need to set CC_ENABLETEMPLATE bit for member Flags of structure<br />

CHOOSECOLOR, and assign the instance handle of the application to member hInstance. Here the instance<br />

handle of the application can be obtained by calling function AfxGetInstanceHandle(). We also need to<br />

assign the name of the custom dialog template to member lptemplateName.<br />

Custom Dialog Template<br />

Sample 7.6\CDB demonstrates how to implement color dialog box using user-designed dialog<br />

template. It is based on sample 7.5\CDB, with two new commands Color Dialog Box | Choose Base Color<br />

and Color Dialog Box | Choose Custom Color added to the application. For command Color Dialog Box<br />

| Choose Base Color, a color dialog box that only allows the user to choose color from base colors is<br />

implemented; for command Color Dialog Box | Choose Custom Color, the user is only allowed to choose<br />

color form custom colors. The IDs of two commands are ID_COLORDIALOGBOX_CHOOSEBASECOLOR and<br />

ID_COLORDIALOGBOX_CHOOSECOSTUMCOLOR, and their WM_COMMAND message handlers are<br />

CCDBDoc::OnColordialogboxChoosebasecolor() and CCDBDoc::<br />

OnColordialogboxChoosecostumcolor() respectively.<br />

Figure 7-6 shows the controls contained in the standard color dialog box.<br />

COLOR_BOX1<br />

COLOR_RAINBOW<br />

COLOR_LUMSCROLL<br />

COLOR_CUSTOM1<br />

COLOR_MIX<br />

COLOR_CURRENT<br />

COLOR_HUE<br />

COLOR_SAT<br />

COLOR_LUM<br />

COLOR_RED<br />

COLOR_GREEN<br />

COLOR_BLUE<br />

COLOR_ADD<br />

Figure 7-6. Standard controls in color dialog box<br />

The following table contains a list of ID values for these controls:<br />

ID Type of Symbol in the Sample<br />

Description<br />

Control<br />

702 Static COLOR_LUMSCROLL Displays possible amounts of white and black in color<br />

703 Edit COLOR_HUE Specifies the hue of the selected color<br />

704 Edit COLOR_SAT Specifies the saturation of the selected color<br />

705 Edit COLOR_LUM Specifies the luminosity of the selected color<br />

706 Edit COLOR_RED Specifies the amount of red in the selected color<br />

707 Edit COLOR_GREEN Specifies the amount of green in the selected color<br />

708 Edit COLOR_BLUE Specifies the amount of blue in the selected color<br />

709 Static COLOR_CURRENT Displays the selected color<br />

710 Static COLOR_RAINBOW Displays the color matrix<br />

712 Push button COLOR_ADD Add the selected color to custom color<br />

719 Push button COLOR_MIX Open the color box fully<br />

720 Static COLOR_BOX1 Displays basic colors<br />

721 Static COLOR_CUSTOM1 Displays custom colors<br />

1 Default push IDOK<br />

OK button<br />

button<br />

2 Push button IDCANCEL Cancel button<br />

1038 Push button 1038 Help button<br />

187

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!