Knowledge Base Nr: 00055 CommonDlg_Wizard_Sample_MFC.cpp - http://www.swe-kaiser.de

Downloads:

MFC: C++-CodeWizard für CFont und COLORREF Support
-benutzt CommonDialoge für Font und Color Auswahl
-generiert CPP-Sourcecode

  
void CCodeWizardView::OnCfontButton()
{
CFontDialog dlg;

dlg.DoModal();

LOGFONT lf;
dlg.GetCurrentFont(&lf);

CString strFontDescr1, strFontDescr2;
strFontDescr1.Format("font.CreatePointFont(%d, \"%s\");\r\n\r\n", dlg.GetSize(), lf.lfFaceName);

strFontDescr2.Format("font.CreateFont(%d, %d, %d, %d, %d, %d, %d, %d,
%d, %d, %d, %d, %d, \"%s\");\r\n",
lf.lfHeight, lf.lfWidth,
lf.lfEscapement, lf.lfOrientation,
lf.lfWeight,
lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut,
lf.lfCharSet,
lf.lfOutPrecision, lf.lfClipPrecision,
lf.lfQuality,
lf.lfPitchAndFamily, lf.lfFaceName);

GetDlgItem(IDC_CODE)->SetWindowText(strFontDescr1 + strFontDescr2);
}

void CCodeWizardView::OnColorButton()
{
CColorDialog dlg;

dlg.DoModal();

COLORREF cref = dlg.GetColor(); //format of returned DWORD is 0x00bbggrr

BYTE red = cref & 0xff;
BYTE green = (cref >> 8) & 0xff;
BYTE blue = (cref >> 16) & 0xff;

CString strColorDescr;
strColorDescr.Format("RGB(%d, %d, %d)\r\n\r\nRGB(0x%02X, 0x%02X, 0x%02X)",
red, green, blue, red, green, blue);

GetDlgItem(IDC_CODE)->SetWindowText(strColorDescr);
}