Help Center

CDtPicker.SetSystemtimemethod

Sets a date and time picker (DTP) control to a given date and time.

WindowsmethodCDtPicker.incdocumented

Syntax

FUNCTION SetSystemtime (BYVAL hDtp AS HWND, BYVAL gd AS DWORD, BYVAL pst AS SYSTEMTIME PTR) AS DWORD
FUNCTION SetSystemtime (BYVAL hDtp AS HWND, BYVAL gd AS DWORD, BYREF st AS SYSTEMTIME) AS DWORD

Parameters

NameDescription
hDtpA handle to the DTP control.
gdA value that specifies which range values are valid. This value can be a combination of the following:
GDT_VALID: Set the DTP control according to the data within the SYSTEMTIME structure pointed to by pst.
GDT_NONE: Set the DTP control to "no date" and clear its check box. When this flag is specified, pst is ignored. This flag applies only to DTP controls that are set to the DTS_SHOWNONE style.
pstA pointer to a SYSTEMTIME structure that contains the system time information by which to set the DTP control.

Return value

Returns nonzero if successful, or zero otherwise.

Description

Sets a date and time picker (DTP) control to a given date and time.

Examples

DIM st AS SYSTEMTIME st.wDay = 15 st.wMonth = 8 st.wYear = 2016 CDtPicker.SetSystemTime(hDtp, GDT_VALID, @st)

#define UNICODE #define _WIN32_WINNT &h0602 #INCLUDE ONCE "AfxNova/CWindow.inc" #INCLUDE ONCE "AfxNova/CDtPicker.inc" USING AfxNova

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
                       BYVAL pwszCmdLine AS WSTRING PTR, _
                       BYVAL nCmdShow AS LONG) AS LONG

END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)

' // Forward declaration DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

CONST IDC_LABEL = 1001 CONST IDC_DTPICKER = 1002

' ======================================================================================== ' Main ' ======================================================================================== FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
               BYVAL pwszCmdLine AS WSTRING PTR, _
               BYVAL nCmdShow AS LONG) AS LONG

' // Set process DPI aware SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) ' // Enable visual styles without including a manifest file AfxEnableVisualStyles

' // Creates the main window DIM pWindow AS CWindow = "MyClassName" ' Use the name you wish DIM hWin AS HWND = pWindow.Create(NULL, "CWindow - Button", @WndProc) ' // Sizes it by setting the wanted width and height of its client area pWindow.SetClientSize(400, 220) ' // Centers the window pWindow.Center ' // Set the main window background color pWindow.SetBackColor(RGB_OLDLACE)

pWindow.AddControl("Label", hWin, IDC_LABEL, "Select one date with the mouse", 50, 20, 300, 23) DIM htDTP AS HWND = pWindow.AddControl("DateTimePicker", hWin, IDC_DTPICKER, "", 100, 60, 150, 23) ' // Anchor the controls pWindow.AnchorControl(IDC_LABEL, AFX_ANCHOR_WIDTH) pWindow.AnchorControl(IDC_DTPICKER, AFX_ANCHOR_WIDTH)

' // Set the date DIM st AS SYSTEMTIME st.wDay = 15 st.wMonth = 8 st.wYear = 2026 CDtPicker.SetSystemTime(htDTP, GDT_VALID, @st)

' // Adds a button pWindow.AddControl("Button", hWin, IDCANCEL, "&Close", 270, 155, 75, 30) ' // Anchors the button to the bottom and the right side of the main window pWindow.AnchorControl(IDCANCEL, AFX_ANCHOR_BOTTOM_RIGHT)

' // Displays the window and dispatches the Windows messages FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION ' ========================================================================================

' ======================================================================================== ' Main window procedure ' ======================================================================================== FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

SELECT CASE uMsg

' // If an application processes this message, it should return zero to continue
  ' // creation of the window. If the application returns –1, the window is destroyed
  ' // and the CreateWindowExW function returns a NULL handle.
  CASE WM_CREATE
     AfxEnableDarkModeForWindow(hwnd)
     RETURN 0

  ' // Theme has changed
  CASE WM_THEMECHANGED
     AfxEnableDarkModeForWindow(hwnd)
     RETURN 0

  ' // Sent when the user selects a command item from a menu, when a control sends a
  ' // notification message to its parent window, or when an accelerator keystroke is translated.
  CASE WM_COMMAND
     SELECT CASE CBCTL(wParam, lParam)
        CASE IDCANCEL
           ' // If ESC key pressed, close the application by sending an WM_CLOSE message
           IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN SendMessageW(hwnd, WM_CLOSE, 0, 0)
     END SELECT
     RETURN 0

  CASE WM_NOTIFY
     ' // Notification messages
     DIM dtp AS NMDATETIMECHANGE
     CBNMTYPESET(dtp, wParam, lParam)
     IF dtp.nmhdr.idfrom = IDC_DTPICKER THEN
        IF dtp.nmhdr.code = DTN_DATETIMECHANGE THEN
           ' // Get the selected date
           DIM wszDate AS WSTRING * 260
           GetDateFormatW LOCALE_USER_DEFAULT, DATE_LONGDATE, @dtp.st, NULL, wszDate, SIZEOF(wszDate)\2
           SetWindowText(GetDlgItem(hwnd, IDC_LABEL), "Selected date: " & wszDate)
        END IF
     END IF

  CASE WM_DESTROY
     ' // End the application by sending an WM_QUIT message
     PostQuitMessage(0)
     RETURN 0

END SELECT

' // Default processing of Windows messages FUNCTION = DefWindowProcW(hwnd, uMsg, wParam, lParam)

END FUNCTION ' ========================================================================================

Reference

  • Include file CDtPicker.inc
  • Defined in AfxNova/CDtPicker.inc:108
  • Documented in Windows/WIndows Controls/CDtPicker Class.md
  • Topic: CDtPicker Class