Borje You did a great job with this!
I just added a bit more flexibility for formatting the output,
and added the verification step that the Win32api suggests on the systemtime.
This is a very neat control!
------------------
Scott
mailto:[email protected][email protected]</A>
I just added a bit more flexibility for formatting the output,
and added the verification step that the Win32api suggests on the systemtime.
This is a very neat control!
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' A small DDT example of how to create and use Commctrl's Calendar. ' Written by Borje Hagsten. Updated by Scott Turchin for easier formatting of output ' Public Domain = free To use And modify. ' Ideas for usage: Databases of all kinds, "Insert date" functions ' in text editors, diaries, PIMs, etc.. :-) Or setting the expiration date on an application '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #Compile Exe #Include "WIN32API.INC" #Include "COMMCTRL.INC" %ID_LABEL = 10 %ID_CALENDAR = 20 Declare CallBack Function DlgCallback() Declare Function GetTimeandDate(sTime As SYSTEMTIME) As String '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' PBMAIN - build dialog and controls '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Function PbMain Dim hDlg As Long Local iccex As INIT_COMMON_CONTROLSEX 'Initialize the calendar iccex.dwSize = SizeOf(iccex) iccex.dwICC = %ICC_DATE_CLASSES Call InitCommonControlsEx(iccex) Dialog New 0, "Calendar demo",,, 196, 60, %WS_SYSMENU To hDlg Control Add Label, hDlg, %ID_LABEL, "Click at the Combo's down arrow.", 6, 30, 180, 14 Control Add Button, hDlg, %IDCANCEL, "&Close", 134, 6, 50, 14 Control Add "SysDateTimePick32", hDlg, %ID_CALENDAR, "", 6, 6, 120, 14, %WS_CHILD Or _ %WS_TABSTOP Or %WS_VISIBLE Or %DTS_LONGDATEFORMAT, , Call DlgCallback 'Note: You can also use "SysMonthCal32", to get the calendar only, ' but then you also have to set the height to e.g. 100 .. :-) 'See Commctrl.inc for other useful Constants and Type structures Dialog Show Modal hDlg Call DlgCallback End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ 'Format your output as you like '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Function GetTimeandDate(sTime As SYSTEMTIME) Export As String Local tDay As Asciiz * 64 Local tTime As Asciiz * 64 GetDateFormat %LOCALE_USER_DEFAULT, %NULL, sTime, "MMM dd',' yyyy", tDay, 64 'Use this to format the date GetTimeFormat %LOCALE_SYSTEM_DEFAULT, %TIME_NOSECONDS,sTime, ByVal %NULL, tTime, 64 'Use this to format the time Function = tDay + " " + tTime End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' The main callback function for all controls '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ CallBack Function DlgCallback() Local hdrX As NMDATETIMECHANGE Ptr Select Case CbMsg Case %WM_COMMAND If CbCtl = %IDCANCEL Then Dialog End CbHndl, (CbCtl = %IDOK) Case %WM_NOTIFY 'Use this to detect changes in the calendar hdrX = CbLparam Select Case @hdrX.hdr.code Case %DTN_CLOSEUP Case %DTN_DROPDOWN Case %DTN_DATETIMECHANGE 'Get selected date/time If @hdrx.dwFlags <> %GDT_VALID Then Exit Function 'Trust but verify SYSTEMTIME STRUCTURE Control Set Text CbHndl, %ID_LABEL, "Selected Date: " & GetTimeandDate(@hdrX.st) End Select End Select End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' The End '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Scott
mailto:[email protected][email protected]</A>
Comment