GetWindowText和SetWindowTextW以及SetWindowText

starryplayer 2011-11-28 11:24:03
代码如下:
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”,为什么???两者之间有什么样的差别呢???
...全文
1259 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
LZNJ06 2011-12-05
  • 打赏
  • 举报
回复
找本windows 编程序书看看,也是很不错的选择了。
starryplayer 2011-12-05
  • 打赏
  • 举报
回复
“LRESULT”是什么类型,返回“0”可以吗???

LRESULT CChatDlg::OnRecvData(WPARAM wParam,LPARAM lParam)
{
//取出接收到的数据
CString str=(char*)lParam;
CString strTemp;

//获得已有数据
GetDlgItemText(IDC_EDIT_RECV,strTemp);
str+="\r\n";
str+=strTemp;
//显示所有接收到的数据
SetDlgItemText(IDC_EDIT_RECEV,str);
return 0;
}
starryplayer 2011-12-05
  • 打赏
  • 举报
回复
“LRESULT”是什么类型,返回“0”可以吗???

LRESULT CChatDlg::OnRecvData(WPARAM wParam,LPARAM lParam)
{
//取出接收到的数据
CString str=(char*)lParam;
CString strTemp;

//获得已有数据
GetDlgItemText(IDC_EDIT_RECV,strTemp);
str+="\r\n";
str+=strTemp;
//显示所有接收到的数据
SetDlgItemText(IDC_EDIT_RECEV,str);
return 0;
}
yyps 2011-11-29
  • 打赏
  • 举报
回复
char * 和 lpctstr 可不一应哦,需要转化的。
fyten1985 2011-11-29
  • 打赏
  • 举报
回复
编译环境中有个项目属性其中可以设置Unicode字符集和多字节字符集
Unicode对应TCHAR
多字节对应char

对于函数来说一般都有最后带W的是对应Unicode 最后带A的是对应多字节

比如SetWindowTextW 这个函数就是对应Unicode 他的输入参数就需要是TCHAR
buyong 2011-11-29
  • 打赏
  • 举报
回复
你把工程属性改成多字节字符集
wangweixu520 2011-11-28
  • 打赏
  • 举报
回复
		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);
shen_wei 2011-11-28
  • 打赏
  • 举报
回复
你看你的编译环境是什么
多字节,还是Unicode。。
一桶姜山 2011-11-28
  • 打赏
  • 举报
回复
你F12找一下SetWindowText的定义应该会发现其实它是根据工程所用字符集来调用SetWindowTextW或SetWindowTextA,而xp以上系统内部只有SetWindowTextW一个函数,SetWindowTextA也只是把参数转换后再调用SetWindowTextW而已
Eleven 2011-11-28
  • 打赏
  • 举报
回复
下面的atoi()这些函数也需要修改_ttoi();
Eleven 2011-11-28
  • 打赏
  • 举报
回复
把你的char换成TCHAR
starryplayer 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wangweixu520 的回复:]

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);
n……
[/Quote]

编译环境用的是VS2010。。。
为什么要用“TCHAR”???

“_wtoi”中“_w”是什么意思???

“_itow”中为什么要用“_”呢???

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧