//good code from CSDN
//int num1,num2,num3;
// WCHAR ch1[10],ch2[10],ch3[10]; //WCHR
//
// GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
// GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
// num1=_wtoi(ch1); //_wtoi
// num2=_wtoi(ch2);
// num3=num1+num2;
// _itow(num3,ch3,10); //_itow
// GetDlgItem(IDC_EDIT3)->SetWindowText((LPTSTR)ch3);
//good code from CSDN
/*int num1,num2,num3;
TCHAR ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=_ttoi(ch1);
num2=_ttoi(ch2);
num3=num1+num2;
_itot(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);*/
/good code From CSDN
// int num1,num2,num3;
//CString str1, str2, str3;
//GetDlgItem(IDC_EDIT1)->GetWindowText(str1);
//GetDlgItem(IDC_EDIT2)->GetWindowText(str2);
//
//num1=_ttoi((LPCTSTR)str1);
//num2=_ttoi((LPCTSTR)str2);
//num3=num1+num2;
//
//_itot(num3,(TCHAR*)str3.GetBuffer(10),10);
//str3.ReleaseBuffer();
//
//GetDlgItem(IDC_EDIT3)->SetWindowText(str3);
//当调用GetDlgItemText()时上述三种情况如下
//int num1,num2,num3;
//TCHAR ch1[10],ch2[10],ch3[10];
//GetDlgItemText(IDC_EDIT1,ch1,10);
//GetDlgItemText(IDC_EDIT2,ch2,10);
//num1=_ttoi(ch1);
//num2=_ttoi(ch2);
//num3=num1+num2;
//_itot(num3,ch3,10);
//SetDlgItemText(IDC_EDIT3,ch3);
//int num1,num2,num3;
//WCHAR ch1[10],ch2[10],ch3[10];
//GetDlgItemText(IDC_EDIT1,ch1,10);
//GetDlgItemText(IDC_EDIT2,ch2,10);
//num1=_wtoi(ch1);
//num2=_wtoi(ch2);
//num3=num1+num2;
//_itow(num3,ch3,10);
//SetDlgItemText(IDC_EDIT3,ch3);
int num1,num2,num3;
CString str1,str2,str3;
GetDlgItemText(IDC_EDIT1,(LPTSTR)str1.GetBuffer(10),10);
GetDlgItemText(IDC_EDIT2,(LPTSTR)str2.GetBuffer(10),10);
num1=_ttoi((LPTSTR)str1.GetBuffer(10));
num2=_ttoi((LPTSTR)str2.GetBuffer(10));
num3=num1+num2;
_itot(num3,(TCHAR*)str3.GetBuffer(10),10);
str3.ReleaseBuffer();
SetDlgItemText(IDC_EDIT3,str3);
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText((LPTSTR)ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText((LPTSTR)ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num2+num1;
itoa(num3,(char*)ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText((LPTSTR)ch3);
最终问题出在不是强制类型转换上,而是
1。char count[6]; 改成wchar count[6];
2.把m_CharNumber.SetWindowTextW(count); 改成
m_CharNumber.SetWindowText(count);把W去掉,还有些类似的函数都要去掉,在项目(project)->属性(property)中通常(general)中有个字符选项(我是英文版的,中文叫什么我不知道,不知道你什么版本),里面有选用多字节还是Unicode改成多字节(Multi-Byte)
使用第2中方法中在项目(project)->属性(property)中通常(general)中有个字符选项(我是英文版的,中文叫什么我不知道,不知道你什么版本),里面有选用多字节还是Unicode改成多字节(Multi-Byte)