This sample illustrates date input with a dropdown calendar (defaulting to today's date using the =Today default text) and date/time input with up-down buttons and tabbing between fields.
The source code is located at C:\Program Files (x86)\Softelvdm\SftMask DLL 7.0\Samples\C\DateTime\DateTime.c or C:\Program Files\Softelvdm\SftMask DLL 7.0\Samples\C\DateTime\DateTime.c (on 32-bit Windows versions).
/****************************************************************************/ /* SftMask/DLL 7.0 - Masked Edit Control for C/C++ */ /* Copyright (C) 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ /* SftMask/DLL 7.0 sample. Guide: https://softelvdm.com/Vault/Softelvdm.com/llms/SftMask-DLL-7.0.txt, API reference: https://softelvdm.com/Vault/Softelvdm.com/llms/SftMask-DLL-7.0-reference.txt - see AGENTS.md. */ #include <windows.h> #include "SftMask.h" /* SftMask/DLL Header File */ #define SFTDARKMODE_IMPLEMENTATION #include "SftDarkMode.h" /* Dark mode support */ #include "resource.h" // application resources HINSTANCE g_hInst; // App Instance Handle /**********************************************************************/ /* Date and Date/Time Input */ /**********************************************************************/ static void InitDate(HWND hwndDlg) { HWND hwndEdit = GetDlgItem(hwndDlg, IDC_DATE); SFTMASK_CONTROL Ctl; Ctl.cbSize = sizeof(SFTMASK_CONTROL); SftMask_GetControlInfo(hwndEdit, &Ctl); Ctl.fAutoSize = TRUE; Ctl.iAlignment = ES_LEFT; Ctl.iBorderStyle = SFTMASK_BORDER_THIN; Ctl.iEditStyle = SFTMASK_EDITCALENDARDROPDOWN; Ctl.fDDButtonCalendar = TRUE; Ctl.calfDropOnFocus = FALSE; Ctl.lpszCaption = (LPTSTR) TEXT("&Date:"); Ctl.captionfTransparent = TRUE; Ctl.captioniPosition = SFTMASK_POSITIONLEFT; Ctl.captioniAlignment = ES_LEFT; Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE; Ctl.captionnSizePercent = 40; Ctl.lpszMask = (LPTSTR) TEXT("$D"); Ctl.lpszDefaultText = (LPTSTR) TEXT("=Today"); Ctl.iDefaultStyle = SFTMASK_DEFAULT_IMMEDIATE; Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO; SftMask_SetControlInfo(hwndEdit, &Ctl); } static void InitDateTime(HWND hwndDlg) { HWND hwndEdit = GetDlgItem(hwndDlg, IDC_DATETIME); SFTMASK_CONTROL Ctl; Ctl.cbSize = sizeof(SFTMASK_CONTROL); SftMask_GetControlInfo(hwndEdit, &Ctl); Ctl.fAutoSize = TRUE; Ctl.iAlignment = ES_LEFT; Ctl.iBorderStyle = SFTMASK_BORDER_THIN; Ctl.iEditStyle = SFTMASK_EDITUPDOWN; Ctl.fTabAdvance = TRUE; Ctl.lpszCaption = (LPTSTR) TEXT("Date/&Time:"); Ctl.captionfTransparent = TRUE; Ctl.captioniPosition = SFTMASK_POSITIONLEFT; Ctl.captioniAlignment = ES_LEFT; Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE; Ctl.captionnSizePercent = 40; Ctl.lpszMask = (LPTSTR) TEXT("$D $T"); Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO; SftMask_SetControlInfo(hwndEdit, &Ctl); } /**********************************************************************/ /* Center the main dialog */ /**********************************************************************/ static void CenterWindow(HWND hwnd) { RECT rc; RECT rcOwner; int x, y; GetWindowRect(hwnd, &rc); GetWindowRect(GetDesktopWindow(), &rcOwner); x = rcOwner.left + (((rcOwner.right - rcOwner.left) - (rc.right - rc.left)) / 2); y = rcOwner.top + (((rcOwner.bottom - rcOwner.top) - (rc.bottom - rc.top)) / 2); SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); } /**********************************************************************/ /* Dialog Proc */ /**********************************************************************/ INT_PTR CALLBACK MainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_APP))); InitDate(hwndDlg); InitDateTime(hwndDlg); SftDarkMode_ApplyToDialog(hwndDlg); CenterWindow(hwndDlg); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hwndDlg, 0); return TRUE; } break; } { INT_PTR dmResult; if (SftDarkMode_HandleDialogMessage(hwndDlg, msg, wParam, lParam, &dmResult)) return dmResult; } return FALSE; } /**********************************************************************/ /* WinMain */ /**********************************************************************/ int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow) { g_hInst = hinst; SftDarkMode_Init(); /* Dark mode support */ SftMask_RegisterApp(hinst); /* Register with SftMask/DLL */ DialogBox(g_hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDialogProc); SftMask_UnregisterApp(hinst); /* Unregister from SftMask/DLL */ return 0; }