如何获取当前键盘布局的代码页? [英] How to get the code page of the current keyboard layout?

查看:113
本文介绍了如何获取当前键盘布局的代码页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的非Unicode应用程序需要能够处理Unicode键盘输入(WM_CHAR/etc.),从而接收8位字符代码,然后在内部将其转换为Unicode. 9x兼容性是必需的,因此不能选择使用大多数Unicode API.

My non-Unicode application needs to be able to process Unicode keyboard input (WM_CHAR/etc.), thus receive the 8-bit character code then internally convert it to Unicode. 9x-compatibility is required, so using most Unicode APIs is not an option.

当前,它查看PRIMARYLANGID(GetKeyboardLayout(0))返回的语言,并在硬编码表中查找相关的代码页.我找不到用于获取特定语言或键盘布局使用的代码页的函数.然后可以使用MultiByteToWideChar来转换字符/字符串.

Currently it looks at the language returned by PRIMARYLANGID(GetKeyboardLayout(0)), and looks up the relevant code page in a hard-coded table. I couldn't find a function to get the code page used by a particular language or keyboard layout. Converting a character/string can then be done with MultiByteToWideChar.

有没有办法获取当前键盘布局的代码页? GetACP返回默认的系统代码页,该页不受当前键盘布局的影响.

Is there a way to get the current keyboard layout's code page? GetACP returns the default system code page, which isn't affected by the current keyboard layout.

推荐答案

这是另一种方法:

WORD languageID = LOWORD(GetKeyboardLayout(0));
char szLCData[6+1];
GetLocaleInfoA(MAKELCID(languageID, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE,
               szLCData, _countof(szLCData));
int codepage = atoi(szLCData);

这篇关于如何获取当前键盘布局的代码页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆