To represent the Win32's color dialog box, the CColorDialog class is equipped with a member variable named m_cc: CHOOSECOLOR m_cc; This member variable allows you to manipulate the characteristics of a color dialog box using the members of the CHOOSECOLOR structure.
The most important and most obvious property of the color dialog box is its color. When the dialog box displays, you may want it to show a certain color as a suggestion or it can be a color you specify for any reason. To specify the default color, when declaring the CColorDialog box, pass the first argument to the constructor. Here is an example: void CExerciseDlg::OnBnClickedColorBtn()
{
// TODO: Add your control notification handler code here
CColorDialog dlg(RGB(25, 125, 155));
}
After using the dialog box, you may want to get the color the user selected. To provide this information, the CColorDialog class is equipped with the GetColor() member function. Its syntax is: COLORREF GetColor()const; Here is an example of calling this member function: void CExerciseDlg::OnBnClickedColorBtn()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if( dlg.DoModal() == IDOK )
SetBackgroundColor(dlg.GetColor());
}
You can control the regular or full size of the dialog box. To specify the default size when the color dialog box comes up, pass the second argument. For example, to display the dialog box in its full size, pass the second argument with a CC_FULLOPEN value. Here is an example: void CExerciseDlg::OnBnClickedColorBtn()
{
// TODO: Add your control notification handler code here
CColorDialog dlg(208468, CC_FULLOPEN);
if( dlg.DoModal() == IDOK )
SetBackgroundColor(dlg.GetColor());
}
If you want to supply the user with a set of colors of your choice, you can do this using a list of custom colors. To support this, the CHOOSECOLOR structure is equipped with a member named lpCustColors. The COLORREF::lpCustColors member is an array of 16 COLORREF values. After creating that array, assign it to this member variable. Here is an example: void CExerciseDlg::OnBnClickedColorBtn() { // TODO: Add your control notification handler code here CColorDialog dlg; COLORREF cRef[] = { RGB(0, 5, 5), RGB(0, 15, 55), RGB(0, 25, 155), RGB(0, 35, 255), RGB(10, 0, 5), RGB(10, 20, 55), RGB(10, 40, 155), RGB(10, 60, 255), RGB(100, 5, 5), RGB(100, 25, 55), RGB(100, 50, 155), RGB(100, 125, 255), RGB(200, 120, 5), RGB(200, 150, 55), RGB(200, 200, 155), RGB(200, 250, 255) }; dlg.m_cc.lpCustColors = cRef; dlg.m_cc.Flags |= CC_FULLOPEN; if( dlg.DoModal() == IDOK ) SetBackgroundColor(dlg.GetColor()); } |
|
|||||||||
|