MFC第三课 多字节处理

  • 时间:
  • 来源:网络

    系统运维

DrawTextW (Unicode) and DrawTextA (ANSI)

参数不同

 

简单来说

unicode  是用两个字节表示所有的字符,包括字母,

ansi  是用1个字节表示字母,两个字节表示汉字等文字

 

字符串变量时ANSI使用DrawTextA

字符串变量是Unicode使用DrawTextW


CString宽字节转换成多字节字符串


 void CStringToChar(CString strSrc,char* pDest,int size)
{
  memset(pDest,0,size);
  int nLength = strSrc.GetLength();
  int nBytes = WideCharToMultiByte(CP_ACP,0,strSrc,nLength,NULL,0,NULL,NULL);
  WideCharToMultiByte(CP_OEMCP, 0, strSrc, nLength, pDest, nBytes, NULL, NULL); 
  pDest[nBytes] = 0;
};

注意:第二次调用WideCharToMultiByte主要是为了能够获取生成的长度


新网虚拟主机