Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4137551
  • 博文数量: 447
  • 博客积分: 1241
  • 博客等级: 中尉
  • 技术积分: 5786
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-27 06:48
个人简介

读好书,交益友

文章分类

全部博文(447)

文章存档

2023年(6)

2022年(29)

2021年(49)

2020年(16)

2019年(15)

2018年(23)

2017年(67)

2016年(42)

2015年(51)

2014年(57)

2013年(52)

2012年(35)

2011年(5)

分类: C/C++

2014-05-14 19:29:01

最近写了一个WTL的项目,发现unicode环境下,CString转为char* 还是比较麻烦的。

点击(此处)折叠或打开

  1. CString str_ReourceText;
  2.     
  3.     //get resource text
  4.         
  5.     HWND hWndResourceText = GetDlgItem(IDC_SRC);
  6.     
  7.     int int_ReourceText=::GetWindowTextLength(hWndResourceText);
  8.     
  9.     int_ReourceText++;
  10.     
  11.     LPTSTR lpStr = str_ReourceText.GetBufferSetLength(int_ReourceText);
  12.     
  13.     ::GetWindowText(hWndResourceText, lpStr, int_ReourceText);
  14.     
  15.     char *output =NULL;
  16.     char *name= (char *)malloc(int_ReourceText);
  17.     CT2A ascii(str_ReourceText);
  18.     
  19.     strcpy_s(name,int_ReourceText, ascii.m_psz);


转为 utf8

点击(此处)折叠或打开

  1. // Convert to UTF8
  2. CString str(_T("Some Unicode goodness"));
  3. CT2A ascii(str, CP_UTF8);
  4. TRACE(_T("UTF8: %S\n"), ascii.m_psz);

  5. // Convert to Thai code page
  6. CString str(_T("Some Thai text"));
  7. CT2A ascii(str, 874);
  8. TRACE(_T("Thai: %S\n"), ascii.m_psz);




阅读(1423) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~