home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / csdtpckr / cscal.ctl (.txt) next >
Encoding:
Visual Basic Form  |  1998-10-31  |  20.5 KB  |  509 lines

  1. VERSION 5.00
  2. Begin VB.UserControl CSCal 
  3.    ClientHeight    =   315
  4.    ClientLeft      =   0
  5.    ClientTop       =   0
  6.    ClientWidth     =   1275
  7.    ScaleHeight     =   21
  8.    ScaleMode       =   3  'Pixel
  9.    ScaleWidth      =   85
  10.    ToolboxBitmap   =   "CSCal.ctx":0000
  11. Attribute VB_Name = "CSCal"
  12. Attribute VB_GlobalNameSpace = False
  13. Attribute VB_Creatable = True
  14. Attribute VB_PredeclaredId = False
  15. Attribute VB_Exposed = True
  16. Option Explicit
  17. ' Written By: Bob Walker
  18. '             bob@computersimple.com
  19. ' For       : Computer Simple, Inc.
  20. '             www.computersimple.com
  21. ' Constants needed
  22. Private Const DATETIMEPICK_CLASS = "SysDateTimePick32"
  23. Private Const ICC_DATE_CLASSES = &H100&
  24. Private Const SW_HIDE = 0
  25. Private Const SW_SHOWNORMAL = 1
  26. Private Const GDTR_MIN = 1&
  27. Private Const GDTR_MAX = 2&
  28. Private Const DTM_GETSYSTEMTIME = (DTM_FIRST + 1)
  29. Private Const DTM_SETSYSTEMTIME = (DTM_FIRST + 2)
  30. Private Const DTM_GETRANGE = (DTM_FIRST + 3)
  31. Private Const DTM_SETRANGE = (DTM_FIRST + 4)
  32. Private Const DTM_SETFORMAT = (DTM_FIRST + 5)
  33. Private Const DTM_SETMCCOLOR = (DTM_FIRST + 6)
  34. Private Const DTM_GETMCCOLOR = (DTM_FIRST + 7)
  35. Private Const DTM_SETMCFONT = (DTM_FIRST + 9)
  36. Private Const DTM_GETMCFONT = (DTM_FIRST + 10)
  37. Private Const DTS_UPDOWN = &H1&            '// use UPDOWN instead of MONTHCAL
  38. Private Const DTS_SHOWNONE = &H2&          '// allow a NONE selection
  39. Private Const DTS_SHORTDATEFORMAT = &H0&   '// use the short date format (app must forward WM_WININICHANGE messages)
  40. Private Const DTS_LONGDATEFORMAT = &H4&    '// use the long date format (app must forward WM_WININICHANGE messages)
  41. Private Const DTS_TIMEFORMAT = &H9&        '// use the time format (app must forward WM_WININICHANGE messages)
  42. Private Const DTS_APPCANPARSE = &H10&      '// allow user entered strings (app MUST respond to DTN_USERSTRING)
  43. Private Const DTS_RIGHTALIGN = &H20&       '// right-align popup instead of left-align it
  44. Private Const MCSC_TEXT = 1&         '   // the dates
  45. Private Const MCSC_TITLEBK = 2&      '   // background of the title and the text day names
  46. Private Const MCSC_TITLETEXT = 3&    '   // text of the date string in the title
  47. Private Const MCSC_MONTHBK = 4&      '   // background within the month cal
  48. Private Const MCSC_TRAILINGTEXT = 5& '   // the text color of header & trailing days
  49. Private Type ICCE
  50.     lSize As Long
  51.     lICC As Long
  52. End Type
  53. Private Declare Function InitCommonControlsEx Lib "Comctl32.dll" (iccex As ICCE) As Boolean
  54. Private Declare Function CreateWindowEX Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  55. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  56. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
  57. 'Default Property Values:
  58. Const m_def_Value = 0
  59. Const m_def_Min = Empty
  60. Const m_def_Max = Empty
  61. Const m_def_UpDown = False
  62. Const m_def_AlignRight = False
  63. Const m_def_TimePick = False
  64. Const m_def_FDOW = vbUseSystemDayOfWeek
  65. Const m_def_ShowToday = False
  66. Const m_def_ShowWeeks = False
  67. Const m_def_BackColor = SystemColorConstants.vbWindowBackground
  68. Const m_def_TextColor = SystemColorConstants.vbWindowText
  69. Const m_def_TitleBackColor = SystemColorConstants.vbActiveTitleBar
  70. Const m_def_TitleTextColor = SystemColorConstants.vbTitleBarText
  71. Const m_def_TrailTextColor = SystemColorConstants.vbGrayText
  72. 'Property Variables:
  73. Dim m_Value As Date
  74. Dim m_Min As Variant
  75. Dim m_Max As Variant
  76. Dim m_UpDown As Boolean
  77. Dim m_AlignRight As Boolean
  78. Dim m_TimePick As Boolean
  79. Dim m_FDOW As VbDayOfWeek
  80. Dim m_ShowToday As Boolean
  81. Dim m_ShowWeeks As Boolean
  82. Dim m_BackColor As OLE_COLOR
  83. Dim m_TextColor As OLE_COLOR
  84. Dim m_TitleBackColor As OLE_COLOR
  85. Dim m_TitleTextColor As OLE_COLOR
  86. Dim m_TrailTextColor As OLE_COLOR
  87. Dim m_hWnd As Long ' Stores the handle to the DatePicker
  88. Dim m_hWndProc As Long ' Stores the handle to the window subclass process
  89. Dim m_hWndUCProc As Long ' Stores the handle to the user control subclass process
  90. Public Event Change()
  91. Attribute Change.VB_Description = "Event raised when the Value has been changed."
  92. ' The HWnd??? properties are hidden, for use by
  93. ' the subclassed routines. They cannot be declared
  94. ' friend properties because the object reference kept in
  95. ' the collection could not access them as such.
  96. Public Property Let HWndValue(ByVal New_Value As Date)
  97. Attribute HWndValue.VB_MemberFlags = "40"
  98.     If CanPropertyChange("Value") Then
  99.         m_Value = New_Value
  100.         PropertyChanged "Value"
  101.         RaiseEvent Change
  102.     End If
  103. End Property
  104. Public Property Get HWndProc() As Long
  105. Attribute HWndProc.VB_MemberFlags = "40"
  106.     HWndProc = m_hWndProc
  107. End Property
  108. Public Property Get HWndUCProc() As Long
  109. Attribute HWndUCProc.VB_MemberFlags = "40"
  110.     HWndUCProc = m_hWndUCProc
  111. End Property
  112. Public Property Get hwnd() As Long
  113. Attribute hwnd.VB_UserMemId = -515
  114. Attribute hwnd.VB_MemberFlags = "40"
  115.     hwnd = UserControl.hwnd
  116. End Property
  117. Public Property Get HWndDP() As Long
  118. Attribute HWndDP.VB_MemberFlags = "40"
  119.     HWndDP = m_hWnd
  120. End Property
  121. Private Sub UserControl_GotFocus()
  122.     ' Move the focus into the textbox portion of the
  123.     ' date/time picker when the control receives focus
  124.     If m_hWnd <> 0 Then apiSetFocus m_hWnd
  125. End Sub
  126. Private Sub UserControl_Initialize()
  127.     Dim iccex As ICCE
  128.     With iccex
  129.         .lSize = LenB(iccex)
  130.         .lICC = ICC_DATE_CLASSES
  131.     End With
  132.     InitCommonControlsEx iccex
  133. End Sub
  134. Private Sub UserControl_InitProperties()
  135.     Set UserControl.Font = Ambient.Font
  136.     m_BackColor = m_def_BackColor
  137.     m_TextColor = m_def_TextColor
  138.     m_TitleBackColor = m_def_TitleBackColor
  139.     m_TitleTextColor = m_def_TitleTextColor
  140.     m_TrailTextColor = m_def_TrailTextColor
  141.     m_Min = m_def_Min
  142.     m_Max = m_def_Max
  143.     m_UpDown = m_def_UpDown
  144.     m_AlignRight = m_def_AlignRight
  145.     m_TimePick = m_def_TimePick
  146.     m_FDOW = m_def_FDOW
  147.     m_ShowToday = m_def_ShowToday
  148.     m_ShowWeeks = m_def_ShowWeeks
  149.     m_Value = m_def_Value
  150.     ' Only SubClass when in Run Mode, otherwise it'll crash
  151.     ' because the ChangeWinProc() isn't available (not running)
  152.     If Ambient.UserMode = True Then
  153.         'SubClass UserControl.hWnd
  154.         scCollection.Add Me, "H" & Hex(hwnd)
  155.         m_hWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf ChangeWinProc)
  156.     End If
  157.     Create
  158. End Sub
  159. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  160.     UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
  161.     Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
  162.     m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
  163.     m_TextColor = PropBag.ReadProperty("TextColor", m_def_TextColor)
  164.     m_TitleBackColor = PropBag.ReadProperty("TitleBackColor", m_def_TitleBackColor)
  165.     m_TitleTextColor = PropBag.ReadProperty("TitleTextColor", m_def_TitleTextColor)
  166.     m_TrailTextColor = PropBag.ReadProperty("TrailTextColor", m_def_TrailTextColor)
  167.     m_Min = PropBag.ReadProperty("Min", m_def_Min)
  168.     m_Max = PropBag.ReadProperty("Max", m_def_Max)
  169.     m_UpDown = PropBag.ReadProperty("UpDown", m_def_UpDown)
  170.     m_AlignRight = PropBag.ReadProperty("AlignRight", m_def_AlignRight)
  171.     m_TimePick = PropBag.ReadProperty("TimePick", m_def_TimePick)
  172.     m_FDOW = PropBag.ReadProperty("FDOW", m_def_FDOW)
  173.     m_ShowToday = PropBag.ReadProperty("ShowToday", m_def_ShowToday)
  174.     m_ShowWeeks = PropBag.ReadProperty("ShowWeeks", m_def_ShowWeeks)
  175.     m_Value = PropBag.ReadProperty("Value", m_def_Value)
  176.         
  177.     ' Only SubClass when in Run Mode, othewise it'll crash
  178.     ' because the ChangeWinProc() isn't available (not running)
  179.     If Ambient.UserMode = True Then
  180.         'SubClass UserControl.hWnd
  181.         scCollection.Add Me, "H" & Hex(hwnd)
  182.         m_hWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf ChangeWinProc)
  183.     End If
  184.         
  185.     Create
  186. End Sub
  187. Private Sub UserControl_Resize()
  188.     ' Whenever the user control is resized,
  189.     ' re-create the window to fit the new size
  190.     Create
  191. End Sub
  192. Private Sub UserControl_Terminate()
  193.     If m_hWndProc <> 0 Then
  194.         ' UnSubclass
  195.         SetWindowLong hwnd, GWL_WNDPROC, m_hWndProc
  196.         scCollection.Remove "H" & Hex(hwnd)
  197.     End If
  198.     Destroy
  199. End Sub
  200. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  201. 'MappingInfo=UserControl,UserControl,-1,Enabled
  202. Public Property Get Enabled() As Boolean
  203. Attribute Enabled.VB_Description = "Determines whether focus and user input are accepted by the control."
  204.     Enabled = UserControl.Enabled
  205. End Property
  206. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  207.     UserControl.Enabled() = New_Enabled
  208.     PropertyChanged "Enabled"
  209.     Create
  210. End Property
  211. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  212. 'MappingInfo=UserControl,UserControl,-1,Font
  213. Public Property Get Font() As Font
  214. Attribute Font.VB_Description = "Determine the font used in displaying the textbox and the dropdown."
  215.     Set Font = UserControl.Font
  216. End Property
  217. Public Property Set Font(ByVal New_Font As Font)
  218.     Set UserControl.Font = New_Font
  219.     PropertyChanged "Font"
  220.     Create
  221. End Property
  222. 'Write property values to storage
  223. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  224.     Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
  225.     Call PropBag.WriteProperty("Font", Font, Ambient.Font)
  226.     Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
  227.     Call PropBag.WriteProperty("TextColor", m_TextColor, m_def_TextColor)
  228.     Call PropBag.WriteProperty("TitleBackColor", m_TitleBackColor, m_def_TitleBackColor)
  229.     Call PropBag.WriteProperty("TitleTextColor", m_TitleTextColor, m_def_TitleTextColor)
  230.     Call PropBag.WriteProperty("TrailTextColor", m_TrailTextColor, m_def_TrailTextColor)
  231.     Call PropBag.WriteProperty("Min", m_Min, m_def_Min)
  232.     Call PropBag.WriteProperty("Max", m_Max, m_def_Max)
  233.     Call PropBag.WriteProperty("UpDown", m_UpDown, m_def_UpDown)
  234.     Call PropBag.WriteProperty("AlignRight", m_AlignRight, m_def_AlignRight)
  235.     Call PropBag.WriteProperty("TimePick", m_TimePick, m_def_TimePick)
  236.     Call PropBag.WriteProperty("FDOW", m_FDOW, m_def_FDOW)
  237.     Call PropBag.WriteProperty("ShowToday", m_ShowToday, m_def_ShowToday)
  238.     Call PropBag.WriteProperty("ShowWeeks", m_ShowWeeks, m_def_ShowWeeks)
  239.     Call PropBag.WriteProperty("Value", m_Value, m_def_Value)
  240. End Sub
  241. Public Property Get BackColor() As OLE_COLOR
  242. Attribute BackColor.VB_Description = "The background color used for the dropdown."
  243.     BackColor = m_BackColor
  244. End Property
  245. Public Property Let BackColor(ByVal New_Color As OLE_COLOR)
  246.     m_BackColor = New_Color
  247.     PropertyChanged "BackColor"
  248.     If m_hWnd = 0 Then
  249.         Create
  250.     Else
  251.         SendMessage m_hWnd, DTM_SETMCCOLOR, _
  252.             MCSC_MONTHBK, ByVal OleColor(BackColor)
  253.     End If
  254. End Property
  255. Public Property Get TextColor() As OLE_COLOR
  256. Attribute TextColor.VB_Description = "Color of the text used to display the dates for the current month."
  257.     TextColor = m_TextColor
  258. End Property
  259. Public Property Let TextColor(ByVal New_Color As OLE_COLOR)
  260.     m_TextColor = New_Color
  261.     PropertyChanged "TextColor"
  262.     If m_hWnd = 0 Then
  263.         Create
  264.     Else
  265.         SendMessage m_hWnd, DTM_SETMCCOLOR, _
  266.             MCSC_TEXT, ByVal OleColor(TextColor)
  267.     End If
  268. End Property
  269. Public Property Get TitleBackColor() As OLE_COLOR
  270. Attribute TitleBackColor.VB_Description = "Color of the background displayed in the dropdown title bar."
  271.     TitleBackColor = m_TitleBackColor
  272. End Property
  273. Public Property Let TitleBackColor(ByVal New_Color As OLE_COLOR)
  274.     m_TitleBackColor = New_Color
  275.     PropertyChanged "TitleBackColor"
  276.     If m_hWnd = 0 Then
  277.         Create
  278.     Else
  279.         SendMessage m_hWnd, DTM_SETMCCOLOR, _
  280.             MCSC_TITLEBK, ByVal OleColor(TitleBackColor)
  281.     End If
  282. End Property
  283. Public Property Get TitleTextColor() As OLE_COLOR
  284. Attribute TitleTextColor.VB_Description = "Color of the font used to display the month/year at the top of the dropdown."
  285.     TitleTextColor = m_TitleTextColor
  286. End Property
  287. Public Property Let TitleTextColor(ByVal New_Color As OLE_COLOR)
  288.     m_TitleTextColor = New_Color
  289.     PropertyChanged "TitleTextColor"
  290.     If m_hWnd = 0 Then
  291.         Create
  292.     Else
  293.         SendMessage m_hWnd, DTM_SETMCCOLOR, _
  294.             MCSC_TITLETEXT, ByVal OleColor(TitleTextColor)
  295.     End If
  296. End Property
  297. Public Property Get TrailTextColor() As OLE_COLOR
  298. Attribute TrailTextColor.VB_Description = "Color of the font used to display the leading and trailing dates from the prior/next month in the dropdown."
  299.     TrailTextColor = m_TrailTextColor
  300. End Property
  301. Public Property Let TrailTextColor(ByVal New_Color As OLE_COLOR)
  302.     m_TrailTextColor = New_Color
  303.     PropertyChanged "TrailTextColor"
  304.     If m_hWnd = 0 Then
  305.         Create
  306.     Else
  307.         SendMessage m_hWnd, DTM_SETMCCOLOR, _
  308.             MCSC_TRAILINGTEXT, ByVal OleColor(TrailTextColor)
  309.     End If
  310. End Property
  311. Public Property Get Min() As Variant
  312. Attribute Min.VB_Description = "Set/get the Lowest date/time value selectable by the user."
  313.     Min = m_Min
  314. End Property
  315. Public Property Let Min(ByVal New_Min As Variant)
  316.     Dim stRange(0 To 1) As SYSTEMTIME
  317.     m_Min = IIf(IsDate(New_Min), New_Min, Empty)
  318.     PropertyChanged "Min"
  319.     If m_hWnd = 0 Then
  320.         Create
  321.     Else
  322.         If Not IsEmpty(m_Min) Then
  323.             SetDate m_Min, stRange(0)
  324.             SendMessage m_hWnd, DTM_SETRANGE, GDTR_MIN, stRange(0)
  325.         End If
  326.     End If
  327. End Property
  328. Public Property Get Max() As Variant
  329. Attribute Max.VB_Description = "Set/Get the highest date/time value selectable by the user."
  330.     Max = m_Max
  331. End Property
  332. Public Property Let Max(ByVal New_Max As Variant)
  333.     Dim stRange(0 To 1) As SYSTEMTIME
  334.     m_Max = IIf(IsDate(New_Max), New_Max, Empty)
  335.     PropertyChanged "Max"
  336.     If m_hWnd = 0 Then
  337.         Create
  338.     Else
  339.         If Not IsEmpty(m_Max) Then
  340.             SetDate m_Max, stRange(1)
  341.             SendMessage m_hWnd, DTM_SETRANGE, GDTR_MAX, stRange(0)
  342.         End If
  343.     End If
  344. End Property
  345. Public Property Get UpDown() As Boolean
  346. Attribute UpDown.VB_Description = "If true, displays an UpDown control on the right edge of the textbox and allow the user to spin/edit the value."
  347.     UpDown = m_UpDown
  348. End Property
  349. Public Property Let UpDown(ByVal New_UpDown As Boolean)
  350.     m_UpDown = New_UpDown
  351.     PropertyChanged "UpDown"
  352.     Create
  353. End Property
  354. Public Property Get AlignRight() As Boolean
  355. Attribute AlignRight.VB_Description = "Determine whether to display the dropdown aligned to the right edge of the control, or the left."
  356.     AlignRight = m_AlignRight
  357. End Property
  358. Public Property Let AlignRight(ByVal New_AlignRight As Boolean)
  359.     m_AlignRight = New_AlignRight
  360.     PropertyChanged "AlignRight"
  361.     Create
  362. End Property
  363. Public Property Get TimePick() As Boolean
  364. Attribute TimePick.VB_Description = "Determine whether the control will be used to pick times or dates."
  365.     TimePick = m_TimePick
  366. End Property
  367. Public Property Let TimePick(ByVal New_Value As Boolean)
  368.     m_TimePick = New_Value
  369.     PropertyChanged "TimePick"
  370.     Create
  371. End Property
  372. Public Property Get FirstDayOfWeek() As VbDayOfWeek
  373. Attribute FirstDayOfWeek.VB_Description = "Determine the order of the days of week displayed on the dropdown."
  374.     FirstDayOfWeek = m_FDOW
  375. End Property
  376. Public Property Let FirstDayOfWeek(ByVal New_Value As VbDayOfWeek)
  377.     m_FDOW = New_Value
  378.     PropertyChanged "FDOW"
  379. End Property
  380. Public Property Get ShowToday() As Boolean
  381. Attribute ShowToday.VB_Description = "Determine whether to display the today date and circle today's date on the dropdown calendar."
  382.     ShowToday = m_ShowToday
  383. End Property
  384. Public Property Let ShowToday(ByVal New_Value As Boolean)
  385.     m_ShowToday = New_Value
  386.     PropertyChanged "ShowToday"
  387. End Property
  388. Public Property Get ShowWeeks() As Boolean
  389. Attribute ShowWeeks.VB_Description = "Determine whether to display the week numbers alongside the dropdown month calendar."
  390.     ShowWeeks = m_ShowWeeks
  391. End Property
  392. Public Property Let ShowWeeks(ByVal New_Value As Boolean)
  393.     m_ShowWeeks = New_Value
  394.     PropertyChanged "ShowWeeks"
  395. End Property
  396. ' The method used to create the date picker(s) from the API
  397. ' calls, based on the various customized settings
  398. Private Function Create() As Boolean
  399.     Dim fTemp As IFont
  400.     Dim stRange(0 To 1) As SYSTEMTIME
  401.     Dim stDateTime As SYSTEMTIME
  402.     Dim stFlags As Long
  403.     If m_hWnd <> 0 Then Destroy
  404.     m_hWnd = CreateWindowEX(0, DATETIMEPICK_CLASS, "DateTime", _
  405.          (WS_CHILD Or WS_VISIBLE Or Abs(UpDown) Or IIf(Enabled, 0, WS_DISABLED)) Or _
  406.          (IIf(AlignRight, DTS_RIGHTALIGN, 0) Or IIf(TimePick, DTS_TIMEFORMAT, 0)), _
  407.           0&, 0&, ScaleWidth, ScaleHeight, _
  408.           UserControl.hwnd, 0&, App.hInstance, ByVal 0&)
  409.     ' Set to the saved date value
  410.     SetDate m_Value, stDateTime
  411.     SendMessage m_hWnd, DTM_SETSYSTEMTIME, 0&, stDateTime
  412.     ' Change Colors
  413.     '   the dates
  414.     SendMessage m_hWnd, DTM_SETMCCOLOR, _
  415.         MCSC_TEXT, ByVal OleColor(TextColor)
  416.         
  417.     '   background of the title
  418.     SendMessage m_hWnd, DTM_SETMCCOLOR, _
  419.         MCSC_TITLEBK, ByVal OleColor(TitleBackColor)
  420.         
  421.     SendMessage m_hWnd, DTM_SETMCCOLOR, _
  422.         MCSC_TITLETEXT, ByVal OleColor(TitleTextColor)
  423.         
  424.     '   background within the month cal
  425.     SendMessage m_hWnd, DTM_SETMCCOLOR, _
  426.         MCSC_MONTHBK, ByVal OleColor(BackColor)
  427.         
  428.     '   the text color of header & trailing days
  429.     SendMessage m_hWnd, DTM_SETMCCOLOR, _
  430.         MCSC_TRAILINGTEXT, ByVal OleColor(TrailTextColor)
  431.     ' Convert/Set Font
  432.     '   need to convert to an IFont to obtain the hFont
  433.     '   property used to set a calendar font.
  434.     Set fTemp = Font
  435.     SendMessage m_hWnd, WM_SETFONT, _
  436.         fTemp.hFont, ByVal False
  437.     SendMessage m_hWnd, DTM_SETMCFONT, _
  438.         fTemp.hFont, ByVal False
  439.     ' Set Min/Max Range
  440.     stFlags = 0
  441.     If Not IsEmpty(Min) Then
  442.         SetDate Min, stRange(0)
  443.         stFlags = GDTR_MIN
  444.     End If
  445.     If Not IsEmpty(Max) Then
  446.         SetDate Max, stRange(1)
  447.         stFlags = stFlags + GDTR_MAX
  448.     End If
  449.     If stFlags > 0 Then
  450.         SendMessage m_hWnd, DTM_SETRANGE, stFlags, stRange(0)
  451.     End If
  452.     'SubClass Only in run mode.
  453.     If Ambient.UserMode = True Then
  454.         scCollection.Add Me, "U" & Hex(m_hWnd)
  455.         m_hWndUCProc = SetWindowLong(m_hWnd, GWL_WNDPROC, AddressOf ToggleWinProc)
  456.     Else
  457.         m_hWndUCProc = 0
  458.     End If
  459.     ShowWindow m_hWnd, SW_SHOWNORMAL
  460. End Function
  461. ' Method used to destroy the created control(s).
  462. Private Function Destroy() As Boolean
  463.     ' UnSubClass
  464.     If m_hWndUCProc <> 0 Then
  465.         scCollection.Remove "U" & Hex(m_hWnd)
  466.         SetWindowLong m_hWnd, GWL_WNDPROC, m_hWndUCProc
  467.         m_hWndUCProc = 0
  468.     End If
  469.     If m_hWnd <> 0 Then DestroyWindow m_hWnd
  470.     m_hWnd = 0
  471. End Function
  472. ' Value returns Empty if either the date is not valid,
  473. ' or if the date has not yet been set. Otherwise return
  474. ' the date/time portion of the value the user selected.
  475. Public Property Get Value() As Variant
  476. Attribute Value.VB_Description = "The value property is used to get/set the current date/time displayed in the control."
  477. Attribute Value.VB_UserMemId = 0
  478. Attribute Value.VB_MemberFlags = "23c"
  479.     If Not IsDate(m_Value) Then
  480.         Value = Empty
  481.     ElseIf m_Value = m_def_Value Then
  482.         Value = Empty
  483.     Else
  484.         If TimePick Then
  485.             Value = TimeValue(m_Value)
  486.         Else
  487.             Value = DateValue(m_Value)
  488.         End If
  489.     End If
  490. End Property
  491. Public Property Let Value(ByVal New_Value As Variant)
  492.     Dim stDateTime As SYSTEMTIME
  493.     If CanPropertyChange("Value") Then
  494.         If m_hWnd = 0 Then Exit Property
  495.         
  496.         If Not IsDate(New_Value) Then New_Value = m_def_Value
  497.         m_Value = New_Value
  498.         
  499.         ' Defaults to today
  500.         SetDate m_Value, stDateTime
  501.         
  502.         SendMessage m_hWnd, DTM_SETSYSTEMTIME, 0&, stDateTime
  503.         
  504.         PropertyChanged "Value"
  505.         RaiseEvent Change
  506.         
  507.     End If
  508. End Property
  509.