BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
//得到ComboBox的句柄
HWND hwndCombo1 = GetDlgItem(hwnd,IDC_COMBO_OPERATOR);
ComboBox_InsertString(hwndCombo1,-1,TEXT("+"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("-"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("*"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("/"));
return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
HWND hwndCombo1 = GetDlgItem(hwnd,IDC_COMBO_OPERATOR);
/*
int cursel = ComboBox_GetCurSel(hwndCombo1);
if (0==cursel)
{
MessageBox(hwnd,TEXT("你选择了+号"),TEXT("choose"),MB_OK);
}
*/
//ComboBox_DeleteString(hwndCombo1,2);
/*
int count = ComboBox_GetCount(hwndCombo1);
TCHAR List_Count[10];
wsprintf(List_Count,"%i",count);
MessageBox(NULL,List_Count,TEXT("总共的项数"),MB_OK);
*/
//ComboBox_SetCurSel(hwndCombo1,1);
/*
TCHAR List_set[10];
int ComboBox_GetLBText(hwndCombo1,2,List_set);
MessageBox(hwnd,List_set,TEXT("消息"),MB_OK);
*/
TCHAR str1[256],str2[256];
int g1 = GetDlgItemText(hwnd,IDC_DATA1,str1,sizeof(str1));
int g2 = GetDlgItemText(hwnd,IDC_DATA2,str2,sizeof(str2));
if (0 == g1 || 0 == g2)
{
MessageBox(NULL,TEXT("输入不能为空值!"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
if (!IsInt(str1))
{
MessageBox(NULL,TEXT("数值1非法"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
if (!IsInt(str2))
{
MessageBox(NULL,TEXT("数值2非法"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
int i1 = atoi(str1);
int i2 = atoi(str2);
TCHAR result[256];
int result_;
int cur_sel = ComboBox_GetCurSel(hwndCombo1);
switch(cur_sel)
{
case 0:
result_=i1 + i2;
break;
case 1:
result_=i1 - i2;
break;
case 2:
result_=i1 * i2;
break;
case 3:
if (0 == i2)
{
MessageBox(NULL,TEXT("除数不能为零!"),TEXT("出
错"),MB_ICONERROR|MB_OK);
return;
}
result_=i1 / i2;
break;
case CB_ERR:
MessageBox(NULL,TEXT("请选择计算类型!"),TEXT("出
错"),MB_ICONERROR|MB_OK);
return;
default:
break;
}
itoa(result_,result,10);
SetDlgItemText(hwnd,IDC_RESULT,result);
}
break;
default:
break;
}
}
阅读(1185) | 评论(0) | 转发(0) |