Programming Tips - Win32: nice way to select the time in a dialog

Date: 2012jul31 OS: Windows Platform: win32, non-MFC Language: C/C++ Q. Win32: nice way to select the time in a dialog A. Drag the "Date Time Picker" onto your dialog. Change the Format to "Time". 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 GetDlgTimeStr(const HWND hDlg, const int id, LPSTR szTime, const size_t size) { SYSTEMTIME st; GetDlgDate(hDlg, id, &st); _snprintf(szTime, size, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond); }