Use the Date/Time Picker common control (IE3+) | CodeGuru

Use the Date/Time Picker common control (IE3+)

NOTE: You must also have the new COMCTL32.DLL (version 4.7 or later). This is installed with Internet Explorer 3 and will come standard with the new Windows 98. So if you are using VC++ 5 then you probably already have this DLL. The API support is available in VC++ 5.0. Otherwise, you need to download […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 25, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

NOTE: You must also have the new COMCTL32.DLL (version 4.7 or later). This
is installed with Internet Explorer 3 and will come standard with the new
Windows 98. So if you are using VC++ 5 then you probably already have this
DLL.

The API support is available in VC++ 5.0. Otherwise, you need to
download the ActiveX SDK from the MS website. To use the date/time
picker, do the following:

Put the following in your app’s InitInstance:

        INITCOMMONCONTROLSEX icc;
        icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
        icc.dwICC = ICC_DATE_CLASSES;
        InitCommonControlsEx(&icc);

Insert a custom control in your dialog where you want the date or
time picker. For the class name, enter “SysDateTimePick32”. For
the style, see commctrl.h and search for the DTS_* style and enter
the desired style (usually either DTS_SHORTDATEFORMAT or
DTS_TIMEFORMAT). Be sure to make the custom control visible and
have a tabstop.

You can always use CreateEx() to create them manually.

You can DDX the control to a SYSTEMTIME structure with the following
code:

void AFXAPI DDX_DateTime(CDataExchange *pDX, int nIDC,
        SYSTEMTIME &SysTime)
{
        HWND hWnd = pDX->m_pDlgWnd->GetDlgItem(nIDC)->GetSafeHwnd();
        ASSERT (hWnd != NULL);

        if (pDX->m_bSaveAndValidate)
        {
                ::SendMessage(hWnd, DTM_GETSYSTEMTIME, 0,
                        (LPARAM)&SysTime);
        }
        else // initializing
        {
                ::SendMessage(hWnd, DTM_SETSYSTEMTIME, GDT_VALID,
                        (LPARAM)&SysTime);
        }
}

void CCtrlTestDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CCtrlTestDlg)
        //}}AFX_DATA_MAP
        // m_Date and m_Time  are SYSTEMTIME structures
        DDX_DateTime(pDX, IDC_DATE, m_Date);
        DDX_DateTime(pDX, IDC_TIME, m_Time);
}
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.