编写的是一个输入文字的MFC程序。
程序在想要WM_CHAR消息的代码。。。。。。。。。。。。。
void CTestView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
CFont font;
font.CreatePointFont(300, _T("华文楷体"), NULL);
CFont *pOldFont = dc.SelectObject(&font);
TEXTMETRIC tx;
dc.GetTextMetrics(&tx);
if (13 == nChar)
{
str.Empty();
m_inputpt.y += tx.tmHeight;
}
else if (0X08 == nChar)
{
COLORREF col = dc.SetTextColor(dc.GetBkColor());
dc.TextOutW(m_inputpt.x, m_inputpt.y, str);
str = str.Left(str.GetLength() - 1);
dc.SetTextColor(col);
}
else
{
str += (char)nChar;
}
CSize sz = dc.GetTextExtent(str);
CPoint pt;
pt.x = m_inputpt.x + sz.cx;
pt.y = m_inputpt.y;
SetCaretPos(pt);
dc.TextOutW(m_inputpt.x, m_inputpt.y, str);
dc.SelectObject(pOldFont);
CView::OnChar(nChar, nRepCnt, nFlags);
}
这是VC++6.0的截图

这是VS2013的截图

有什么解决办法吗?我知道它们的字符集不同,可是在VS2013写MFC程序也不能用多字节字符集啊
------解决思路----------------------
Unicode 字符集是系统在显示文字时使用的字符集,如果使用了多字符集,那么最终也会在显示前转换成Unicode字符集
------解决思路----------------------
str += (TCHAR)nChar; //char 改为 TCHAR 试试看
------解决思路----------------------
可以转换 下面是我自己用的 un转换为as
string Cptype::converToMultiChar(const wstring& str)
{
char* pElementText;
int iTextLen;
iTextLen = WideCharToMultiByte(CP_OEMCP,0,str.c_str(),-1,NULL,0,NULL,NULL);
pElementText = new char[iTextLen+1];
memset((void*)pElementText,0,sizeof(char)*(iTextLen+1));
WideCharToMultiByte(CP_OEMCP,0,str.c_str(),-1,pElementText,iTextLen+1,NULL,NULL);
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}