Created
February 10, 2019 05:17
-
-
Save kenjinote/07fd7cbe39fda83d1a9d7180ca0981b6 to your computer and use it in GitHub Desktop.
指定された年の和暦元号のアルファベット頭文字をレジストリから取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL GetEraAlphabet(const LPSYSTEMTIME lpSystemTime, LPWSTR lpszEraAlphabet, DWORD dwEraAlphabetSize) | |
{ | |
BOOL bRet = FALSE; | |
WCHAR szEra[256] = { 0 }; | |
if (GetDateFormatEx(L"ja-JP", DATE_USE_ALT_CALENDAR, lpSystemTime, L"gg", szEra, _countof(szEra), NULL) > 0) | |
{ | |
HKEY hKey; | |
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras", 0, KEY_READ, &hKey) == ERROR_SUCCESS) | |
{ | |
DWORD dwValues; | |
if (RegQueryInfoKeyW(hKey, 0, 0, 0, 0, 0, 0, &dwValues, 0, 0, 0, 0) == ERROR_SUCCESS) | |
{ | |
for (DWORD i = 0; i < dwValues; ++i) | |
{ | |
WCHAR szValueName[1024] = { 0 }; | |
DWORD dwValueNameSize = _countof(szValueName); | |
WCHAR szData[1024]; | |
DWORD dwDataByteSize = sizeof(szData); | |
if (RegEnumValueW(hKey, i, szValueName, &dwValueNameSize, 0, 0, (LPBYTE)szData, &dwDataByteSize) == ERROR_SUCCESS) | |
{ | |
if (wcsncmp(szData, szEra, lstrlenW(szEra)) == 0) | |
{ | |
LPWSTR context = 0; | |
LPWSTR p = wcstok_s(szData, L"_", &context); | |
for (int i = 0; i < 3 && p; ++i) | |
{ | |
p = wcstok_s(0, L"_", &context); | |
} | |
if (p) | |
{ | |
lstrcpynW(lpszEraAlphabet, p, dwEraAlphabetSize); | |
bRet = TRUE; | |
} | |
break; | |
} | |
} | |
} | |
} | |
RegCloseKey(hKey); | |
} | |
} | |
return bRet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment