我已经在控制面板 (Windows 7) 的区域和本地设置中调整了一周的第一天,现在我正在编写一个 C++ 函数,它必须返回我调整过的一周的第一天。 我可以使用它的任何 Windows API 或标准 c++ 函数吗?
最佳答案
(对不起,我写的完全错了。我已经更新了帖子。)
正确使用的函数是EnumCalendarInfoExEx :
#include <Windows.h>
#include <strsafe.h>
#include <iostream>
using namespace std;
BOOL CALLBACK EnumCalendarInfoProcExEx(LPWSTR lpszInfo, CALID calendar, LPWSTR lpReserved, LPARAM lParam)
{
StringCchCopy(reinterpret_cast<LPWSTR>(lParam), 64, lpszInfo);
return FALSE;
}
int main()
{
WCHAR szDay[64];
BOOL bResult = ::EnumCalendarInfoExEx(
&EnumCalendarInfoProcExEx,
LOCALE_NAME_USER_DEFAULT,
ENUM_ALL_CALENDARS,
nullptr,
CAL_SDAYNAME1,
reinterpret_cast<LPARAM>(szDay)
);
if (!bResult)
{
wcout << L"Error" << endl;
return 0;
}
wcout << szDay << endl;
return 0;
}
需要注意的几点:
- 即使在我 PC 的控制面板中将一周的第一天配置为星期日,这也会返回星期一...
- 显然,用户的区域设置可以有多个日历。上面的代码只获取第一个日历的第一天。
关于c++ - 如何开始星期几?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39325212/