You don't need 'CWnd::' to use the member functions, ie.
Code:
CWnd* CheckBox[5];
CheckBox[0] = GetDlgItem(IDC_CHECK1);
CheckBox[1] = GetDlgItem(IDC_CHECK2);
CheckBox[2] = GetDlgItem(IDC_CHECK3);
CheckBox[3] = GetDlgItem(IDC_CHECK4);
CheckBox[4] = GetDlgItem(IDC_CHECK5);
should suffice. You should also use '->' operator to use member functions with a given object pointer, but check for a valid pointer first:
Code:
LRESULT lresult;
for (n=0;n<5;n++)
{
if (CheckBox[n]!=0)
{
lresult = CheckBox[n]->SendMessage(BM_GETCHECK);
if(lresult == BS_CHECKED)
{
SetDlgItemText(IDC_EDIT1, "Checked");
}
}
}
BTW, i've just noticed from the CWnd::GetDlgItem description on msdn that "The returned pointer may be temporary and should not be stored for later use." although, ironically, the window handle (HWND) should be ok. It may, therefore, be in your best interests to adopt another strategy for your control array or, if you know their identifiers have consecutive values, you could just:
Code:
CWnd *pCheckBox;
int n;
for (n=0;n<5;++n)
{
pCheckBox=GetDlgItem(IDC_CHECK1+n);
if (pCheckBox)
{
if (pCheckBox->SendMessage(BM_GETCHECK)==BST_CHECKED)
{
SetDlgItemText(IDC_EDIT1, "Checked");
}
}
}
If you want or need to stick with the original control array idea then something like:
Code:
CWnd CheckBox[5];
CheckBox[0].Attach(GetDlgItem(IDC_CHECK1));
CheckBox[1].Attach(GetDlgItem(IDC_CHECK2));
//etc
might work (CWnd::Attach) to ensure persistent CWnd objects.