GuiDateTimePicker.au3 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #include-once
  2. #include "DateTimeConstants.au3"
  3. #include "Memory.au3"
  4. #include "SendMessage.au3"
  5. #include "StructureConstants.au3"
  6. #include "UDFGlobalID.au3"
  7. #include "WinAPIConv.au3"
  8. ;~ #include "WinAPIGdiInternals.au3"
  9. #include "WinAPISysInternals.au3"
  10. ; #INDEX# =======================================================================================================================
  11. ; Title .........: Date_Time_Picker
  12. ; AutoIt Version : 3.3.14.5
  13. ; Description ...: Functions that assist with date and time picker (DTP) control management.
  14. ; A date and time picker (DTP) control provides a simple and intuitive interface through which to exchange date
  15. ; and time information with a user. For example, with a DTP control you can ask the user to enter a date and
  16. ; then retrieve his or her selection with ease.
  17. ; Author(s) .....: Paul Campbell (PaulIA)
  18. ; ===============================================================================================================================
  19. ; #VARIABLES# ===================================================================================================================
  20. Global $__g_hDTLastWnd
  21. ; ===============================================================================================================================
  22. ; #CONSTANTS# ===================================================================================================================
  23. Global Const $__DTPCONSTANT_ClassName = "SysDateTimePick32"
  24. ; ===============================================================================================================================
  25. ; #CURRENT# =====================================================================================================================
  26. ; _GUICtrlDTP_Create
  27. ; _GUICtrlDTP_Destroy
  28. ; _GUICtrlDTP_GetMCColor
  29. ; _GUICtrlDTP_GetMCFont
  30. ; _GUICtrlDTP_GetMonthCal
  31. ; _GUICtrlDTP_GetRange
  32. ; _GUICtrlDTP_GetRangeEx
  33. ; _GUICtrlDTP_GetSystemTime
  34. ; _GUICtrlDTP_GetSystemTimeEx
  35. ; _GUICtrlDTP_SetFormat
  36. ; _GUICtrlDTP_SetMCColor
  37. ; _GUICtrlDTP_SetMCFont
  38. ; _GUICtrlDTP_SetRange
  39. ; _GUICtrlDTP_SetRangeEx
  40. ; _GUICtrlDTP_SetSystemTime
  41. ; _GUICtrlDTP_SetSystemTimeEx
  42. ; ===============================================================================================================================
  43. ; #FUNCTION# ====================================================================================================================
  44. ; Author ........: Paul Campbell (PaulIA)
  45. ; Modified.......: Gary Frost
  46. ; ===============================================================================================================================
  47. Func _GUICtrlDTP_Create($hWnd, $iX, $iY, $iWidth = 120, $iHeight = 21, $iStyle = 0x00000000, $iExStyle = 0x00000000)
  48. $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE)
  49. Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
  50. If @error Then Return SetError(@error, @extended, 0)
  51. Return _WinAPI_CreateWindowEx($iExStyle, $__DTPCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
  52. EndFunc ;==>_GUICtrlDTP_Create
  53. ; #FUNCTION# ====================================================================================================================
  54. ; Author ........: Gary Frost (gafrost)
  55. ; Modified.......:
  56. ; ===============================================================================================================================
  57. Func _GUICtrlDTP_Destroy(ByRef $hWnd)
  58. If Not _WinAPI_IsClassName($hWnd, $__DTPCONSTANT_ClassName) Then Return SetError(2, 2, False)
  59. Local $iDestroyed = 0
  60. If IsHWnd($hWnd) Then
  61. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  62. Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd)
  63. Local $hParent = _WinAPI_GetParent($hWnd)
  64. $iDestroyed = _WinAPI_DestroyWindow($hWnd)
  65. Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID)
  66. If Not $iRet Then
  67. ; can check for errors here if needed, for debug
  68. EndIf
  69. Else
  70. ; Not Allowed to Destroy Other Applications Control(s)
  71. Return SetError(1, 1, False)
  72. EndIf
  73. Else
  74. $iDestroyed = GUICtrlDelete($hWnd)
  75. EndIf
  76. If $iDestroyed Then $hWnd = 0
  77. Return $iDestroyed <> 0
  78. EndFunc ;==>_GUICtrlDTP_Destroy
  79. ; #FUNCTION# ====================================================================================================================
  80. ; Author ........: Paul Campbell (PaulIA)
  81. ; Modified.......:
  82. ; ===============================================================================================================================
  83. Func _GUICtrlDTP_GetMCColor($hWnd, $iIndex)
  84. Return _SendMessage($hWnd, $DTM_GETMCCOLOR, $iIndex)
  85. EndFunc ;==>_GUICtrlDTP_GetMCColor
  86. ; #FUNCTION# ====================================================================================================================
  87. ; Author ........: Paul Campbell (PaulIA)
  88. ; Modified.......:
  89. ; ===============================================================================================================================
  90. Func _GUICtrlDTP_GetMCFont($hWnd)
  91. Return Ptr(_SendMessage($hWnd, $DTM_GETMCFONT))
  92. EndFunc ;==>_GUICtrlDTP_GetMCFont
  93. ; #FUNCTION# ====================================================================================================================
  94. ; Author ........: Paul Campbell (PaulIA)
  95. ; Modified.......:
  96. ; ===============================================================================================================================
  97. Func _GUICtrlDTP_GetMonthCal($hWnd)
  98. Return HWnd(_SendMessage($hWnd, $DTM_GETMONTHCAL))
  99. EndFunc ;==>_GUICtrlDTP_GetMonthCal
  100. ; #FUNCTION# ====================================================================================================================
  101. ; Author ........: Paul Campbell (PaulIA)
  102. ; Modified.......:
  103. ; ===============================================================================================================================
  104. Func _GUICtrlDTP_GetRange($hWnd)
  105. Local $aRange[14]
  106. Local $tRange = _GUICtrlDTP_GetRangeEx($hWnd)
  107. $aRange[0] = DllStructGetData($tRange, "MinValid")
  108. $aRange[1] = DllStructGetData($tRange, "MinYear")
  109. $aRange[2] = DllStructGetData($tRange, "MinMonth")
  110. $aRange[3] = DllStructGetData($tRange, "MinDay")
  111. $aRange[4] = DllStructGetData($tRange, "MinHour")
  112. $aRange[5] = DllStructGetData($tRange, "MinMinute")
  113. $aRange[6] = DllStructGetData($tRange, "MinSecond")
  114. $aRange[7] = DllStructGetData($tRange, "MaxValid")
  115. $aRange[8] = DllStructGetData($tRange, "MaxYear")
  116. $aRange[9] = DllStructGetData($tRange, "MaxMonth")
  117. $aRange[10] = DllStructGetData($tRange, "MaxDay")
  118. $aRange[11] = DllStructGetData($tRange, "MaxHour")
  119. $aRange[12] = DllStructGetData($tRange, "MaxMinute")
  120. $aRange[13] = DllStructGetData($tRange, "MaxSecond")
  121. Return $aRange
  122. EndFunc ;==>_GUICtrlDTP_GetRange
  123. ; #FUNCTION# ====================================================================================================================
  124. ; Author ........: Paul Campbell (PaulIA)
  125. ; Modified.......:
  126. ; ===============================================================================================================================
  127. Func _GUICtrlDTP_GetRangeEx($hWnd)
  128. Local $tRange = DllStructCreate($tagDTPRANGE)
  129. Local $iRet
  130. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  131. $iRet = _SendMessage($hWnd, $DTM_GETRANGE, 0, $tRange, 0, "wparam", "struct*")
  132. Else
  133. Local $iRange = DllStructGetSize($tRange)
  134. Local $tMemMap
  135. Local $pMemory = _MemInit($hWnd, $iRange, $tMemMap)
  136. $iRet = _SendMessage($hWnd, $DTM_GETRANGE, 0, $pMemory, 0, "wparam", "ptr")
  137. _MemRead($tMemMap, $pMemory, $tRange, $iRange)
  138. _MemFree($tMemMap)
  139. EndIf
  140. DllStructSetData($tRange, "MinValid", BitAND($iRet, $GDTR_MIN) <> 0)
  141. DllStructSetData($tRange, "MaxValid", BitAND($iRet, $GDTR_MAX) <> 0)
  142. Return $tRange
  143. EndFunc ;==>_GUICtrlDTP_GetRangeEx
  144. ; #FUNCTION# ====================================================================================================================
  145. ; Author ........: Paul Campbell (PaulIA)
  146. ; Modified.......:
  147. ; ===============================================================================================================================
  148. Func _GUICtrlDTP_GetSystemTime($hWnd)
  149. Local $aDate[6]
  150. Local $tDate = _GUICtrlDTP_GetSystemTimeEx($hWnd)
  151. $aDate[0] = DllStructGetData($tDate, "Year")
  152. $aDate[1] = DllStructGetData($tDate, "Month")
  153. $aDate[2] = DllStructGetData($tDate, "Day")
  154. $aDate[3] = DllStructGetData($tDate, "Hour")
  155. $aDate[4] = DllStructGetData($tDate, "Minute")
  156. $aDate[5] = DllStructGetData($tDate, "Second")
  157. Return $aDate
  158. EndFunc ;==>_GUICtrlDTP_GetSystemTime
  159. ; #FUNCTION# ====================================================================================================================
  160. ; Author ........: Paul Campbell (PaulIA)
  161. ; Modified.......:
  162. ; ===============================================================================================================================
  163. Func _GUICtrlDTP_GetSystemTimeEx($hWnd)
  164. Local $tDate = DllStructCreate($tagSYSTEMTIME)
  165. Local $iRet
  166. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  167. $iRet = _SendMessage($hWnd, $DTM_GETSYSTEMTIME, 0, $tDate, 0, "wparam", "struct*")
  168. Else
  169. Local $iDate = DllStructGetSize($tDate)
  170. Local $tMemMap
  171. Local $pMemory = _MemInit($hWnd, $iDate, $tMemMap)
  172. $iRet = _SendMessage($hWnd, $DTM_GETSYSTEMTIME, 0, $pMemory, 0, "wparam", "ptr")
  173. _MemRead($tMemMap, $pMemory, $tDate, $iDate)
  174. _MemFree($tMemMap)
  175. EndIf
  176. Return SetError($iRet, $iRet, $tDate)
  177. EndFunc ;==>_GUICtrlDTP_GetSystemTimeEx
  178. ; #FUNCTION# ====================================================================================================================
  179. ; Author ........: Paul Campbell (PaulIA)
  180. ; Modified.......:
  181. ; ===============================================================================================================================
  182. Func _GUICtrlDTP_SetFormat($hWnd, $sFormat)
  183. Local $iRet
  184. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  185. $iRet = _SendMessage($hWnd, $DTM_SETFORMATW, 0, $sFormat, 0, "wparam", "wstr")
  186. Else
  187. Local $iMemory = 2 * (StringLen($sFormat) + 1)
  188. Local $tMemMap
  189. Local $pMemory = _MemInit($hWnd, $iMemory, $tMemMap)
  190. _MemWrite($tMemMap, $sFormat, $pMemory, $iMemory, "wstr")
  191. $iRet = _SendMessage($hWnd, $DTM_SETFORMATW, 0, $pMemory, 0, "wparam", "ptr")
  192. _MemFree($tMemMap)
  193. EndIf
  194. Return $iRet <> 0
  195. EndFunc ;==>_GUICtrlDTP_SetFormat
  196. ; #FUNCTION# ====================================================================================================================
  197. ; Author ........: Paul Campbell (PaulIA)
  198. ; Modified.......:
  199. ; ===============================================================================================================================
  200. Func _GUICtrlDTP_SetMCColor($hWnd, $iIndex, $iColor)
  201. Return _SendMessage($hWnd, $DTM_SETMCCOLOR, $iIndex, $iColor)
  202. EndFunc ;==>_GUICtrlDTP_SetMCColor
  203. ; #FUNCTION# ====================================================================================================================
  204. ; Author ........: Paul Campbell (PaulIA)
  205. ; Modified.......:
  206. ; ===============================================================================================================================
  207. Func _GUICtrlDTP_SetMCFont($hWnd, $hFont, $bRedraw = True)
  208. _SendMessage($hWnd, $DTM_SETMCFONT, $hFont, $bRedraw, 0, "handle")
  209. EndFunc ;==>_GUICtrlDTP_SetMCFont
  210. ; #FUNCTION# ====================================================================================================================
  211. ; Author ........: Paul Campbell (PaulIA)
  212. ; Modified.......:
  213. ; ===============================================================================================================================
  214. Func _GUICtrlDTP_SetRange($hWnd, ByRef $aRange)
  215. Local $tRange = DllStructCreate($tagDTPRANGE)
  216. DllStructSetData($tRange, "MinValid", $aRange[0])
  217. DllStructSetData($tRange, "MinYear", $aRange[1])
  218. DllStructSetData($tRange, "MinMonth", $aRange[2])
  219. DllStructSetData($tRange, "MinDay", $aRange[3])
  220. DllStructSetData($tRange, "MinHour", $aRange[4])
  221. DllStructSetData($tRange, "MinMinute", $aRange[5])
  222. DllStructSetData($tRange, "MinSecond", $aRange[6])
  223. DllStructSetData($tRange, "MaxValid", $aRange[7])
  224. DllStructSetData($tRange, "MaxYear", $aRange[8])
  225. DllStructSetData($tRange, "MaxMonth", $aRange[9])
  226. DllStructSetData($tRange, "MaxDay", $aRange[10])
  227. DllStructSetData($tRange, "MaxHour", $aRange[11])
  228. DllStructSetData($tRange, "MaxMinute", $aRange[12])
  229. DllStructSetData($tRange, "MaxSecond", $aRange[13])
  230. Return _GUICtrlDTP_SetRangeEx($hWnd, $tRange)
  231. EndFunc ;==>_GUICtrlDTP_SetRange
  232. ; #FUNCTION# ====================================================================================================================
  233. ; Author ........: Paul Campbell (PaulIA)
  234. ; Modified.......:
  235. ; ===============================================================================================================================
  236. Func _GUICtrlDTP_SetRangeEx($hWnd, ByRef $tRange)
  237. Local $iFlags = 0, $iRet
  238. If DllStructGetData($tRange, "MinValid") Then $iFlags = BitOR($iFlags, $GDTR_MIN)
  239. If DllStructGetData($tRange, "MaxValid") Then $iFlags = BitOR($iFlags, $GDTR_MAX)
  240. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  241. $iRet = _SendMessage($hWnd, $DTM_SETRANGE, $iFlags, $tRange, 0, "wparam", "struct*")
  242. Else
  243. Local $iRange = DllStructGetSize($tRange)
  244. Local $tMemMap
  245. Local $pMemory = _MemInit($hWnd, $iRange, $tMemMap)
  246. _MemWrite($tMemMap, $tRange)
  247. $iRet = _SendMessage($hWnd, $DTM_SETRANGE, $iFlags, $pMemory, 0, "wparam", "ptr")
  248. _MemFree($tMemMap)
  249. EndIf
  250. Return $iRet <> 0
  251. EndFunc ;==>_GUICtrlDTP_SetRangeEx
  252. ; #FUNCTION# ====================================================================================================================
  253. ; Author ........: Paul Campbell (PaulIA)
  254. ; Modified.......:
  255. ; ===============================================================================================================================
  256. Func _GUICtrlDTP_SetSystemTime($hWnd, ByRef $aDate)
  257. Local $tDate = DllStructCreate($tagSYSTEMTIME)
  258. DllStructSetData($tDate, "Year", $aDate[1])
  259. DllStructSetData($tDate, "Month", $aDate[2])
  260. DllStructSetData($tDate, "Day", $aDate[3])
  261. DllStructSetData($tDate, "Hour", $aDate[4])
  262. DllStructSetData($tDate, "Minute", $aDate[5])
  263. DllStructSetData($tDate, "Second", $aDate[6])
  264. Return _GUICtrlDTP_SetSystemTimeEx($hWnd, $tDate, $aDate[0])
  265. EndFunc ;==>_GUICtrlDTP_SetSystemTime
  266. ; #FUNCTION# ====================================================================================================================
  267. ; Author ........: Paul Campbell (PaulIA)
  268. ; Modified.......:
  269. ; ===============================================================================================================================
  270. Func _GUICtrlDTP_SetSystemTimeEx($hWnd, ByRef $tDate, $bFlag = False)
  271. Local $iFlag, $iRet
  272. If $bFlag Then
  273. $iFlag = $GDT_NONE
  274. Else
  275. $iFlag = $GDT_VALID
  276. EndIf
  277. If _WinAPI_InProcess($hWnd, $__g_hDTLastWnd) Then
  278. $iRet = _SendMessage($hWnd, $DTM_SETSYSTEMTIME, $iFlag, $tDate, 0, "wparam", "struct*")
  279. Else
  280. Local $iDate = DllStructGetSize($tDate)
  281. Local $tMemMap
  282. Local $pMemory = _MemInit($hWnd, $iDate, $tMemMap)
  283. _MemWrite($tMemMap, $tDate)
  284. $iRet = _SendMessage($hWnd, $DTM_SETSYSTEMTIME, $iFlag, $pMemory, 0, "wparam", "ptr")
  285. _MemFree($tMemMap)
  286. EndIf
  287. Return $iRet <> 0
  288. EndFunc ;==>_GUICtrlDTP_SetSystemTimeEx