=====Using the Date and Time Picker===== //by Richard Russell, May 2006//\\ \\ One of the standard controls provided by the Windows API is the Date and Time Picker. This can be used when you want the user to enter a date or a time into your program. For date entry Windows can display a small clickable calendar:\\ \\ {{dtp.gif}}\\ \\ You can display the Date/Time Picker either on your main output window or in a dialogue box.\\ \\ ==== Output window ==== \\ To display a Date/Time picker on the output window use code similar to the following:\\ \\ INSTALL @lib$+"WINLIB5" ICC_DATE_CLASSES = &100 DIM iccx{Size%, ICC%} : REM INITCOMMONCONTROLSEX structure iccx.Size% = 8 iccx.ICC% = ICC_DATE_CLASSES SYS "InitCommonControlsEx", iccx{} hdtp% = FN_createwindow("SysDateTimePick32", "", x%, y%, cx%, cy%, 0, style%, 0) Here **x%,y%** is the position at which the Date/Time picker should be displayed, **cx%,cy%** is the size of the Date/Time picker window and **style%** is one of the following values (the figures in brackets are suggested window sizes for the different styles):\\ \\ * 0 - to display a date picker using the short date format (cx%=88, cy%=20) * **4** - to display a date picker using the long date format (cx%=120, cy%=20) * **9** - to display a time picker (cx%=72, cy%=20) \\ To read the currently selected date or time from the control use code similar to the following:\\ \\ DIM systemtime{Year{l&,h&}, Month{l&,h&}, DayOfWeek{l&,h&}, Day{l&,h&}, \ \ Hour{l&,h&}, Minute{l&,h&}, Second{l&,h&}, Milliseconds{l&,h&}} DTM_GETSYSTEMTIME = &1001 SYS "SendMessage", hdtp%, DTM_GETSYSTEMTIME, 0, systemtime{} day% = systemtime.Day.l& month% = systemtime.Month.l& year% = systemtime.Year.h& * 256 + systemtime.Year.l& hour% = systemtime.Hour.l& minute% = systemtime.Minute.l& second% = systemtime.Second.l& To close the control use the following code:\\ \\ PROC_closewindow(hdtp%) \\ ==== Dialogue box ==== \\ To display a Date/Time picker in a dialogue box use code similar to the following:\\ \\ INSTALL @lib$+"WINLIB2" ICC_DATE_CLASSES = &100 WS_VISIBLE = &10000000 WS_CHILD = &40000000 WS_GROUP = &20000 BS_DEFPUSHBUTTON = 1 DIM iccx{Size%, ICC%} : REM INITCOMMONCONTROLSEX structure iccx.Size% = 8 iccx.ICC% = ICC_DATE_CLASSES SYS "InitCommonControlsEx", iccx{} dtpdlg% = FN_newdialog("Date/Time picker", 20, 20, 150, 140, 8, 300) PROC_dlgctrl(dtpdlg%, "", 101, 8, 8, 64, 14, \ \ WS_VISIBLE + WS_CHILD + style%, "SysDateTimePick32") PROC_pushbutton(dtpdlg%, "OK", 1, 12, 120, 56, 14, WS_GROUP + BS_DEFPUSHBUTTON) PROC_pushbutton(dtpdlg%, "Cancel", 2, 80, 120, 56, 14, 0) PROC_showdialog(dtpdlg%) Where **style%** has one of the values listed above. Again the size of the Date/Time picker control will need to be modified according to the style, but here the size is specified in dialogue box units rather than pixels (see the main [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#dlgitem|BBC BASIC for Windows documentation]]).\\ \\ To read the currently selected date or time from the control when the OK button is clicked use code similar to the following:\\ \\ click% = 0 ON SYS click% = @wparam% AND &FFFF : RETURN REPEAT WAIT 1 UNTIL !dtpdlg% = 0 OR click% = 1 OR click% = 2 ON SYS OFF DTM_GETSYSTEMTIME = &1001 IF click% = 1 THEN DIM systemtime{Year{l&,h&}, Month{l&,h&}, DayOfWeek{l&,h&}, Day{l&,h&}, \ \ Hour{l&,h&}, Minute{l&,h&}, Second{l&,h&}, Milliseconds{l&,h&}} SYS "SendDlgItemMessage", !dtpdlg%, 101, DTM_GETSYSTEMTIME, 0, systemtime{} day% = systemtime.Day.l& month% = systemtime.Month.l& year% = systemtime.Year.h& * 256 + systemtime.Year.l& hour% = systemtime.Hour.l& minute% = systemtime.Minute.l& second% = systemtime.Second.l& ENDIF PROC_closedialog(dtpdlg%) You will want to use **ON ERROR** and **ON CLOSE** statements to ensure that "PROC_closedialog" is called even if the program is terminated unexpectedly.