BOOL isinteger(TCHAR *str)
{
//判断输入是否为整数
TCHAR strtmp[256];
int str_int = atoi(str);
wsprintf(strtmp,"%i",str_int);
if (!strcmp(strtmp,str))
{
return TRUE;
}
else
{
return FALSE;
}
}
//各个按钮事件
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_COUNT:
{
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(!isinteger(str1))
{
MessageBox(NULL,TEXT("第一个输入值非法"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
if(!isinteger(str2))
{
MessageBox(NULL,TEXT("第二个输入值非法"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
int i1 = atoi(str1);
int i2 = atoi(str2);
TCHAR str3[256];
SetDlgItemText(hwnd,IDC_RESULT,itoa((i1+i2),str3,10));
}
break;
case IDC_INT_ER_TRANS:
{
TCHAR str1[256],str2[256];
int k = GetDlgItemText(hwnd,IDC_DATA4,str1,sizeof(str1));
if (0==k)
{
MessageBox(NULL,TEXT("输入不能为空"),TEXT("出错"),MB_ICONERROR|MB_OK);
return;
}
if (!isinteger(str1))
{
MessageBox(NULL,TEXT("输入值非法!"),TEXT("出错"),MB_ICONERROR|MB_OK);
}
int i1 = atoi(str1);
SetDlgItemText(hwnd,IDC_TRANS_RESULT,itoa(i1,str2,2));
}
break;
case IDC_QUIT:
{
EndDialog(hwnd, 0);
}
break;
default:
break;
}
}
阅读(1117) | 评论(0) | 转发(0) |