www.gusucode.com > 超级VC++整数计算器源码,支持10、2、8、16进制转换源码程序 > 超级VC++整数计算器源码,支持10、2、8、16进制转换源码程序/code/MainDlg.cpp
#include "stdafx.h" #include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" #include <string> //Download by http://www.NewXing.com bool check(TCHAR *str) { TCHAR strtem[256]; int n=atoi(str); wsprintf(strtem,"%d",n); if(strcmp(str,strtem)!=0) { return FALSE; } return TRUE; } 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) { return TRUE; } void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { switch(id) { case IDC_OK1: { TCHAR str1[256],str2[256],str3[256],str4[256],str5[256],str6[256]; GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1)); if(check(str1)==FALSE) { MessageBox(hwnd,TEXT("The first value is error!"),TEXT("ERROR"),MB_ICONWARNING); return; } GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2)); if(check(str2)==FALSE) { MessageBox(hwnd,TEXT("The second value is error"),TEXT("ERROR"),MB_OK); return; } int i1=atoi(str1); int i2=atoi(str2); int i3=i1+i2; //wsprintf(str3,"%d",i3); itoa(i3,str3,10); SetDlgItemText(hwnd,IDC_EDIT3,str3); itoa(i3,str4,2); SetDlgItemText(hwnd,IDC_EDIT4,str4); itoa(i3,str5,8); SetDlgItemText(hwnd,IDC_EDIT5,str5); itoa(i3,str6,16); SetDlgItemText(hwnd,IDC_EDIT6,str6); break; } case IDC_OK2: { TCHAR str1[256],str2[256],str3[256],str4[256],str5[256],str6[256]; GetDlgItemText(hwnd,EDITA,str1,sizeof(str1)); if(check(str1)==FALSE) { MessageBox(hwnd,TEXT("The first value is error"),TEXT("ERROR"),MB_OK); return; } GetDlgItemText(hwnd,EDIAB,str2,sizeof(str2)); if(check(str2)==FALSE) { MessageBox(hwnd,TEXT("The second value is error"),TEXT("ERROR"),MB_OK); return; } int i1=atoi(str1); int i2=atoi(str2); int i3=i1-i2; //wsprintf(str3,"%d",i3); itoa(i3,str3,10); SetDlgItemText(hwnd,IDC_EDIT3,str3); itoa(i3,str4,2); SetDlgItemText(hwnd,IDC_EDIT4,str4); itoa(i3,str5,8); SetDlgItemText(hwnd,IDC_EDIT5,str5); itoa(i3,str6,16); SetDlgItemText(hwnd,IDC_EDIT6,str6); break; } case IDC_OK3: { TCHAR str1[256],str2[256],str3[256],str4[256],str5[256],str6[256]; GetDlgItemText(hwnd,EDITC,str1,sizeof(str1)); if(check(str1)==FALSE) { MessageBox(hwnd,TEXT("The first value is error"),TEXT("ERROR"),MB_OK); return; } GetDlgItemText(hwnd,EDITD,str2,sizeof(str2)); if(check(str2)==FALSE) { MessageBox(hwnd,TEXT("The second value is error"),TEXT("ERROR"),MB_OK); return; } int i1=atoi(str1); int i2=atoi(str2); int i3=i1*i2; //wsprintf(str3,"%d",i3); itoa(i3,str3,10); SetDlgItemText(hwnd,IDC_EDIT3,str3); itoa(i3,str4,2); SetDlgItemText(hwnd,IDC_EDIT4,str4); itoa(i3,str5,8); SetDlgItemText(hwnd,IDC_EDIT5,str5); itoa(i3,str6,16); SetDlgItemText(hwnd,IDC_EDIT6,str6); break; } case IDC_OK4: { TCHAR str1[256],str2[256],str3[256],str4[256],str5[256],str6[256]; GetDlgItemText(hwnd,EDITE,str1,sizeof(str1)); if(check(str1)==FALSE) { MessageBox(hwnd,TEXT("The first value is error"),TEXT("ERROR"),MB_OK); return; } GetDlgItemText(hwnd,EDITF,str2,sizeof(str2)); if(check(str2)==FALSE) { MessageBox(hwnd,TEXT("The second value is error"),TEXT("ERROR"),MB_OK); return; } int i1=atoi(str1); int i2=atoi(str2); int i3=i1/i2; //wsprintf(str3,"%d",i3); itoa(i3,str3,10); SetDlgItemText(hwnd,IDC_EDIT3,str3); itoa(i3,str4,2); SetDlgItemText(hwnd,IDC_EDIT4,str4); itoa(i3,str5,8); SetDlgItemText(hwnd,IDC_EDIT5,str5); itoa(i3,str6,16); SetDlgItemText(hwnd,IDC_EDIT6,str6); break; } case IDC_ABOUT: { MessageBox(hwnd,TEXT("武士杰 QQ354075962\n此软件开源,不可用于逆向工程,否则后果自负!"), TEXT("关于"),NULL); } default: break; } } void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); }