📄 date.c
字号:
/* Get current short date format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SSHORTDATE,
wszShortDateFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of date formats */
for(nCBIndex=0;nCBIndex<MAX_SHORT_FMT_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)ShortDateFmtSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszShortDateFmt);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
CB_ADDSTRING,
MAX_SHORT_FMT_SAMPLES+1,
(LPARAM)wszShortDateFmt);
SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszShortDateFmt);
}
}
/* Init long date control box */
VOID
InitLongDateCB(HWND hwndDlg)
{
/* Where this data stored? */
WCHAR LongDateFmtSamples[MAX_LONG_FMT_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"d MMMM yyyy 'y.'",
L"dd MMMM yyyy 'y.'"
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszLongDateFmt[MAX_SAMPLES_STR_SIZE];
/* Get current long date format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SLONGDATE,
wszLongDateFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATEFMT_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of date formats */
for(nCBIndex=0;nCBIndex<MAX_LONG_FMT_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATEFMT_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)LongDateFmtSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATEFMT_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszLongDateFmt);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATEFMT_COMBO),
CB_ADDSTRING,
MAX_LONG_FMT_SAMPLES+1,
(LPARAM)wszLongDateFmt);
SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATEFMT_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszLongDateFmt);
}
}
/* Set up max date value to registry */
VOID
SetMaxDate(HWND hwndDlg)
{
const HWND hWndYearSpin = GetDlgItem(hwndDlg, IDC_SCR_MAX_YEAR);
WCHAR wszMaxDateVal[YEAR_STR_MAX_SIZE];
INT nSpinVal;
/* Get spin value */
nSpinVal=LOWORD(SendMessage(hWndYearSpin,
UDM_GETPOS,
0,
0));
/* convert to wide char */
_itow(nSpinVal,wszMaxDateVal,DECIMAL_RADIX);
/* Save max date value */
SetCalendarInfoW(LOCALE_USER_DEFAULT,
CAL_GREGORIAN,
48 , /* CAL_ITWODIGITYEARMAX */
(LPCWSTR)&wszMaxDateVal);
}
/* Get max date value from registry set */
INT
GetMaxDate()
{
int nMaxDateVal;
GetCalendarInfoW(LOCALE_USER_DEFAULT,
CAL_GREGORIAN,
CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER,
NULL,
0, /* ret type - number */
(LPDWORD)&nMaxDateVal);
return nMaxDateVal;
}
/* Set's MIN data edit control value to MAX-99 */
static
VOID
SetMinData(HWND hwndDlg)
{
WCHAR OutBuffer[YEAR_STR_MAX_SIZE];
const HWND hWndYearSpin = GetDlgItem(hwndDlg, IDC_SCR_MAX_YEAR);
/* Get spin value */
INT nSpinVal=LOWORD(SendMessage(hWndYearSpin,
UDM_GETPOS,
0,
0));
/* Set min year value */
wsprintf(OutBuffer, L"%d", (DWORD)nSpinVal-YEAR_DIFF);
SendMessageW(GetDlgItem(hwndDlg, IDC_FIRSTYEAR_EDIT),
WM_SETTEXT,
0,
(LPARAM)OutBuffer);
}
/* Init spin control */
static
VOID
InitMinMaxDateSpin(HWND hwndDlg)
{
WCHAR OutBuffer[YEAR_STR_MAX_SIZE];
const HWND hWndYearSpin = GetDlgItem(hwndDlg, IDC_SCR_MAX_YEAR);
/* Init max date value */
wsprintf(OutBuffer, L"%04d", (DWORD)GetMaxDate());
SendMessageW(GetDlgItem(hwndDlg, IDC_SECONDYEAR_EDIT),
WM_SETTEXT,
0,
(LPARAM)OutBuffer);
/* Init min date value */
wsprintf(OutBuffer, L"%04d", (DWORD)GetMaxDate()-YEAR_DIFF);
SendMessageW(GetDlgItem(hwndDlg, IDC_FIRSTYEAR_EDIT),
WM_SETTEXT,
0,
(LPARAM)OutBuffer);
/* Init updown control */
/* Set bounds */
SendMessageW(hWndYearSpin,
UDM_SETRANGE,
0,
MAKELONG(MAX_YEAR,YEAR_DIFF));
/* Set current value */
SendMessageW(hWndYearSpin,
UDM_SETPOS,
0,
MAKELONG(GetMaxDate(),0));
}
/* Update all date locale samples */
static
VOID
UpdateDateLocaleSamples(HWND hwndDlg,
LCID lcidLocale)
{
WCHAR OutBuffer[MAX_FMT_SIZE];
/* Get short date format sample */
GetDateFormatW(lcidLocale, DATE_SHORTDATE, NULL, NULL, OutBuffer,
MAX_FMT_SIZE);
SendMessageW(GetDlgItem(hwndDlg, IDC_SHRTDATESAMPLE_EDIT), WM_SETTEXT,
0, (LPARAM)OutBuffer);
/* Get long date sample */
GetDateFormatW(lcidLocale, DATE_LONGDATE, NULL, NULL, OutBuffer,
MAX_FMT_SIZE);
SendMessageW(GetDlgItem(hwndDlg, IDC_LONGDATESAMPLE_EDIT),
WM_SETTEXT, 0, (LPARAM)OutBuffer);
}
/* Date options setup page dialog callback */
INT_PTR
CALLBACK
DateOptsSetProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
//int i,j;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(hwndDlg);
switch(uMsg)
{
case WM_INITDIALOG:
{
InitMinMaxDateSpin(hwndDlg);
UpdateDateLocaleSamples(hwndDlg, LOCALE_USER_DEFAULT);
InitShortDateCB(hwndDlg);
InitLongDateCB(hwndDlg);
InitShortDateSepSamples(hwndDlg);
/* TODO: Add other calendar types */
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_SECONDYEAR_EDIT:
{
if(HIWORD(wParam)==EN_CHANGE)
{
SetMinData(hwndDlg);
}
}
case IDC_SCR_MAX_YEAR:
{
/* Set "Apply" button enabled */
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
case IDC_CALTYPE_COMBO:
case IDC_HIJCHRON_COMBO:
case IDC_SHRTDATEFMT_COMBO:
case IDC_SHRTDATESEP_COMBO:
case IDC_LONGDATEFMT_COMBO:
{
if (HIWORD(wParam) == CBN_SELCHANGE ||
HIWORD(wParam) == CBN_EDITCHANGE)
{
/* Set "Apply" button enabled */
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
}
break;
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnm = (LPNMHDR)lParam;
/* If push apply button */
if (lpnm->code == (UINT)PSN_APPLY)
{
SetMaxDate(hwndDlg);
if(!SetShortDateSep(hwndDlg)) break;
if(!SetShortDateFormat(hwndDlg)) break;
if(!SetLongDateFormat(hwndDlg)) break;
InitShortDateCB(hwndDlg);
/* FIXME: */
Sleep(15);
UpdateDateLocaleSamples(hwndDlg, LOCALE_USER_DEFAULT);
}
}
break;
}
return FALSE;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -