+ -
当前位置:首页 → 问答吧 → GetWindowText和SetWindowTextW以及SetWindowText

GetWindowText和SetWindowTextW以及SetWindowText

时间:2011-11-28

来源:互联网

代码如下:
void CTestDlg::OnClickedBtnSum()
{
// TODO: Add your control notification handler code here
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
问题一:“->”处提示错误,信息如下,
1 IntelliSense: no instance of overloaded function "CWnd::GetWindowTextW" matches the argument list c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\mybole\mybole\testdlg.cpp 102 23 Mybole

“10”处提示错误,信息如下:
2 IntelliSense: too many arguments in function call c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\mybole\mybole\testdlg.cpp 102 43 Mybole


GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=atoi(ch3);
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);

问题二:“ch3”处提示错误,信息如下:
5 IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCTSTR" c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\mybole\mybole\testdlg.cpp 108 39 Mybole

如果将“ch3”改为“_T(ch3)”,则会提示错误:
5 IntelliSense: identifier "Lch3" is undefined c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\mybole\mybole\testdlg.cpp 108 39 Mybole

这是怎么回事,应该怎样修改???



}

问题三:VS2010智能提示方法“SetWindowTextW”而不是“GetWindowText”,为什么???两者之间有什么样的差别呢???

作者: starryplayer   发布时间: 2011-11-28

把你的char换成TCHAR

作者: VisualEleven   发布时间: 2011-11-28

下面的atoi()这些函数也需要修改_ttoi();

作者: VisualEleven   发布时间: 2011-11-28

你F12找一下SetWindowText的定义应该会发现其实它是根据工程所用字符集来调用SetWindowTextW或SetWindowTextA,而xp以上系统内部只有SetWindowTextW一个函数,SetWindowTextA也只是把参数转换后再调用SetWindowTextW而已

作者: paulcxz   发布时间: 2011-11-28

你看你的编译环境是什么
多字节,还是Unicode。。

作者: shen_wei   发布时间: 2011-11-28

C/C++ code
        int num1,num2,num3;
        TCHAR ch1[10],ch2[10],ch3[10];
        GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);



        GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
        num1=_wtoi(ch1);
        num2=_wtoi(ch2);
        num3=_wtoi(ch3);
        _itow(num3,ch3,10);
        GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);

作者: wangweixu520   发布时间: 2011-11-28