Virtual Developer Workshop: Containerized Development with Docker

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:
        icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
        icc.dwICC = ICC_DATE_CLASSES;

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, 
        else // initializing
                ::SendMessage(hWnd, DTM_SETSYSTEMTIME, GDT_VALID,

void CCtrlTestDlg::DoDataExchange(CDataExchange* pDX)
        // m_Date and m_Time  are SYSTEMTIME structures
        DDX_DateTime(pDX, IDC_DATE, m_Date); 
        DDX_DateTime(pDX, IDC_TIME, m_Time);


  • Please Help me

    Posted by joselo58 on 07/05/2007 08:37pm

    I don't know how to work with DatatimePicker when I change the value, for example Today It's 5th July I want to add + 2 months. Please send me the code... Jose Luis.

  • How to update the custom control with a date

    Posted by Legacy on 10/07/2003 07:00am

    Originally posted by: Jabberwoky

    Here's how I get and put the control data (quick and dirty) 

    CString fmtStr;

    //Get the cureent displayed date
    GetDlgItemText(IDC_CUSTOM1, fmtStr);

    //Get today date, change date

    HWND hWnd = GetDlgItem(IDC_CUSTOM1)->GetSafeHwnd();
    ASSERT (hWnd != NULL);

    DateTime_SetSystemtime(hWnd, GDT_VALID , &now);

  • Read time from a edit box

    Posted by Legacy on 01/09/2003 08:00am

    Originally posted by: Stefano

    Probaly it's a stupid question but I'm not a really good programmer. I want to read the hour, according to the format hh:mm, from a edit box.
    Can you help me?

    Thank you

  • ExCalendar

    Posted by Legacy on 01/30/2002 08:00am

    Originally posted by: Mike Philips

    If you would like to check, please feel free to download a nice calendar control here

    Regards, Mike

  • Urgent!

    Posted by Legacy on 01/16/2002 08:00am

    Originally posted by: Patricia

    Can you tell me if it is possible to change the color of the text appearing in the edit? The WM_CTCOLOR seems to not work...It is quite easy to change the background color but for the text it seems impossible!
    Is it possible to display the date time control as edit only without spin?

  • European format

    Posted by Legacy on 12/26/2001 08:00am

    Originally posted by: Malka Shafir

    Can I change the text on the bottom "Today: 12/26/01" to European format ("Today: 26/12/01")?
    If yes, I would like to know how.
    Thanks a lot.

  • returned dates 4 years in future

    Posted by Legacy on 08/11/2001 07:00am

    Originally posted by: sqe

    After picking a date (let's say 1.8.2001) and closing the dialog with OK, in a variable m_blahblah (a CTime object) used for ddx (i used classwizard to add that variable(s)), the value in m_blahblah is about 4 years in the future (let's say 10.3.2004)..., i use 4 callendars and they all return values the same 4 years (minus a few days) in future (if i choose 2.8.2001, it returns 11.3.2004, so it works, but a little bit strange:) ... could you help me please? (i use MS VC++ 6.0)


    PS: i also tryied to use CDateTimeOle (or what!, i don't know the exact name now:) object (not CTime) using classwizard, in that case, the returned dates were correct or "-1"'s, if i changed the year or month, the returned value was ok (no +4 years), but if i only clicked on some day (in actual month/year), the returned values (in .GetDay(), .GetMonth(), GetYear()) were all "-1". I am realy tired of it, please help me... ... thanx


  • control bug?

    Posted by Legacy on 08/01/2001 07:00am

    Originally posted by: TP

    I have instantiated the control under Win32 and can select dates as normal when using the popup date grid, which works perfectly.

    However, if I attempt to modify the year value in either the "long date" or "short date" view (without opening the popup date grid), I consistently get an access violation. As far as I know, that part of the interface should be handled automatically, so is there a bug in the control?


  • How do I change the date in run time (programmatically) ?

    Posted by Legacy on 05/24/2001 07:00am

    Originally posted by: Michael Tjong

    I use COleDateTime as the date object. When I change to a certain date in code and run it, yet still appears/display out with the current date?
    Any coding that I have missed? Thanks a lot for your help in advance.

    For instance:

    COleDateTime m_TodayDate;
    m_TodayDate.SetDate(1990, 05, 12);


  • Saving Date Ctrl to Database

    Posted by Legacy on 02/10/2001 08:00am

    Originally posted by: Kalvain

    Year and a half late post but thought I would add for anyone in the future looking for this answer.
    When you bind a Date Time Picker to a database variable the class wizard will set up a function in the data exchange that does not exist. Correction is below...

    ///Bad code inserted by class wizard
    DDX_FieldDateTimeCtrl(pDX, IDC_SR22Date, Driverptr->m_SR22DATE, Driverptr);

    ///Correction to code to make it work
    DDX_DateTimeCtrl(pDX, IDC_SR22Date, Driverptr->m_SR22DATE );

    Remove the word "Field" in the DDX function and remove the fourth parameter all together.


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date