rich edit control is displayed question mark when enter Chinese characters ?
Problem:
I have a rich edit control in which am entering chinese character.I Am using GetDlgItemText() to retrieve the characters from rich edit control in avariable of type CString, but the variable doesntshow the chinese character. Instead "???" is displayed. Does anybody have any idea about the
problem?
he internals of rich edit control uses Unicode. But when you call GetDlgItemText() and your code is not Unicode then it will try to convert the Unicode to the current codepage of the process. In your case I think it is trying to convert from UNICODE to ASCII (or CP1252 (Latin)) and hence it turns all the Chinese Unicode char's to question mark.
The solution is to make sure you have /D_UNICODE in your compiler defines. Defining this will make rest of your code handle Unicode as well. (Assuming you used TCHAR everwhere). If you have never used this flag and you have a big code-base this cound be a tedious task, fixing all the compiler errors. But worth it if you have support multiple languages.
The other option is to initialize your current code page to Chinese so when it does the conversion it can still recognize the characters. See the definition of macro's like W2A() A2W() or win32 API's like WideCharToMultiByte() MultiByteToWideChar() to convert Unicode to multi-byte without turning them into question mark. You need to pass the appropriate code page.
I have a rich edit control in which am entering chinese character.I Am using GetDlgItemText() to retrieve the characters from rich edit control in avariable of type CString, but the variable doesntshow the chinese character. Instead "???" is displayed. Does anybody have any idea about the
problem?
he internals of rich edit control uses Unicode. But when you call GetDlgItemText() and your code is not Unicode then it will try to convert the Unicode to the current codepage of the process. In your case I think it is trying to convert from UNICODE to ASCII (or CP1252 (Latin)) and hence it turns all the Chinese Unicode char's to question mark.
The solution is to make sure you have /D_UNICODE in your compiler defines. Defining this will make rest of your code handle Unicode as well. (Assuming you used TCHAR everwhere). If you have never used this flag and you have a big code-base this cound be a tedious task, fixing all the compiler errors. But worth it if you have support multiple languages.
The other option is to initialize your current code page to Chinese so when it does the conversion it can still recognize the characters. See the definition of macro's like W2A() A2W() or win32 API's like WideCharToMultiByte() MultiByteToWideChar() to convert Unicode to multi-byte without turning them into question mark. You need to pass the appropriate code page.
0 Comments:
Post a Comment
<< Home