未处理的异常...使用数组访问违规以进行回调?
BEGIN_MESSAGE_MAP(yoda, CDialog)
ON_COMMAND_RANGE(2000, 2009, OnChannelClick)
BOOL yoda::OnInitDialog()
{
chbxChannel = new CButton[10];
CString s;
for (i = 0; i < 10; i++){
(chbxChannel + i) -> Create("", WS_CHILD | WS_VISIBLE | BS_CHECKBOX, CRect(80-50, 100+i*20, 100-50, 120+i*20), this, 2000+i);
s.Format("%d",(chbxChannel + nID) -> GetCheck()); // <-- Works fine
MessageBox(s);
}
}
void yoda::OnChannelClick(UINT nID)
{
CString s;
s.Format("%d",nID);// values for nID are correct
MessageBox(s);
s.Format("%d",(chbxChannel + nID) -> GetCheck()); //?? <-- Unhandled Exception... Access Violation ?????
MessageBox(s);
}
答案 0 :(得分:1)
您的ID范围从2000到2009,但您的数组是从0到9.您需要减去范围的开头以用作数组索引。