关于减法计算器的问题
#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)
{
return TRUE;
}
BOOL IsInt(TCHAR* str)
{
int i = atoi(str);
TCHAR strtemp[256];
wsprintf(strtemp,"%i",i);
if(strcmp(str,strtemp) != 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
TCHAR str1[256];
TCHAR str2[256];
GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1));
GetDlgItemText(hwnd,IDC_EDIT1,str2,sizeof(str2));
int i1 = atoi(str1);
int i2 = atoi(str2);
if(IsInt(str1))
{
MessageBox(hwnd,TEXT("输入的第一个数不是正确的输入!"),TEXT("错误"),MB_OK|MB_ICONERROR);
return;
}
if(IsInt(str2))
{
MessageBox(hwnd,TEXT("输入的第二个数不是正确的输入!"),TEXT("错误"),MB_OK|MB_ICONERROR);
return;
}
int i3 = i1 - i2;
TCHAR str3[256];
wsprintf(str3,"%i",i3);
SetDlgItemText(hwnd,IDC_EDIT3,str3);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
其实就是一个减法,但是有两个问题,第二个数如果不是整数测不出来和计算结果不对,求大神指点