The date field control and the month calendar control are used with the SftDate_xxx functions or the C++ classes CSftDate and CSftCalendar. In addition, the following standard Windows messages can be sent to a control by an application:
| Message | Description |
|---|---|
| WM_SETFONT, WM_GETFONT | Sets or retrieves the font of the control. |
| WM_SETTEXT, WM_GETTEXT, WM_GETTEXTLENGTH | Sets or retrieves the value of a date field control as text. |
| WM_SETREDRAW | Suspends or resumes redrawing while many settings are changed. |
| WM_ENABLE | The control has been enabled or disabled (EnableWindow). |
| WM_CANCELMODE | Cancels the operation in progress and closes the dropdown of a date field control. |
| WM_PRINTCLIENT | Renders the control into a device context. |
| WM_SETTINGCHANGE | Must be forwarded to the control by its parent window to follow the Windows dark mode setting. |
The messages of the Windows Date and Time Picker (DTM_xxx) and Month Calendar (MCM_xxx) controls are not supported. See Comparison with the Windows Date and Time Picker and Month Calendar.
The WM_SETFONT message defines the font used by the control.
hFont = (HFONT) wParam;
The font handle, or NULL to use the Windows message font.
fRedraw = (BOOL) LOWORD(lParam);
Set to TRUE to redraw the control, FALSE otherwise.
The font is used for the value of a date field control and its dropdown, and for the days and names of a month calendar control, unless a calendar font is defined using SetCalendarFont. A control in a dialog receives the dialog's font. Without a font, the control uses the Windows message font for the DPI of its monitor.
A control that sizes itself (SetAutoSize) adjusts its size when the font changes.
The font is owned by the application and must remain valid until the control is destroyed or another font is set. In a per-monitor DPI aware dialog, Windows sends the dialog's font for the new DPI itself when the dialog moves to a monitor with another DPI; an application that defines its own font sends a font of the appropriate size when it receives the NM_SFTDATE_DPI_CHANGED notification.
The WM_GETFONT message returns the handle of the font defined using WM_SETFONT, or NULL.
The WM_SETTEXT message (or the Windows API SetWindowText) sets the value of a date field control from a text.
The text is parsed like text typed in free-form editing: the NM_SFTDATE_TEXTPARSING notification is sent first, then the text is parsed in the format of the field and leniently in the formats of the culture. In range selection mode, the text can hold both dates, separated by the range separator (SetRangeSeparator). An empty text empties the field, if it allows an empty value or shows a check box.
The message returns TRUE if the value was set, or FALSE if the text cannot be parsed or the date is outside the range defined using SetMinDate and SetMaxDate. The value is not validated using NM_SFTDATE_VALUEVALIDATING; NM_SFTDATE_VALUECHANGED is sent if the value changes.
The WM_GETTEXT message (or the Windows API GetWindowText) retrieves the value of a date field control as it is shown, WM_GETTEXTLENGTH its length.
The text is empty if the field has no value (GetValue returns FALSE). In range selection mode, it holds both dates with the range separator. The value itself is retrieved using GetValue, which doesn't depend on the format or the culture.
The WM_SETREDRAW message suspends (wParam FALSE) or resumes (wParam TRUE) redrawing of the control. Resuming redraws the control.
The WM_ENABLE message is sent by Windows when the control is enabled or disabled using EnableWindow.
A disabled control is shown dimmed and doesn't respond to the mouse and keyboard. A date field control closes its dropdown when it is disabled.
The WM_CANCELMODE message cancels the operation in progress: a date field control closes its dropdown without applying a pending choice and stops spinning.
The WM_PRINTCLIENT message renders the control into the device context passed in wParam, for example for PrintWindow or animations.
The WM_SETTINGCHANGE message informs the control about a change of a Windows setting.
Windows sends WM_SETTINGCHANGE to top-level windows only. A control with the dark mode setting SFTDATE_DARKMODE_AUTO (SetDarkMode) follows the Windows "Choose your mode" setting only if its parent window forwards the message to it. SftDarkMode_HandleDialogMessage in SftDarkMode.h does this for dialogs (see Dark Mode).
The control also handles a change of the Windows high contrast setting and of the message font (when no font was defined using WM_SETFONT). High contrast changes reach the control without forwarding, through the WM_THEMECHANGED message Windows sends to every window.
See Also C/C++ API | Categories | Notifications