CFont *f; f = new CFont; f->CreateFont(13, // nHeight 5, // nWidth 0, // nEscapement 0, // nOrientation 500, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_TT_ALWAYS, // nClipPrecision PROOF_QUALITY , // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Tahoma")); // lpszFacGetDlgItem(IDC_STATIC1)->SetFont(f);
这是设定ID为IDC_STATIC1的静态文本的字体。但我有10个静态文本,有没有一次就设定这10个静态文本的字体的方法。只要一行代码的那种,有没有啊。
1.
可以在OnCtlColor中设置
if( CTLCOLOR_STATIC == nCtlColor) { if( IDC_STATIC1
== pWnd->GetDlgCtrlID() || IDC_STATIC2
== pWnd->GetDlgCtrlID() || IDC_STATIC3
== pWnd->GetDlgCtrlID() || IDC_STATIC4
== pWnd->GetDlgCtrlID() || IDC_STATIC5
== pWnd->GetDlgCtrlID() || IDC_STATIC6
== pWnd->GetDlgCtrlID() || IDC_STATIC7
== pWnd->GetDlgCtrlID() || IDC_STATIC8
== pWnd->GetDlgCtrlID() || IDC_STATIC9
== pWnd->GetDlgCtrlID() || IDC_STATIC10
== pWnd->GetDlgCtrlID() ) { CWnd *pWnd = GetDlgItem(dwID); pWnd ->SetFont(pFont); // pFont是自己定义的字体 } }
2.
或将下面代码放在初始化函数那里:CFont *f;
f = new CFont;
f->CreateFont(13, // nHeight
5, // nWidth
0, // nEscapement
0, // nOrientation
500, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_TT_ALWAYS, // nClipPrecision
PROOF_QUALITY , // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Tahoma")); // lpszFac
CWnd *pWndChild = GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild=pWndChild->GetNextWindow();
//TRACE1("%d\n",pWndChild->GetDlgCtrlID());
if(pWndChild == NULL)
continue;
pWndChild->SetFont(f);
}

1万+

被折叠的 条评论
为什么被折叠?



