做这个东西之前一直很鄙视微软的东西,我想应该是跟着网上一些说法有关,所以一直搞着linux的东西,但是发现自己还没有鄙视的资本,只有高手才有,所以从零开始先搞一下vc做一些工具游戏之类的。存在及合理,还没有到否定这些技术的境界。
win32对话框开发的很小的计算器程序。
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 2 { 3 switch(uMsg) 4 { 5 HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); 6 HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); 7 HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); 8 } 9 10 return FALSE; 11 } 12 13 BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) 14 { 15 HWND hwnd1 = GetDlgItem(hwnd,IDC_COMBO1); 16 ComboBox_InsertString(hwnd1,-1,TEXT("+")); 17 ComboBox_InsertString(hwnd1,-1,TEXT("-")); 18 ComboBox_InsertString(hwnd1,-1,TEXT("*")); 19 ComboBox_InsertString(hwnd1,-1,TEXT("/")); 20 return TRUE; 21 } 22 23 void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) 24 { 25 switch(id) 26 { 27 case IDC_OK: 28 { 29 TCHAR str1[256]; 30 TCHAR str2[256]; 31 GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1)); 32 GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2)); 33 int i1 = atoi(str1); 34 int i2 = atoi(str2); 35 int i3 = 0; 36 HWND hwnd1 = GetDlgItem(hwnd,IDC_COMBO1); 37 int ret = ComboBox_GetCurSel(hwnd1); 38 switch(ret) 39 { 40 case 0: 41 { 42 i3 = i1 + i2; 43 } 44 break; 45 case 1: 46 { 47 i3 = i1 - i2; 48 } 49 break; 50 case 2: 51 { 52 i3 = i1 * i2; 53 } 54 break; 55 case 3: 56 { 57 i3 = i1 / i2; 58 } 59 break; 60 } 61 TCHAR str3[256]; 62 itoa(i3,str3,10); 63 SetDlgItemText(hwnd,IDC_EDIT3,str3); 64 } 65 break; 66 default: 67 break; 68 } 69 } 70 71 void Main_OnClose(HWND hwnd) 72 { 73 EndDialog(hwnd, 0); 74 }
运行结果: