Microsoft KB Archive/238077

= How to set a blank date as the initial value for Date Time Picker control =

Article ID: 238077

Article Last Modified on 1/10/2006

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q238077



Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.



SUMMARY
Both Windows Date Time Picker control (CDateTimeCtrl) and Microsoft Date Time Picker ActiveX controls have the current date as the initial value by default. This article explains how to set a blank date as initial value for these controls.



MORE INFORMATION
Windows Date Time Picker control and Microsoft Date Time Picker ActiveX controls change the time back to the current date even if you set it to blank by calling SetWindowText with a blank string as parameter.

The following steps describe a way to set a blank date as the initial value for Microsoft Date Time Picker ActiveX control.   Change the format type to custom format (3) and set the custom format to where one blank string.m_datePicker is a member variable created for the Windows Date Time Picker control placed on a dialog box. BOOL CDtpickerDlg::OnInitDialog {      CDialog::OnInitDialog;

SetIcon(m_hIcon, TRUE);                // Set big icon SetIcon(m_hIcon, FALSE);               // Set small icon m_datePicker.SetFormat(3);        // Change the format type to    custom format. m_datePicker.SetCustomFormat(" "); // One blank string.

return TRUE; // return TRUE  unless you set the focus to a control }

  Add an event handler for the Change event in your dialog class using ClassWizard. ON_EVENT(CDtpickerDlg, IDC_DTPICKER1, 2,OnChangeDtpicker1,VTS_NONE) NOTE: If using Visual Studio.NET do the following: In the Property browser, on the Events tav, add an event handler for the Change event in your dialog class.   In the event handler (OnChangeDtPicker1) change the format back to the format you want. void CDtpickerDlg::OnChangeDtpicker1 {      m_datePicker.SetFormat(1); }                       

You could use similar logic to set a blank date as an initial value for Windows Standard Date Time Picker control.   Call SetFormat with one blank string as parameter. m_dateCtrl.SetFormat(" "); //one blank   Add a notification message handler for the DTN_DATETIMECHANGE message in your dialog class and add the following code to it. Change the format type to the format you want. void CDateTimeCtrlDlg::OnDateTimeChange(NMHDR *pNotifyStruct, LRESULT   *result) {       m_dateCtrl.SetFormat(DTS_SHORTDATEFORMAT); *pResult = 0; }                       </li></ol>

(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Sreedhar Pelluru, Microsoft Corporation.

Keywords: kbhowto kbdatetime kbcmnctrls kbctrl kbcontrol KB238077

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.