Link to home
Start Free TrialLog in
Avatar of Paul Winkle
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+iOffsetX, rc.top + iPosY,thisString);      

And I get " ||||||| "  in the combo box (both edit box and dropdown).

      dc.TextOut(rc.left+iOffsetX, rc.top + iPosY,L"TESTSTRING");
works fine.

Any ideas would be helpful...I've been working this way too long.
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul Winkle
Paul Winkle

ASKER

Thanks ZOPPO,
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
                  
BOOL isIt = IsWindowUnicode(m_ComboBox.m_hWnd);

Open in new window

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
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.
Hm - ok, fine :o)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It turned out that the Combobox was defined with a non-UNICODE font what caused the issue.

Sara