2024年2月19日发(作者:)

VS2010默认生成的MFC程序菜单栏字体很模糊,在CMainFrame::OnCreate函数中加入以下代码即可:

//设置正常字体

LOGFONT lf;

Font(&lf);

Object();

ht =-12;

lstrcpy(Name, _T("宋体")); // using without style office 2007

FontIndirect(&lf);

//设置加粗的字体

Font(&lf);

Object();

ht =-12;

lstrcpy(Name, _T("宋体"));

FontIndirect(&lf);

Font(&lf);

Object();

ht =-12;

lstrcpy(Name, _T("宋体"));

FontIndirect(&lf);

添加 WM_NCPAINT 消息函数, 当然可以设置字体以及居中显示

在你的对话框的头文件中, 在消息映射中添加 afx_msg void OnNcPaint();

在你的对话框的cpp文件中, 在消息映射中添加 ON_WM_NCPAINT()

然后再添加这个消息响应函数:

void CXXXDlg::OnNcPaint()

{

CDialog::OnNcPaint();

CDC* pDC = GetWindowDC();

int x =

GetSystemMetrics(SM_CXSIZE)+GetSystemMetrics(SM_CXBORDER)+GetSystemMetrics(SM_CXDLGFRAME);

int y = GetSystemMetrics(SM_CYDLGFRAME);

CRect CapRct;

GetWindowRect(&CapRct);

int y1 =

GetSystemMetrics(SM_CYICON)-GetSystemMetrics(SM_CYDLGFRAME)-GetSystemMetrics(SM_CYBORDER);

int x1 = ()-

GetSystemMetrics(SM_CXSIZE)-GetSystemMetrics(SM_CXBORDER)-GetSystemMetric

s(SM_CXDLGFRAME);

= x;

= y;

= x1;

= y1;

//pDC->FillSolidRect(&CapRct,RGB(0,0,0));

CFont* pCurFont = GetFont();

LOGFONT lf;

pCurFont->GetLogFont (&lf);

ic = TRUE;

ht = FW_BOLD;

ht = 18;

strcpy(Name ,"Arial");

CFont capfont ;

FontIndirect (&lf);

pCurFont = pDC->SelectObject (&capfont);

pDC->SetBkMode (TRANSPARENT);

pDC->SetTextColor (GetSysColor(COLOR_CAPTIONTEXT));

pDC->DrawText ("My Caption" , &CapRct, DT_SINGLELINE

DT_VCENTER); //最好定义一个m_strCaption类成员

ReleaseDC(pDC);

}

DT_CENTER | |