#include "stdafx.h" #include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch {(uMsg) HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); } return FALSE; } BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { HWND handle_combox1=GetDlgItem(hwnd,IDC_COMBO1); ComboBox_InsertString(handle_combox1,-1,TEXT("+")); ComboBox_InsertString(handle_combox1,-1,TEXT("-")); ComboBox_InsertString(handle_combox1,-1,TEXT("*")); ComboBox_InsertString(handle_combox1,-1,TEXT("/")); //ComboBox_InsertString(handle_combox1,-1,TEXT("转换为二进制")); return TRUE; } void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { switch(id) { case IDC_OK: { HWND handle_combox1=GetDlgItem(hwnd,IDC_COMBO1); int index1=ComboBox_GetCurSel(handle_combox1); TCHAR str1[256]; TCHAR str2[256]; TCHAR str3[256]; GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1)); GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2)); int i1=atoi(str1); int i2=atoi(str2); TCHAR S1[256]; TCHAR S2[256]; wsprintf(S1,"%i",i1); wsprintf(S2,"%i",i2); if(strcmp(str1,S1)!=0) { MessageBox(hwnd,TEXT("你晕了吗?第一个数不是一个合法的数字"),TEXT("错误"),MB_OK|MB_ICONWARNING); return; } if(strcmp(str2,S2)!=0) { MessageBox(hwnd,TEXT("你晕了吗?第二个数不是一个合法的数字"),TEXT("错误"),MB_OK|MB_ICONWARNING); return; } switch(index1) { case 0: { int i3=i1+i2; wsprintf(str3,"%i",i3); SetDlgItemText(hwnd,IDC_EDIT3,str3); } break; case 1: { int i3=i1-i2; wsprintf(str3,"%i",i3); SetDlgItemText(hwnd,IDC_EDIT3,str3); } break; case 2: { int i3=i1*i2; wsprintf(str3,"%i",i3); SetDlgItemText(hwnd,IDC_EDIT3,str3); } break; case 3: { int i3; if(0==i2) { MessageBox(hwnd,TEXT("严重错误"),TEXT("错误"),MB_OK|MB_ICONWARNING); return; } else { i3=i1/i2; wsprintf(str3,"%i",i3); SetDlgItemText(hwnd,IDC_EDIT3,str3); } } break; /*case 4: { int i3; int r2=GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2)); if(r2!=0) { MessageBox(hwnd,TEXT("不用输入"),TEXT("警告"),MB_OK); } wsprintf(str3,"%b",str1); SetDlgItemText(hwnd,IDC_EDIT3,str3); } break;*/ } } break; default: break; } } void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); }