I have adjusted the first day of week at Region and Local settings in a control panel (Windows 7), and now I'm writing a C++ function that must returns the first day of week which I have adjusted. Any Windows API or standard c++ function that I can use it ?
Asked
Active
Viewed 928 times
3
-
"the first day of week which selected": can't understand that fragment. Give an example. – Sep 05 '16 at 06:55
-
1This seems to bee a question that Google will gladly give you an answer for. – RedX Sep 05 '16 at 06:55
-
3Possible duplicate of [Determine what day of week the week starts with](http://stackoverflow.com/questions/11351196/determine-what-day-of-week-the-week-starts-with) – Puck Sep 05 '16 at 06:56
-
I need get a start day of week that selected at Region and Local settings in a control panel (Windows OS) – Bassam Najeeb Sep 05 '16 at 07:24
-
Look at this ref: https://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v=vs.110).aspx – H.Ghassami Sep 05 '16 at 09:49
2 Answers
3
(Sorry what I had written was totally wrong. I have updated the post.)
The right function to use is 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;
}
A couple of things to watch out for:
- Even though the first day of the week is configured as Sunday in Control Panel on my PC, this returns Monday...
- Apparently there can be multiple calendars for the user's locale. The above code only gets the first day for the first calendar.

user1610015
- 6,561
- 2
- 15
- 18
-
I try modification to tour code as use a GetLocaleInfoEx that returns a CALID "Caleder ID" and pass it as replacement to CAL_SDAYNAME1 parameter in main function, but the result has tow issues: 1- Always the start day returned a previous day for example if the first day is Sunday the result is Saturday. 2- The result returned as string how can I get it as integer. thanks. – Bassam Najeeb Sep 06 '16 at 10:20
2
I try use a GetLocaleInfoEx windows API and it worked well :)
int GetSystemStartDayOfWeek()
{
int ret;
DWORD StartDayOfWeek;
ret = GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
(LPTSTR)&StartDayOfWeek,
sizeof(StartDayOfWeek) / sizeof(TCHAR));
return StartDayOfWeek;
}

Bassam Najeeb
- 607
- 2
- 7
- 16