Multibyte character set in an MFC application

I have an MFC application in which I want to add internationalization support. The project is configured to use a "multibyte character set" ("Unicode character set" is not an option in my situation).

Now, I would expect the CWnd :: OnChar () function to send me multibyte characters if I set my keyboard to some foreign language, but it looks like it doesn't. The OnChar () function always sends me a 1 byte character in its nChar variable.

I thought the _getmbcp () function would give me the current page of code for the application, but this function always returns 0.

Any advice would be appreciated.

0


source to share


5 answers


And help here? Multibyte Functions in Microsoft C Run-time



+2


source


Regarding changing the default codepage:

The default codepage for the user (for WinXP - not sure how it is in Vista) is set in the Regional and Language Options control panel applet under the Advanced tab.

"Language for Non-Unicode Programs" sets the default codecode for the current user. Unfortunately, it doesn't actually tell you the codepage number it is configuring - it just gives you the language (which can be optionally set using the region variant). This makes sense from an end-user perspective, because I think the number of code pages is irrelevant for 99.999% of end-users. You need to reboot for the changes to take effect. If you use regmon to determine what changes you could probably come up with, which simplifies the default code page somewhat.



Microsoft also has an unsupported utility called AppLocale for testing localization that changes the code page for specific applications: http://www.microsoft.com/globaldev/tools/apploc.mspx

Also you can change the codepage for the thread by calling SetThreadLocale()

- but you must also call the runtime function setlocale()

because some CRT functions don't talk to Win API language functions (and vice versa). See "Windows SetThreadLocale

and CRT setlocale

"
by Chris Grimes for details .

+2


source


For _getmbcp MSDN says "A return value of 0 indicates that one bytecode page is being used." This makes it not very useful. Try one of them: GetUserDefaultLCID GetSystemDefaultLCID GetACP. (Now why isn't there a "custom" equivalent for GetACP?)

Anyway, if you want _getmbcp to return an actual value, set your default language to the default language of Chinese, Japanese, or Korean.

+2


source


As always in non-Unicode scripts, you will only get reliable results if the locale is set (aka "Control Panel Language" for non-unicode applications). If not, don't expect anything good.

For example, if the system locale is Traditional Chinese, you will receive 2 consecutive WM_CHAR messages (one for each byte if the user is 2 char).

isleadbyte () should help you determine if the second byte is coming soon.

If your system locale is not set to Chinese, do not expect to receive correct messages, even if you use a Chinese keyboard / IME. The downside is that some scripts work. for example, using a Greek keyboard, you will get the WM_CHAR char values ​​based on the Greek code page, even if your locale of your system is Latin based. But you really should avoid trying to deal with such scenarios: success is not guaranteed and will likely change depending on the Windows version and locale.

As MikeB wrote, MS AppLocale is your friend to do basic tests.

[ad] and appTranslator is your friend if you need to translate your user interface [/ ad]

+2


source


Actually a very simple (but weird) way to force the OnChar function to send Unicode characters to an application, even if configured in a multibyte character set:

SetWindowLongW( m_hWnd, GWL_WNDPROC, GetWindowLong( m_hWnd, GWL_WNDPROC ) );

      

By simply calling the Unicode version of "SetWindowLong", it forces the application to receive Unicode characters.

0


source







All Articles