Chinaunix首页 | 论坛 | 博客
  • 博客访问: 410349
  • 博文数量: 73
  • 博客积分: 3326
  • 博客等级: 中校
  • 技术积分: 631
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-05 15:31
文章分类

全部博文(73)

文章存档

2014年(1)

2011年(51)

2010年(21)

分类: C/C++

2010-07-09 18:14:52

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;
    }
}
阅读(1130) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~