您的位置:首页 > 其它

ATL与WTL中CString的使用, 利用ATLCString获得窗口的文字.

2009-10-21 20:46 288 查看
http://hi.baidu.com/icexile/blog/item/2c698efdfd653a1009244dd8.html

WTL提供的CString类在ATL中也提供了相同的类后变得有点鸡肋,并且使用WTL::CString类后,经常会出现标题所示的编译错误(不能从“WTL::CString”转换为“ATL::CSimpleString &”的问题)。

实际上ATL不仅在<atlstr.h>中提供了CString类,还在<atltypes.h>中提供了CPoint、CSize和CRect类,因此,WTL中提供的同名类变得可有可无。我认为还是用ATL中的类会好一些,毕竟WTL没有文档嘛。

因此,应该在工程头文件中包含任何WTL头文件前定义以下两行:

// 一定要注意下面的顺序

#define _WTL_NO_CSTRING
#define _WTL_NO_WTYPES

典型的声明顺序应该这样:

#include <atlbase.h>
#include <atlstr.h>
#include <atltypes.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>
#include <atlcrack.h>
#include <atlsplit.h>
#include <atlframe.h>
#include <atlgdi.h>
#include <atlctrls.h>
#include <atlctrlx.h>
#include <atlmisc.h>

#include <......等等>

 

 

// 下面是获得控件文字的代码

 CString strTemp(TEXT(""));
 m_wndEdit.GetWindowText(strTemp);
 ::MessageBox(m_hWnd, strTemp, TEXT("编辑框的内容"), MB_OK);
 return 0;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  文档 c
相关文章推荐