The CMFCColorDialog class is derived from CDialogEx. Based on this, to present the dialog box to the user, call its DoModal() member function. Here is an example: void CExerciseDlg::OnBnClickedColors()
{
// TODO: Add your control notification handler code here
CMFCColorDialog dlgColors;
dlgColors.DoModal();
}
After using the dialog box, if the user clicks OK, the DoModal() member function returns IDOK. In this case, you can get the values from the dialog box and use it as you see fit.
Before displaying the colors dialog box, you can specify what primary color the dialog box should select. To assist you with this, the CMFCColorDialog class has the following construction: CMFCColorDialog( COLORREF clrInit=0, DWORD dwFlags=0, CWnd* pParentWnd=NULL, HPALETTE hPal=NULL ); As you can see, all arguments are optional. The clrInit argument allows you to specify the initial color that the dialog box would select. Here is an example: void CExerciseDlg::OnBnClickedColors()
{
// TODO: Add your control notification handler code here
CMFCColorDialog dlgColors(268405);
dlgColors.DoModal();
}
Besides the constructor, to let you set the initial or current color of the dialog box, the CMFCColorDialog class is equipped with a member function named SetCurrentColor. Its syntax is: void SetCurrentColor(COLORREF rgb); Here is an example of calling it: void CExerciseDlg::OnBnClickedColors()
{
// TODO: Add your control notification handler code here
CMFCColorDialog dlgColors;;
dlgColors.SetCurrentColor(702416);
dlgColors.DoModal();
}
After using the dialog box, the user can click OK, in which case DoModal() would return IDOK. In this case, to let you identify the color the user would have selected, the CMFCColorDialog class provides the Color() member function. Its syntax is: COLORREF GetColor() const; Here is an example of calling that member function and using the color the user selected: void CExerciseDlg::OnBnClickedColors()
{
// TODO: Add your control notification handler code here
CMFCColorDialog dlgColors;
if( dlgColors.DoModal() == IDOK )
SetBackgroundColor(dlgColors.GetColor());
}
|
|
|||||||||||
|