|
2024/06/07(Fri) 21:07:04 編集(投稿者)
■No103174 (KOZ さん) に返信 > 日本語版 Windows 11 の場合、C:\Windows\System32\ja-jp\user32.dll.mui > にリソースとして格納されているようです。
ということは、LoadLibraryEx で LOAD_LIBRARY_AS_IMAGE_RESOURCE を指定すれば切り替わるかも? (手元の環境には en-us と ja-jp しかインストールしておらず、この 2 種しか確認できませんでした)
// en-US OK Cancel &Abort &Retry &Ignore &Yes &No &Close Help &Try Again &Continue
// ja-JP OK キャンセル 中止(&A) 再試行(&R) 無視(&I) はい(&Y) いいえ(&N) 閉じる(&C) ヘルプ 再実行(&T) 続行(&C)
public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { comboBox1.DisplayMember = "DisplayName"; comboBox1.ValueMember = "LCID"; // comboBox1.DataSource = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures); comboBox1.DataSource = CultureInfo.GetCultures(CultureTypes.SpecificCultures); }
private void Form1_Shown(object sender, EventArgs e) { comboBox1.SelectedValue = CultureInfo.CurrentCulture.LCID; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //textBox1.Lines = GetMessageBoxButtonsText();
var culture = comboBox1.SelectedItem as CultureInfo; Text = culture?.Name; textBox1.Lines = GetMessageBoxButtonsText(culture); }
internal string[] GetMessageBoxButtonsText() => GetMessageBoxButtonsText(null); internal string[] GetMessageBoxButtonsText(CultureInfo culture) { var results = new string[11]; var sb = new StringBuilder(1024); IntPtr h = default; try { h = LoadLibraryEx("user32.dll", default, LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE); ushort langid = (culture == null) ? default : GetThreadUILanguage(); if (langid != default) { var newLangId = LANGIDFROMLCID(culture.LCID); var setLangId = SetThreadUILanguage(newLangId); if (setLangId != newLangId) { var ex = new Win32Exception(); SetThreadUILanguage(langid); // throw ex; } } for (int id = 800; id <= 810; id++) { LoadString(h, id, sb, sb.Capacity); results[id - 800] = sb.ToString(); } if (langid != default) { SetThreadUILanguage(langid); } } finally { if (h != default) { FreeLibrary(h); } } return results; }
private ushort LANGIDFROMLCID(int lcid) => unchecked((ushort)lcid);
[Flags] public enum LoadLibraryFlags : uint { DONT_RESOLVE_DLL_REFERENCES = 0x00000001, LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010, LOAD_LIBRARY_AS_DATAFILE = 0x00000002, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040, LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020, LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100, LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000, }
[DllImport("kernel32", CharSet = CharSet.Auto)] private static extern IntPtr LoadLibraryEx([In] string lpLibFileName, IntPtr hFile, LoadLibraryFlags dwFlags);
[DllImport("kernel32", CharSet = CharSet.Auto)] private static extern ushort GetThreadUILanguage();
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern ushort SetThreadUILanguage(ushort langId);
[DllImport("kernel32", SetLastError = true)] public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("user32", CharSet = CharSet.Auto)] private static extern int LoadString(IntPtr hInstance, int uID, StringBuilder lpBuffer, int nBufferMax); }
|