首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC的一个有关问题,请

2012-01-21 
VC的一个问题,请高手指点:if(GetDlgCtrlID()IDC_SPIN_D1){……m_spin_d1(CSpinButtonCtrl*)GetDlgItem(ID

VC的一个问题,请高手指点:
if(GetDlgCtrlID()==IDC_SPIN_D1)
{……m_spin_d1=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_D1);……}
if(GetDlgCtrlID()==IDC_SPIN_D2)
{……m_spin_d2=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_D2);……}
……
……
……
if(GetDlgCtrlID()==IDC_SPIN_D10)
{……m_spin_d10=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_D10);……}

类似这一串的语句怎么用循环语句实现呢?
显然不能用数组实现的,要是比10更多怎么办的呢?

[解决办法]

C/C++ code
UINT nResID [] = {IDC_SPIN_D1,IDC_SPIN_D2,IDC_SPIN_D3,...};int nResCount = sizeof(nResID)/sizeof(UINT);CSpinButtonCtrl *pSpinCtrl[nResCount];pSpinCtrl[0] = &m_spin_d1;pSpinCtrl[1] = &m_spin_d2;pSpinCtrl[2] = &m_spin_d3;//...for(int i=0;i<nResCount;i++){    pSpinCtrl[i] = (CSpinButtonCtrl*)GetDlgItem(nResID[i]);}
[解决办法]
探讨
C/C++ code
UINT nResID [] = {IDC_SPIN_D1,IDC_SPIN_D2,IDC_SPIN_D3,...};

int nResCount = sizeof(nResID)/sizeof(UINT);

CSpinButtonCtrl *pSpinCtrl[nResCount];
pSpinCtrl[0] = &amp;m_spin_d1;
pSpin……

热点排行