还是把这个小工具最主要的两个转换函数的源码贴出来吧:
/** * GBK->UNICODE */ void CGBK2UnicodeDlg::OnConvertText() { //我的视图 鎴戠殑瑙嗗浘 UpdateData(TRUE); int wc = WideCharToMultiByte(CP_UTF8,0,m_txt_input.AllocSysString(),m_txt_input.GetLength(),0,0,NULL,NULL); TCHAR* sUnicode = new TCHAR[wc+1]; sUnicode[wc] = 0; WideCharToMultiByte(CP_UTF8,0,m_txt_input.AllocSysString(),m_txt_input.GetLength(),sUnicode,wc,NULL,NULL); SetDlgItemText(IDC_UNICODE_TEXT, sUnicode); if(sUnicode) delete[] sUnicode; GetDlgItem(IDC_GBK_TEXT)->SetFocus(); } /** * UNICODE->GBK */ void CGBK2UnicodeDlg::OnReverseText() { UpdateData(TRUE); int wc = MultiByteToWideChar(CP_UTF8,0,m_txt_input,m_txt_input.GetLength(),0,0); wchar_t* sUnicode = new wchar_t[wc+1]; sUnicode[wc] = 0; MultiByteToWideChar(CP_UTF8,0,m_txt_input,m_txt_input.GetLength(),sUnicode,wc); CString unicode(sUnicode); SetDlgItemText(IDC_UNICODE_TEXT, unicode); if(sUnicode) delete[] sUnicode; GetDlgItem(IDC_GBK_TEXT)->SetFocus(); }
[Edit on 2004-09-21 14:54:28 By 刘冬] |