Dave's Brain

Browse - Programming Tips - How can I give my users a nice way to select the date in a dialog?

Date: 2012jul31
OS: Windows
Platform: win32, non-MFC
Language: C/C++

Q.  How can I give my users a 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:

#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); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.