Disclaimer: I am dealing with dates in the American format of Month/Day/Year.
Sending the message of %DTM_SETRANGE to a calendar controls allows us to set the range of a date picker control. The problem I am having is two-fold:
1. The range will not wait to validate until it gets the entire date. For example if the calendar control has a date of 9/24/2008 and a range that goes from 9/24/2008 to 2/1/2009. When I type 2 for the month, it will not allow it. I assume this is because it is validating "2/24/2008" but that is not what I am trying to type. If I try to start with the date then I get other problems because it appears to validate "9/24/2009." But if I use my mouse and click on the pop-up part of the control then I can get to the correct date. This is really annoying. Has anybody encountered this before? If so, what are choices of work-arounds. I guess it is possible to create my own validation when the NM_KILLFOCUS notification is sent. However, I am looking for better ideas.
2. This is the fun part.
Here is an example:
The above example will allow the user to type in "12/30/2009". If the user types in "12/31/2009" it will change it to "12/31/2008." I can however, use the pop-up part of the control and choose "12/31/2008." So the validation again seems odd. Again the only work-around I can think of is to do my own validation of the range using the NM_KILLFOCUS notification. Can somebody explain this control's behavior to me? Can anybody think of any other work-around?
Thanks!
Sending the message of %DTM_SETRANGE to a calendar controls allows us to set the range of a date picker control. The problem I am having is two-fold:
1. The range will not wait to validate until it gets the entire date. For example if the calendar control has a date of 9/24/2008 and a range that goes from 9/24/2008 to 2/1/2009. When I type 2 for the month, it will not allow it. I assume this is because it is validating "2/24/2008" but that is not what I am trying to type. If I try to start with the date then I get other problems because it appears to validate "9/24/2009." But if I use my mouse and click on the pop-up part of the control then I can get to the correct date. This is really annoying. Has anybody encountered this before? If so, what are choices of work-arounds. I guess it is possible to create my own validation when the NM_KILLFOCUS notification is sent. However, I am looking for better ideas.
2. This is the fun part.

Code:
#COMPILE EXE #DIM ALL #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF #IF NOT %DEF(%COMMCTRL_INC) #INCLUDE "COMMCTRL.INC" #ENDIF '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ %IDD_DIALOG1 = 101 %IDC_SYSDATETIMEPICK32_1 = 1002 '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ FUNCTION PBMAIN() ShowDIALOG1 %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowDIALOG1Proc() LOCAL systime() AS SYSTEMTIME LOCAL hctl, x AS LONG DIM SYSTIME(1) SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler systime(0).wYear = 2008 systime(0).wMonth = 1 systime(0).wDay = 1 systime(1).wYear = 2009 systime(1).wMonth = 12 systime(1).wDay = 31 CONTROL HANDLE CBHNDL, %IDC_SYSDATETIMEPICK32_1 TO hCtl X=SendMessage(HCTL, %DTM_SETRANGE, %GDTR_MIN OR %GDTR_MAX, VARPTR(systime(0))) CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_SYSDATETIMEPICK32_1 END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD DIALOG NEW hParent, "Dialog1", 270, 249, 247, 114, TO hDlg CONTROL ADD "SysDateTimePick32", hDlg, %IDC_SYSDATETIMEPICK32_1, _ "SysDateTimePick32_1", 55, 50, 80, 15, %WS_CHILD OR %WS_VISIBLE OR _ %WS_TABSTOP OR %DTS_SHORTDATEFORMAT, %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt FUNCTION = lRslt END FUNCTION
Thanks!
Comment