Paul Winkle
asked on
MFC CComboBox will not display wide characters
MFC CComboBox won't display wide characters.
I'm using VS 2008, UNICODE is defined in the build and all of the prompts and other strings in the app are coming out fine.
The first try I just added the strings like any combobox and the display and dropdown showed a black line for each
character like the font was wrong.
I tried to SetFont to no avail.
I went to an owner-drawn combo box with no change.
The string shows correctly in the debugger (both in the watch and in the hover box).
the string is "Активна" and, copied from the debugger window, shows up fine in WordPad.
In DrawItem I did:
CString fontName;
CDC dc;
dc.Attach(lpDrawItemStruct ->hDC);
dc.GetTextFace(fontName);
//fontName is "MS Sans Serif" which is is expected and what I am using in the rest of my app and is reported to support Cyrillic.
//The rest is :
CString thisString;
GetLBText(lpDrawItemStruct ->itemID, thisString);
//note that at this point, thisString shows to have the correct string in the debugger
dc.TextOut(rc.left+iOffset X, rc.top + iPosY,thisString);
And I get " ||||||| " in the combo box (both edit box and dropdown).
dc.TextOut(rc.left+iOffset X, rc.top + iPosY,L"TESTSTRING");
works fine.
Any ideas would be helpful...I've been working this way too long.
I'm using VS 2008, UNICODE is defined in the build and all of the prompts and other strings in the app are coming out fine.
The first try I just added the strings like any combobox and the display and dropdown showed a black line for each
character like the font was wrong.
I tried to SetFont to no avail.
I went to an owner-drawn combo box with no change.
The string shows correctly in the debugger (both in the watch and in the hover box).
the string is "Активна" and, copied from the debugger window, shows up fine in WordPad.
In DrawItem I did:
CString fontName;
CDC dc;
dc.Attach(lpDrawItemStruct
dc.GetTextFace(fontName);
//fontName is "MS Sans Serif" which is is expected and what I am using in the rest of my app and is reported to support Cyrillic.
//The rest is :
CString thisString;
GetLBText(lpDrawItemStruct
//note that at this point, thisString shows to have the correct string in the debugger
dc.TextOut(rc.left+iOffset
And I get " ||||||| " in the combo box (both edit box and dropdown).
dc.TextOut(rc.left+iOffset
works fine.
Any ideas would be helpful...I've been working this way too long.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Property/ Character Set is set to "Use Unicode Character Set"
Looking at the Command Line window, it shows: /D "_AFXDLL" /D "_UNICODE" /D "UNICODE"
To my knowledge, that should cover it.
'DISPLAY_RICHEDIT_STYLE' turns out to be my #define for a combination of styles to use on a richedit edit box.
59630b15.jpg
Looking at the Command Line window, it shows: /D "_AFXDLL" /D "_UNICODE" /D "UNICODE"
To my knowledge, that should cover it.
BOOL isIt = IsWindowUnicode(m_ComboBox.m_hWnd);
Returns 1.'DISPLAY_RICHEDIT_STYLE' turns out to be my #define for a combination of styles to use on a richedit edit box.
59630b15.jpg
ASKER
This morning I determined that "MS Sans Serif" font works wonderfully in a richedit box but puts '|' for each character in a combo box.
On the other hand, the font "Microsoft Sans Serif" appears to work correctly.
Thank you Zoppo. You sent me in a different direction that allowed me to discover this anomaly.
On the other hand, the font "Microsoft Sans Serif" appears to work correctly.
Thank you Zoppo. You sent me in a different direction that allowed me to discover this anomaly.
Hm - ok, fine :o)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For future searchers...this is also what happens when the font is destroyed before the combo box.
The object drops back to a standard system font that won't handle multiple languages correctly.
I did not spend the time to determine if that was my root cause of the above issue or not.
I don't think it is because I downloaded a sample code for owner drawn multiple fonts,
changed the string to Cyrillic and found that MS and Microsoft fonts are handled differently.
The object drops back to a standard system font that won't handle multiple languages correctly.
I did not spend the time to determine if that was my root cause of the above issue or not.
I don't think it is because I downloaded a sample code for owner drawn multiple fonts,
changed the string to Cyrillic and found that MS and Microsoft fonts are handled differently.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It turned out that the Combobox was defined with a non-UNICODE font what caused the issue.
Sara
Sara
ASKER
I have never heard of a 'Unicode Window' but I will check.
I do know that I had to use 'DISPLAY_RICHEDIT_STYLE' style to get a wide char edit box on the same dialog.
I will check as soon as I can.
paulw