65,210
社区成员
发帖
与我相关
我的任务
分享
void Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
int nRow, nCol;
switch (id) {
case IDCANCEL:
EndDialog(hwnd, id);
break;
case IDC_ROW:
// User modified the row, update the UI
nRow = GetDlgItemInt(hwnd, IDC_ROW, NULL, FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_READCELL),
chINRANGE(0, nRow, g_nNumRows - 1));
EnableWindow(GetDlgItem(hwnd, IDC_WRITECELL),
chINRANGE(0, nRow, g_nNumRows - 1));
break;
case IDC_COLUMN:
// User modified the column, update the UI
nCol = GetDlgItemInt(hwnd, IDC_COLUMN, NULL, FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_READCELL),
chINRANGE(0, nCol, g_nNumCols - 1));
EnableWindow(GetDlgItem(hwnd, IDC_WRITECELL),
chINRANGE(0, nCol, g_nNumCols - 1));
break;
case IDC_READCELL:
// Try to read a value from the user's selected cell
SetDlgItemText(g_hwnd, IDC_LOG, TEXT("No violation raised"));
nRow = GetDlgItemInt(hwnd, IDC_ROW, NULL, FALSE);
nCol = GetDlgItemInt(hwnd, IDC_COLUMN, NULL, FALSE);
__try {
SetDlgItemInt(hwnd, IDC_VALUE, g_ss[nRow][nCol].dwValue, FALSE);
}
__except (
g_ssObject.ExceptionFilter(GetExceptionInformation(), FALSE)) {
// The cell is not backed by storage, the cell contains nothing.
SetDlgItemText(hwnd, IDC_VALUE, TEXT(""));
}
break;
case IDC_WRITECELL:
// Try to read a value from the user's selected cell
SetDlgItemText(g_hwnd, IDC_LOG, TEXT("No violation raised"));
nRow = GetDlgItemInt(hwnd, IDC_ROW, NULL, FALSE);
nCol = GetDlgItemInt(hwnd, IDC_COLUMN, NULL, FALSE);
// If the cell is not backed by storage, an access violation is
// raised causing storage to automatically be committed,
//这里尝试去 访问没有分配内存的空间,抛异常.但是整个工程,只有一个try结构,也就是IDC_READCELL里的.
g_ss[nRow][nCol].dwValue =
GetDlgItemInt(hwnd, IDC_VALUE, NULL, FALSE);
break;
}
}