- MFC Tutorial
- MFC - Home
- MFC - Overview
- MFC - Environment Setup
- MFC - VC++ Projects
- MFC - Getting Started
- MFC - Windows Fundamentals
- MFC - Dialog Boxes
- MFC - Windows Resources
- MFC - Property Sheets
- MFC - Windows Layout
- MFC - Controls Management
- MFC - Windows Controls
- MFC - Messages & Events
- MFC - Activex Controls
- MFC - File System
- MFC - Standard I/O
- MFC - Document View
- MFC - Strings
- MFC - Carray
- MFC - Linked Lists
- MFC - Database Classes
- MFC - Serialization
- MFC - Multithreading
- MFC - Internet Programming
- MFC - GDI
- MFC - Libraries
- MFC Useful Resources
- MFC - Quick Guide
- MFC - Useful Resources
- MFC - Discussion
MFC - Date & Time Picker
The date and time picker control (CDateTimeCtrl) implements an intuitive and recognizable method of entering or selecting a specific date. The main interface of the control is similar in functionality to a combo box. However, if the user expands the control, a month calendar control appears (by default), allowing the user to specify a particular date. When a date is chosen, the month calendar control automatically disappears.
Let us look into a simple example by creating a new MFC application.
Step 1 − Remove the Caption and set its ID to IDC_STATIC_TXT.
Step 2 − Add the value variable for text control.
Step 3 − Drag the Date Time Picker control.
Step 4 − Add a control variable for Date Time Picker.
Step 5 − Add the Event handler for Date Time Picker.
Step 6 − Here is the implementation of event handler.
void CMFCDateAndTimePickerDlg::OnDtnDatetimechangeDatetimepicker1(NMHDR *pNMHDR, LRESULT *pResult){ LPNMDATETIMECHANGE pDTChange = reinterpret_cast <LPNMDATETIMECHANGE>(pNMHDR); // TODO: Add your control notification handler code here GetDlgItemText(IDC_DATETIMEPICKER1, m_strValue); UpdateData(FALSE); *pResult = 0; }
Step 7 − When you run the above application, you see the following output. Select any date, it will display on the Static Text Control.