當前位置:編程學習大全網 - 網站源碼 - vc中文顯示亂碼

vc中文顯示亂碼

CString類支持編碼轉換,使用CString完全沒有必要使用MultiByteToWideChar,因為這裏面已經內置的轉換了。

如果妳的工程是UNICODE模式,那麽str=charpoint的時候,轉換就已經發生。如果不是,那麽只要資源中指定中文字符集,那麽顯示多字節的中文也是沒有問題的。

CString類的源碼如下:

#ifdef?_UNICODE

const?CString&?CString::operator=(LPCSTR?lpsz)

{

int?nSrcLen?=?lpsz?!=?NULLlstrlenA(lpsz)?:?0;

AllocBeforeWrite(nSrcLen);

_mbstowcsz(m_pchData,?lpsz,?nSrcLen+1);//這個就是MultiByteToWideChar

ReleaseBuffer();

return?*this;

}

#else?//!_UNICODE

const?CString&?CString::operator=(LPCWSTR?lpsz)

{

int?nSrcLen?=?lpsz?!=?NULLwcslen(lpsz)?:?0;

AllocBeforeWrite(nSrcLen*2);

_wcstombsz(m_pchData,?lpsz,?(nSrcLen*2)+1);

ReleaseBuffer();

return?*this;

}

#endif?//!_UNICODE

建議妳,還是檢查壹下MYSQL裏面保存的字符串,是如何定義的字段屬性,從這裏查起。

  • 上一篇:windows10電腦顯存怎麽看
  • 下一篇:linuxkernel監控can寄存器變化
  • copyright 2024編程學習大全網