BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { //当会话框初始化的时候被调用 HWND hwndCombo1 = GetDlgItem(hwnd,IDC_COMBOOP); /* 怎样使字符串加入的顺序不变? ComboBox_AddString(hwndCombo1,TEXT("+")); ComboBox_AddString(hwndCombo1,TEXT("-")); ComboBox_AddString(hwndCombo1,TEXT("*")); ComboBox_AddString(hwndCombo1,TEXT("/")); */ 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_COMBO1); /*确定目前选项的索引 int curSel = ComboBox_GetCurSel(hwndCombo1); if(0==curSel) { MessageBox(hwnd,TEXT("你选择的是-号"),TEXT("消息"),MB_OK); } */ /*删除其中的一个选项 ComboBox_DeleteString(hwndCombo1,2); 选定某一项 ComboBox_SetCurSel(hwndCombo1,2); */ /*得到某项的值 TCHAR str[256]; ComboBox_GetLBText(hwndCombo1,1,str); MessageBox(hwnd,str, TEXT("消息"),MB_OK); */ TCHAR str1[256]; TCHAR str2[256]; GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1)); GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2)); int i1 = atoi(str1); int i2 = atoi(str2); int i3 = 0; HWND hwndComboOp = GetDlgItem(hwnd,IDC_COMBOOP); int curIndex = ComboBox_GetCurSel(hwndComboOp); switch(curIndex) { case 0: { i3 = i1+i2; } break; case 1: { i3 = i1-i2; } break; case 2: { i3 = i1*i2; } break; case 3: { i3 = i1/i2; } break; } TCHAR str3[256]; itoa(i3,str3,10); SetDlgItemText(hwnd,IDC_EDIT3,str3); } break; default: break; } }