void COptionsPage2::ChangeFont(CString strSection, CString strEntry, CString strDefaultFace, int nDefaultSize /*-1*/) { //empty the logfont structure LOGFONT lf; ZeroMemory( &lf, sizeof(LOGFONT) ); //read current setting lf.lfItalic = AfxGetApp()->GetProfileInt( strSection, strEntry + "Italic", 0 ); lf.lfWeight = AfxGetApp()->GetProfileInt( strSection, strEntry + "Weight", 0 ); strcpy( lf.lfFaceName, AfxGetApp()->GetProfileString( strSection, strEntry + "Face", strDefaultFace ) ); if( nDefaultSize != -1 ) lf.lfHeight = AfxGetApp()->GetProfileInt( strSection, strEntry + "Size", nDefaultSize ); else lf.lfHeight = 13; //display font dialog CFontDialog FontDlg( &lf, CF_SCREENFONTS|CF_NOSCRIPTSEL|(nDefaultSize==-1?CF_LIMITSIZE:0) ); if( nDefaultSize == -1 ) FontDlg.m_cf.nSizeMin = FontDlg.m_cf.nSizeMax = 10; if( FontDlg.DoModal() == IDOK ) { AfxGetApp()->WriteProfileInt( strSection, strEntry + "Italic", lf.lfItalic ); AfxGetApp()->WriteProfileInt( strSection, strEntry + "Weight", lf.lfWeight ); AfxGetApp()->WriteProfileString( strSection, strEntry + "Face", lf.lfFaceName ); if( nDefaultSize != -1 ) AfxGetApp()->WriteProfileInt( strSection, strEntry + "Size", lf.lfHeight ); } }
/*-------------------------------------------------------------------*/ BOOL BlockTextFontDlg(POBJECT pObj, WINDOWINFO *pwi) { blocktext *pT; BOOL bResult; SIZEF sizfx; pT = (blocktext *)pObj; bResult = FontDlg(pwi,&pT->fattrs,TRUE); /* Start the fontdialog.... */ if (bResult && getFontDlgSizfx(&sizfx)) { pT->sizfx.fcx = (float)sizfx.cx; pT->sizfx.fcy = (float)sizfx.cy; pT->sizfx.fcx /= (float)pwi->usWidth; pT->sizfx.fcy /= (float)pwi->usHeight; } return bResult; }