#include <CommCtrl.h> BOOL SetDlgDate(HWND hDlg, const int id, const SYSTEMTIME *st) { return DateTime_SetSystemtime(GetDlgItem(hDlg, id), GDT_VALID, st); } BOOL GetDlgDate(const HWND hDlg, const int id, SYSTEMTIME *st) { return DateTime_GetSystemtime(GetDlgItem(hDlg, id), st); } void GetDlgDateStr(const HWND hDlg, const int id, LPSTR szDate, const size_t size) { SYSTEMTIME st; GetDlgDate(hDlg, id, &st); _snprintf(szDate, size, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); }
Programming Tips - Win32: nice way to select the date in a dialog
Date: 2012jul31
OS: Windows
Platform: win32, non-MFC
Language: C/C++
Q. Win32: nice way to select the date in a dialog
A. Drag the "Date Time Picker" onto your dialog.
Change the Format to "Long Date" or "Short Date".
Use this code to get or set the values: