Freigeben über


CDateTimeCtrl::GetTime

Retrieves the currently selected time from a date and time picker control and puts it in a specified SYSTEMTIME structure.

BOOL GetTime( 
   COleDateTime& timeDest  
) const; 
DWORD GetTime( 
   CTime& timeDest  
) const; 
DWORD GetTime( 
   LPSYSTEMTIME pTimeDest  
) const;

Parameters

  • timeDest
    In the first version, a reference to a COleDateTime object that will receive the system time information. In the second version, a reference to a CTime object that will receive the system time information.

  • pTimeDest
    A pointer to the SYSTEMTIME structure to receive the system time information. Must not be NULL.

Return Value

In the first version, nonzero if the time is successfully written to the COleDateTime object; otherwise 0. In the second and third versions, a DWORD value equal to the dwFlag member set in the NMDATETIMECHANGE structure. See the Remarks section below for more information.

Remarks

This member function implements the behavior of the Win32 message DTM_GETSYSTEMTIME, as described in the Windows SDK. In the MFC implementation of GetTime, you can use COleDateTime or CTime classes, or you can use a SYSTEMTIME structure, to store the time information.

The return value DWORD in the second and third versions, above, indicates whether or not the date and time picker control is set to the "no date" status, as indicated in the NMDATETIMECHANGE structure member dwFlags. If the value returned equals GDT_NONE, the control is set to "no date" status, and uses the DTS_SHOWNONE style. If the value returned equals GDT_VALID, the system time is successfully stored in the destination location.

Example

void CDateTimeDlg::OnBnClickedTimebutton()
{
   // get as a CTime
   CTime timeTime;
   DWORD dwResult = m_DateTimeCtrl.GetTime(timeTime);
   if (dwResult == GDT_VALID)
   {
      // the user checked the box and specified data
      CString str;

      // is it a time-only control, or a date-only control? 
      if ((m_DateTimeCtrl.GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)
         str = timeTime.Format(_T("%X"));
      else
         str = timeTime.Format(_T("%x"));
      AfxMessageBox(str);
   }
   else
   {
      // the user unmarked the "none" box
      AfxMessageBox(_T("Time not set!"));
   }

   // Calling as SYSTIME is much the same, but calling for a COleDateTime 
   // has us test the state of the COleDateTime object for validity to  
   // see if the user did or didn't check the "none" box.
}

Requirements

Header: afxdtctl.h

See Also

Reference

CDateTimeCtrl Class

Hierarchy Chart

CDateTimeCtrl::SetTime