我再VC里面假如有10个BUTTON,我要在代码里面实现对这些BUTTON固定位置,设置字体等等,现在我用的方法是一个个的设置,能否把这些BUTTON添加到一个数组里面,然后进行一个循环,我觉得这样比较简单,我现在的方法比较笨,还请高手指点应该怎么做?CButton m_btnStrips_print;
CButton m_btnStrips_confirm;
CButton m_btnPageup;
CButton m_btnPagedown;
CButton m_btnNormal;
CButton m_btnClassify_VE;
CButton m_btnClassify_SVE;
CButton m_btnClassify_artifact;
CButton m_chTwo;
CButton m_chThree;
CButton m_chOne;
CButton m_chAll;
CButton m_btn56;
CButton m_btn48;
CButton m_btn42;
CButton m_btn36;
CButton m_btn32;
CButton m_btn28;
CButton m_btn24;
CButton m_btn180;
CButton m_btnMax;
我写了一个方法对所有的BUTTON设置字体:
 void CCBUIView::ButtonStyle()
{
 //设置BUTTON的字体
CFont m_newFont;
m_newFont.CreatePointFont(90,"Arial",NULL);
m_btnArtifact.SetFont(&m_newFont,TRUE);
m_btnBigmini.SetFont(&m_newFont,TRUE);
m_btnBrady.SetFont(&m_newFont,TRUE);
         m_btnMinimum.SetFont(&m_newFont,TRUE);
m_btnPair.SetFont(&m_newFont,TRUE);
m_btnPause.SetFont(&m_newFont,TRUE);
m_btnPVC.SetFont(&m_newFont,TRUE);
m_btnSVE.SetFont(&m_newFont,TRUE);
m_btnSVEBigmini.SetFont(&m_newFont,TRUE);
m_btnMax.SetFont(&m_newFont,TRUE);    m_btn180.SetFont(&m_newFont,TRUE);
m_btn24.SetFont(&m_newFont,TRUE);
m_btn28.SetFont(&m_newFont,TRUE);
m_btn32.SetFont(&m_newFont,TRUE);
m_btn36.SetFont(&m_newFont,TRUE);
m_btn42.SetFont(&m_newFont,TRUE);
m_btn48.SetFont(&m_newFont,TRUE);
m_btn56.SetFont(&m_newFont,TRUE);
m_btnClassify_artifact.SetFont(&m_newFont,TRUE);
m_btnClassify_SVE.SetFont(&m_newFont,TRUE);
m_btnClassify_VE.SetFont(&m_newFont,TRUE);
m_btnNormal.SetFont(&m_newFont,TRUE);
m_btnPagedown.SetFont(&m_newFont,TRUE);
m_btnPageup.SetFont(&m_newFont,TRUE);
m_btnStrips_confirm.SetFont(&m_newFont,TRUE);
m_btnStrips_print.SetFont(&m_newFont,TRUE);
m_chAll.SetFont(&m_newFont,TRUE);
m_chOne.SetFont(&m_newFont,TRUE);
m_chTwo.SetFont(&m_newFont,TRUE);
m_chThree.SetFont(&m_newFont,TRUE);
}
可是我觉得这样太笨了,有简单的方法吗?

解决方案 »

  1.   

    CButton *pBtnArray[] = { &m_btnStrips_print, &m_btnStrips_confirm, ....,
                       &m_btnMax};for ( int i = 0; i < sizeof(pBtnArray) / sizeof( pBtnArray[0] ); i++ )
    {
         (pBtnArray[i])->SetFont(&m_newFont,TRUE); }
      

  2.   

    定义ID连续的10个BUTTON 控件初始ID 为 IDC_BUTTON1for(UINT i=0;i<10;i++)
    {
      CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTON1+i);
      pButton->SetFont;
    }
      

  3.   

    如果ID不连续则保存ID的数组
      

  4.   

    另外可以在 InitDialog函数中用 FindWindow函数遍历子窗口(即控件)判断是否Button,再进行SetFont