Displaying WChar string in non-Unicode Project.
Hi,
I am trying to display a wide char string to an Edit box. My prject setting is MBCS. Is it possible to display Wchar string in non-unicode project?
If so Please let me know.
For setting unicode font :
CDC *pDC = GetDC();
// create UNICODE font
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = MulDiv(12, ::GetDeviceCaps(pDC->m_hDC, LOGPIXELSY), 72);
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
_tcscpy(lf.lfFaceName, _T("Lucida Sans Unicode"));
m_font.CreateFontIndirect(&lf);
// apply the font to the controls
m_edit.SetFont(&m_font);
For Displaying text :
wchar_t str[10];
str[0]=0x41;
str[1]=0x42;
str[2]=0x284;
str[3]=0x44;
str[4]=0x45;
str[5]=0x46;
str[6]=0x47;
str[7]=0x48;
str[8]=0x49;
str[9]=0x00;
::SetWindowTextW(m_edit.m_hWnd,(LPCWSTR)str);
Plz help.
Thanks.
# 2 Re: Displaying WChar string in non-Unicode Project.
Hi,
Thanks for the reply.
It displays string as "AB?DEFGHI".
In Lucida san Unicode font instead of square box. it should display the char combinition of
'J' + 'f' + '='. that is unicode value of 0x284. You can refer to Character map in Programs=>Accessories=>system tools=>Character map. select font as Lucida san Unicode. and check character for U+0284 .
I am trying to display that character in my string.It displays the same perfectly if your project setting is _UNICODE.
Is my approach wronge? please let me know.
Regards,
Nilesh.
# 3 Re: Displaying WChar string in non-Unicode Project.
Hi,
I am able to display the unicode string in EditBox only after creating the EditBox using CreateWindowExW() API.
Now I want to display the same string in EditBox Created using Resource Editor.
May be While creating EditBox through rc file. It might call API in following sequence.
CEdit::Create() => CWnd::Create() => CWnd::CreateWindow() => ::CreateWindow() or ::CreateWindowEx()
Can we modify this flow so that ultimately last call will be ::CreateWindowW() or ::CreateWindowExW()?
Plz Help...
# 4 Re: Displaying WChar string in non-Unicode Project.
No, you cannot do it for control on the dialog template.
As a workaround you could create (using CreateWindowExW) the new edit control with the same size and position and use it instead of the original one (just hide the original control!).
BTW, Why don't you want to create a UNICODE project?
# 5 Re: Displaying WChar string in non-Unicode Project.
Hi Victor,
Thanks a lot for reply.
My client and sever are recently changed to UNICODE. But inhouse developed libraries are not UNICODE. The dialog Box in which I am trying to display the UNICODE text (received by server), is SBCS.
And we will going to covert libraries to UNICODE in near future.
But till then I was checking possibility of Displaying UNICODE data in SBCS application.
Regards,
Nilesh.