RejiKumar
August 6th, 2007, 07:39 AM
Hi,
I am using Graphics::DrawString method to draw text on my MFC dialog based application (with GDI+ support). DrawString method takes only a WCHAR* as its first input parameter. My project settings, Character set is set to "Use Multi-Byte Character Set" and this cannot be changed. I have a CString variable and i use the following code to convert that into WCHAR*:-
LPWSTR lpszW = new WCHAR[sText.GetLength()+1]; //where sText is the CString variable.
LPTSTR lpstr = sText.GetBuffer(sText.GetLenght());
int nLen = MultiByteToWideChar(CP_ACP,0,lpstr,-1,NULL,NULL);
MultiByteToWideChar(CP_ACP,0,lpstr,-1,lpszW,nLen);
Graphics graphics(hDC);
graphics.DrawString(lpszW,nLen,font,rectF,&format,&brush);
This works fine in English Language. But in Japanese OS, my sText is a Japanese string and on the dialog this code displays junk characters. Why is it happening so?
Thanks in advance,
Reji
I am using Graphics::DrawString method to draw text on my MFC dialog based application (with GDI+ support). DrawString method takes only a WCHAR* as its first input parameter. My project settings, Character set is set to "Use Multi-Byte Character Set" and this cannot be changed. I have a CString variable and i use the following code to convert that into WCHAR*:-
LPWSTR lpszW = new WCHAR[sText.GetLength()+1]; //where sText is the CString variable.
LPTSTR lpstr = sText.GetBuffer(sText.GetLenght());
int nLen = MultiByteToWideChar(CP_ACP,0,lpstr,-1,NULL,NULL);
MultiByteToWideChar(CP_ACP,0,lpstr,-1,lpszW,nLen);
Graphics graphics(hDC);
graphics.DrawString(lpszW,nLen,font,rectF,&format,&brush);
This works fine in English Language. But in Japanese OS, my sText is a Japanese string and on the dialog this code displays junk characters. Why is it happening so?
Thanks in advance,
Reji