CEdit :: GetLine()Windows 7 [英] CEdit::GetLine() windows 7

查看:166
本文介绍了CEdit :: GetLine()Windows 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码段,其中m_edit是CEdit控件:

I have the following segment of code where m_edit is a CEdit control:

TCHAR lpsz[MAX_PATH+1];

// get the edit box text
m_edit.GetLine(0,lpsz, MAX_PATH); 

这在运行Windows XP及更早版本的计算机上完美运行.我尚未在Vista中进行测试,但是在Windows 7上,lpsz会在其中插入垃圾unicode字符(有时还会插入实际文本).您对这里发生的事情有任何了解吗?

This works perfectly on computers running Windows XP and earlier. I have not tested this in Vista, but on Windows 7, lpsz gets junk unicode characters inserted into it (as well as the actual text sometimes). Any idea as to what is going on here?

推荐答案

既然您使用的是MFC,为什么不利用它的CString类呢?这是许多程序员被MFC吸引的原因之一,因为它使处理字符串变得非常容易.

Since you're using MFC, why aren't you taking advantage of its CString class? That's one of the reasons many programmers were drawn to MFC, because it makes working with strings so much easier.

例如,您可以简单地写:

For example, you could simply write:

int len = m_edit.LineLength(m_edit.LineIndex(0));
CString path;
LPTSTR p = path.GetBuffer(len);
m_edit.GetLine(0, p, len);
path.ReleaseBuffer();

(上面的代码经过测试可以在Windows 7上正常工作.)

(The above code is tested to work fine on Windows 7.)

请注意,复制的行不包含空终止符(请参见文档).这可以解释您在更高版本的Windows中看到的无用字符.

Note that the copied line does not contain a null-termination character (see the "Remarks" section in the documentation). That could explain the nonsense characters you're seeing in later versions of Windows.

这篇关于CEdit :: GetLine()Windows 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆