Piecewise conversion of an MFC app to Unicode/MBCS
Asked Answered
R

3

5

I have a large MFC application that I am extending to allow for multi-lingual input. At the moment I need to allow the user to enter Unicode data in edit boxes on a single dialog.

Is there a way to do this without turning UNICODE or MBCS on for the entire application? I only need a small part of the application converted at the moment. Is it possible to do this piecewise, and if so, how?


Clarification: I could use ::GetWindowTextW() to get Unicode information out of the window. I am trying to figure out how to allow the user to enter Unicode text in the window. Currently, characters the user types outside of the windows-1252 codepage show up as '?'. Is there a way to fix this?

Rolfrolfe answered 24/8, 2009 at 14:39 Comment(1)
Why can't you just go full Unicode?Bitter
I
4

To allow CEdit to show Unicode characters you should create it with CreateWindowW function. I've just tested it in ANSI MFC program.

// allows Unicode characters
CreateWindowW( L"EDIT", L"", WS_CHILD|WS_VISIBLE, 10, 10, 50, 20, GetSafeHwnd(), 0, 0, 0 );

// shows Unicode characters as ?
CreateWindow( "EDIT", "", WS_CHILD|WS_VISIBLE, 10, 10, 50, 20, GetSafeHwnd(), 0, 0, 0 );

You could create all edit boxes manually in OnInitDialog function of dialog box. And later subclass them to custom CMyEdit class with Unicode support.

Indisputable answered 24/8, 2009 at 15:52 Comment(0)
B
2

Can you replace these edit boxes with rich edit controls? Then you could enter international characters even in a non-Unicode build; internally, they would be rtf-encoded, but then when you stream the text out from the control, you can use the SF_UNICODE format to get the Unicode representation.

Bosom answered 24/8, 2009 at 15:58 Comment(0)
I
0

Just a thought - you could try turning on UNICODE for your build and use ANSI calls where you need to (eg. CStringA).

(I understand that this may not be an option for you, but thought it worth pointing out that you could tackle this problem the other way round)

Ish answered 24/8, 2009 at 15:2 Comment(1)
I can't to that in this case. There would be tens of thousands of calls to hunt down and convert.Rolfrolfe

© 2022 - 2024 — McMap. All rights reserved.