编程时,若将字体设置成“黑体、宋体、仿宋—GB2312、楷体—GB2312、隶书、幼圆”中的某一字体时,需将lfCharSet设置成GB2312—CHARSET才使设置的字体有效。下面给出相关程序:
1 CWnd *pWnd=GetDlgItem(IDC_USER);//获取标识号为IDC—USER的控件的CWnd指针
2 CDC *pDC=pWnd->GetDC();
3 CFont font;
4 LOGFONT stFont;
5 memset(&stFont,0,sizeof(LOGFONT));
6 stFont.lfHeight=MulDiv(12,-pDC->GetDeviceCaps(LOGPIXELSY),72);//设置字体高度为12
7 stFont.lfWeight=FW—NORMAL;
8 stFont.lfCharSet=GB2312_CHARSET;
9 strcpy(stFont.lfFaceName,"黑体");//设置字样为黑体
10 font.CreateFontIndirect(&stFont);
11 CFont *oldfont=pDC->SelectObject(&font);
12 pWnd->SetFont(&font,TRUE);
13 font.DeleteObject();
14 pDC->SelectObject(oldfont);
15 pWnd->ReleaseDC(pDC);
2 CDC *pDC=pWnd->GetDC();
3 CFont font;
4 LOGFONT stFont;
5 memset(&stFont,0,sizeof(LOGFONT));
6 stFont.lfHeight=MulDiv(12,-pDC->GetDeviceCaps(LOGPIXELSY),72);//设置字体高度为12
7 stFont.lfWeight=FW—NORMAL;
8 stFont.lfCharSet=GB2312_CHARSET;
9 strcpy(stFont.lfFaceName,"黑体");//设置字样为黑体
10 font.CreateFontIndirect(&stFont);
11 CFont *oldfont=pDC->SelectObject(&font);
12 pWnd->SetFont(&font,TRUE);
13 font.DeleteObject();
14 pDC->SelectObject(oldfont);
15 pWnd->ReleaseDC(pDC);
设置代码如下:
LOGFONT stFont;
memset(&stFont,0,sizeof(LOGFONT));
stFont.lfHeight=25;//MulDiv(12,-pDC->GetDeviceCaps(LOGPIXELSY),72);//设置字体高度为12
stFont.lfCharSet=GB2312_CHARSET;
strcpy(stFont.lfFaceName,"华文彩云");//设置字样为黑体
m_FontPD.CreateFontIndirect(&stFont);
//m_FontPD.CreateFont (25, 0, 0, 0, 800, FALSE, 0, 0, 0, 0, 0, 0, 0, _T("华文彩云") );
GetDlgItem(IDC_STATIC_PD)->SetFont(&m_FontPD);