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

来源:互联网 发布:上古卷轴5enb优化 编辑:程序博客网 时间:2024/04/30 12:53

转自:http://blog.csdn.net/bagboy_taobao_com/article/details/4710315

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;


0 0
原创粉丝点击