Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.
Source code and project files for this sample can be found in the samples\gui\DateTimePicker directory of the sample projects download.
Overview
A COXDateTimeCtrl
object encapsulates the functionality of a date and time picker control. The date and time picker control (DTP control) provides a simple interface to exchange date and time information with a user. This interface contains fields, each of which displays a part of the date and time information stored in the control. The user can change the information stored in the control by changing the content of the string in a given field. The user can move from field to field using the mouse or the keyboard.
Using COXDateTimeCtrl
The date and time picker control (COXDateTimeCtrl
) 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.
Note: To use both the CDateTimePicker
and COXMonthCalCtrl
classes in your project, you must include OXDateTimeCtrl.h.
Creating the Date and Time Picker Control
How the date and time picker control is created depends on whether you are using the control in a dialog box or creating it in a non-dialog window.
To Use COXDateTimeCtrl Directly in a Dialog Box
Visual C++ v6.0:
In the dialog editor, add a date and time picker control to your dialog template resource. Specify its control ID. Specify any styles required, using the Properties dialog box of the date and time picker control. Use ClassWizard to map handler functions in the dialog class for any date time picker control notification messages you need to handle. In OnInitDialog
, set any additional styles for the COXDateTimeCtrl
object.
Visual C++ v5.0:
In the dialog editor, add a Static control to your dialog template resource (it will be a placeholder for the DTP control). Specify its control ID. In OnInitDialog
, you can use the following code to replace the Static control with our DTP control:
CWnd *pFrame= GetDlgItem(IDC_DATETIMEPICKER);
CRect rcWnd;
pFrame>GetWindowRect(rcWnd);
pFrame>DestroyWindow();
ScreenToClient(rcWnd);
m_ctlDateTimePicker.Create(WS_CHILD|WS_VISIBLE|WS_TABSTOP, rcWnd,this,
IDC_DATETIMEPICKER);
To Use COXDateTimeCtrl in a Non-Dialog Window
Declare the control in the view or the window class. Call the control's Create
member function, possibly in OnInitialUpdate
, possibly as early as the parent window's OnCreate
handler function (if you're subclassing the control). You can then set the styles for the control.
See the COXDateTimeCtrl
class reference in the Graphical User Interface section of the compiled HTML help for a description of the member functions available for setting and retrieving data from the control.
Initial CodeProject release August 2007.