为什么 EnumUILanguages 只返回一种语言?
我在安装了中文和法语 shell 语言包 (MUI) 的 Windows XP Embedded 版本上使用 Win API 函数 EnumUILanguages,但 API 调用仅返回一种语言代码:0409(基本 en-US 安装语言)。
如果我查看 HKLM\SYSTEM\CurrentControlSet\Control\Nls\MUILanguages\ 下的注册表,那么我可以看到所有可用的语言(0409、040C、0804)。我更喜欢使用 API 调用而不是直接访问注册表......关于为什么此 API 调用仅返回唯一语言有什么建议吗?
谢谢,邓肯
更新:一些代码和信息 - 我从带有备忘录框和按钮的表单中调用它。按下按钮,将启动 WinAPI 调用,并传递一个指向 TMemoBox 的 Strings 属性的指针,以便回调函数可以对其进行写入。
// The Button handler
procedure TForm1.btnEnumLangsClick(Sender: TObject);
var
dwFlags : DWORD;
callback : TEnumUILanguagesProc;
begin
dwFlags := 0; // Same as MUI_LANGUAGE_ID for WinXP compat
EnumUILanguagesW( @EnumUILanguages_Callback,
dwFlags,
LParam(memoUILangs.Lines) // Pointer to Memo box text lines
);
end;
// API Callback function:
function EnumUILanguages_Callback(lpUILanguageString: PWideChar;
List: TStringList): BOOL; stdcall;
begin
// Add language ID to the memo box
List.Add(lpUILanguageString);
// Return true so the callback continues to run
Result := True;
end;
I'm using the Win API function EnumUILanguages on a Windows XP Embedded build that has Chinese and French shell language packs (MUI) installed, however the API call only returns one language code: 0409 (the base en-US installed language).
If I look in the registry under HKLM\SYSTEM\CurrentControlSet\Control\Nls\MUILanguages\ then I can see all of the available languages (0409, 040C, 0804). I'd prefer to use the API call over accessing the registry directly.... any suggestions as to why this API call returns just the only language?
Thanks, Duncan
Update: A little code and information - I'm calling this from a form with a memo box and a button. Press the button, the WinAPI call is initiated and a pointer to the Strings property of the TMemoBox passed so the call back function can write to it.
// The Button handler
procedure TForm1.btnEnumLangsClick(Sender: TObject);
var
dwFlags : DWORD;
callback : TEnumUILanguagesProc;
begin
dwFlags := 0; // Same as MUI_LANGUAGE_ID for WinXP compat
EnumUILanguagesW( @EnumUILanguages_Callback,
dwFlags,
LParam(memoUILangs.Lines) // Pointer to Memo box text lines
);
end;
// API Callback function:
function EnumUILanguages_Callback(lpUILanguageString: PWideChar;
List: TStringList): BOOL; stdcall;
begin
// Add language ID to the memo box
List.Add(lpUILanguageString);
// Return true so the callback continues to run
Result := True;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EnumUILanguages 仅在回调中返回 true 时才会调用回调。是否可能在第一个回调中返回 false 并且 EnumUILanguages 停止?
EnumUILanguages only calls the callback as long as you return true in the callback. Could it be that you return false right in the first callback and EnumUILanguages stops?
这是一个相当老的问题,但仍然没有答案。因为我遇到了同样的问题并且能够解决它,所以我想分享我的解决方案。
如果您在 Delphi 下进行开发,问题就出在回调函数的返回类型上。将其声明为
DWORD
并写入Result := 1
。 Delphi 的True
不会被EnumUILanguages
的调用代码识别为TRUE
。幸运的是;-) Delphi 的单元
Winapi.Windows.pas
缺少(在 XE2 下)EnumUILanguages
的声明及其回调函数的函数类型,因此您可以通过以下方式声明它:你自己的。This is a rather old question but it is still unanswered. Because I came across the same problem and was able to solve it, I want to share my solution.
If you are developing under Delphi the problem is the return type of the callback function. Declare it as
DWORD
and writeResult := 1
. Delphi'sTrue
isn't recognized asTRUE
by the calling code ofEnumUILanguages
.Fortunately ;-) Delphi's unit
Winapi.Windows.pas
lacks (under XE2) of a declaration forEnumUILanguages
and the function type of its callback function, so you can declare it by your own.将 dwFlags 设置为 0 表示 MUI_LANGUAGE_ID 或 MUI_LICENSED_LANGUAGES。这意味着两件事:
Setting the dwFlags to 0 means MUI_LANGUAGE_ID or MUI_LICENSED_LANGUAGES. This implies two things: