Click to See Complete Forum and Search --> : Displaying unicode characters in edit box


nick1
January 15th, 2004, 09:32 AM
My application gets some data form the database and should display it in various controls.
The problem is that those data contains some unicode characters that are shown as question marks in edit boxes and comboboxes.

For example string like this: "Abß/ß2m"
is shown as "Ab?/?2m"

I operate with wchar_t* data. When loading into the list view control it's ok. The code looks like this:
wchar_t* str = NULL;
// initialize str
// ....
LVITEMW item;
item.mask = LVIF_TEXT;
item.iItem = i;
item.iSubItem = 0;
item.pszText = str;
// ....
::SendMessage(hListWnd, LVM_INSERTITEMW, 0, (LPARAM)&item);

But when loading the same text into edit box:

wchar_t* str = NULL;
// initialize ..
SetDlgItemTextW(m_hWnd, IDC_NAME_EDIT, str);

or a combobox:

wchar_t* wch ;
// ...
::SendMessageW(hComboWnd, CB_ADDSTRING, 0, (LPARAM)wch);

all 'ß' characters are shown as '?'.

Could you please advice me any solution?
Thank You.

drzarkov
January 15th, 2004, 11:21 AM
do you conmpile your up with the _UNICODE-flag or option set?

but be aware that its better to use TCHAR, _T, CA2T and CT2A-macros. otherwise your application will crash for sure. even an app created by the wizard.

E

nick1
January 16th, 2004, 03:11 AM
> do you conmpile your up with the _UNICODE-flag or option set

No. When the problem occured application was big enough and changing character set to unicode now would require to replace all string constants from "..." to L"..." (_T"..."). I would like not to do this now if possible.

TCHAR is defined as
typedef wchar_t TCHAR;

CA2T is ATL conversion routine that is based on (uses inside)
::MultiByteToWideChar function.
But my problem is not in conversion.

The problem is in displaying TCHAR* data that contain special symbols in edit box.
Also when application is running and I try to pase the same symbols into edit box from a text editor they are replaced with '?' signs.
Is the only way to fix this migrating application to Unicode character set?

drzarkov
January 16th, 2004, 04:24 AM
TCHAR is char if you compile it with single-byte option in your compiler. Only with _UNICODE-option it is two byte wide.

Nevertheless. Thats of course no solution for your problem. As you said you already have the 2byte-strings but the edit-box doesnt view those characters right. But it seems to me that theres no way around converting all constants and make your app unicode-ready. Because there is a difference between MFC71.dll and MFC71u.dll! The one for GUI-elemts capable to handle single-byte strings - the other one is for unicode-programs.

To all other programmers in the forum: please correct me if I'm wrong!

E