Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hi
 
I have wrote a VC++ project . in design mode for interface of program , I write Persian in caption field and I run the project , But in run mode the Texts is shown " ?????? "
 
How can I fix it?
Posted 9-Apr-13 12:38pm
hor_313627
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Ever heard of Unicode and how it works?
Please see:
http://en.wikipedia.org/wiki/Unicode[^],
http://unicode.org/[^].
 
Unicode is not encoding. One thing you need to know is that on Windows memory representation of Unicode text is UTF-16LE. Please see:
http://www.unicode.org/faq/utf_bom.html[^].
 
About Unicode and C++:
http://www.i18nguy.com/unicode/c-unicode.html[^],
http://msdn.microsoft.com/en-us/library/1by39td3%28v=vs.110%29.aspx[^].
 
Unicode with MFC: http://msdn.microsoft.com/en-us/library/wsdfs47e%28v=vs.110%29.aspx[^].
 
—SA
  Permalink  
v2
Comments
Espen Harlinn at 9-Apr-13 20:07pm
   
5'ed! L"Unicode text using escape codes"
Sergey Alexandrovich Kryukov at 9-Apr-13 20:36pm
   
Thank you, Espen.
Frankly, at this moment of time its hard for me to understand what escape codes did you mean, but I'm very glad to hear from you.
—SA
Espen Harlinn at 10-Apr-13 4:14am
   
OP may have trouble entering the Persian text in his editor and may have to use escape sequences to get the text he wants.
 
The escape \xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively
Sergey Alexandrovich Kryukov at 10-Apr-13 9:46am
   
Oh yes, but it's not advisable to enter hard-coded text in the code, even if this is a part of UI. There are resources for that purpose...
—SA
Espen Harlinn at 10-Apr-13 9:48am
   
Perhaps we should mention that he needs to use a font that supports the required characters too?
Sergey Alexandrovich Kryukov at 10-Apr-13 9:59am
   
Oh yes, this too, thank you for the note.
I would note that nearly all modern platforms support Perso-Arabic script (character repertoire) by default; any with wide font support of Unicode will support it.
—SA
Espen Harlinn at 10-Apr-13 10:00am
   
That's useful, thanks :)
Sergey Alexandrovich Kryukov at 10-Apr-13 10:27am
   
:-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi.
 
Add this two simple functions and use its.
 
void MakeUnicodeString(CStringW &cstrW, const char* multibyte)
{
int nbytes = MultiByteToWideChar(CP_ACP,0,multibyte,-1,0,0);
WCHAR *wstr = new WCHAR[nbytes+2];
MultiByteToWideChar(CP_ACP,0,multibyte,-1,wstr,nbytes);
wstr[nbytes]=0;
cstrW = wstr;
delete [] wstr;
}
 
void MakeAnsiString(CString &cstr, const WCHAR* wide)
{
int nbytes = WideCharToMultiByte(CP_ACP,0,wide,-1,0,0,0,0);
char *str = new char[nbytes+2];
WideCharToMultiByte(CP_ACP,0,wide,-1,str,nbytes,0,0);
str[nbytes]=0;
cstr = str;
delete [] str;
}
 
Write me for any questions in google++ or blog:
http://strongcpp.blogspot.ru/[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 260
1 Afzaal Ahmad Zeeshan 252
2 OriginalGriff 251
3 Mathew Soji 234
4 Maciej Los 230
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100