Click here to Skip to main content
Click here to Skip to main content

The Ultimate Toolbox Date Time Picker Control

, 25 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
COXDateTimeCtrl provides a handy and flexible method of Date/Time entry and display.

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.

History

Initial CodeProject release August 2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
 
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

391 members


Comments and Discussions

 
Generalis it resizable for let's say an environment that needs to have a BIG DTP control...(touch screen?) Pinmemberhesaigo999ca3-Dec-08 9:26 
GeneralRe: is it resizable for let's say an environment that needs to have a BIG DTP control...(touch screen?) PineditorTim Deveaux4-Dec-08 8:24 
General[Message Removed] Pinmemberstonber5-Oct-08 8:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411019.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid