天天看點

怎麼VC++設定對話框中所有靜态文本的字型

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

GetDlgItem(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);    }