#include #include #include #include #include #include #include #include #include Global Const $DATERANGE_MONTHS = __DateRange_FormatMonths() Global Const $DATERANGE_DAYS = __DateRange_FormatDays() Global Const $SC_DRAGMOVE = 0xF012 _Example() Func _Example() Local $aReturn = _DateRange_Picker() If IsArray($aReturn) Then _ArrayDisplay($aReturn) EndFunc ;==>_Example Func _DateRange_Picker($sTitle = '') Local $iMonth1 = Number(@MON) Local $iYear1 = Number(@YEAR) Local $iMonth2 = Mod($iMonth1, 12) + 1 Local $iYear2 = $iYear1 + Floor($iMonth1 / 12) Local $hGUI = GUICreate($sTitle, 660, 310, -1, -1, $WS_POPUP + $WS_BORDER) GUISetBkColor(0xC0C0C0) Local $aDay1[42], $aDay2[42], $idMonth1, $idMonth2 __DateRange_CreateMonth(35, 20, $aDay1, $iMonth1, $iYear1, $idMonth1) __DateRange_CreateMonth(375, 20, $aDay2, $iMonth2, $iYear2, $idMonth2) Local $idLeft1 = GUICtrlCreateLabel(ChrW(0x276C), 5, 115, 20, 50, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 40, $FW_NORMAL, $GUI_FONTNORMAL, "Segoe UI Symbol") Local $idRight1 = GUICtrlCreateLabel(ChrW(0x276D), 295, 115, 20, 50, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 40, $FW_NORMAL, $GUI_FONTNORMAL, "Segoe UI Symbol") Local $idLeft2 = GUICtrlCreateLabel(ChrW(0x276C), 345, 115, 20, 50, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 40, $FW_NORMAL, $GUI_FONTNORMAL, "Segoe UI Symbol") Local $idRight2 = GUICtrlCreateLabel(ChrW(0x276D), 630, 115, 20, 50, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 40, $FW_NORMAL, $GUI_FONTNORMAL, "Segoe UI Symbol") Local $idSelect = GUICtrlCreateButton(" " & __DateRange_GetString(800), 240, 270, 80, 35) GUICtrlSetImage(-1, "shell32.dll", 253, 0) Local $idCancel = GUICtrlCreateButton(" " & __DateRange_GetString(801), 340, 270, 80, 35) GUICtrlSetImage(-1, "shell32.dll", 240, 0) GUISetState() Local $nMsg, $iStart, $iEnd, $aReturn[2], $aPos While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $idCancel $aReturn = 0 ExitLoop Case $GUI_EVENT_PRIMARYDOWN GUISetCursor($MCID_SIZEALL, $GUI_CURSOR_OVERRIDE) _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) Case $GUI_EVENT_PRIMARYUP GUISetCursor() Case $idLeft1 To $idRight2 If $iStart Then __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, False) $iStart = 0 EndIf __DateRange_AdjustDate($nMsg - $idLeft1 + 1, $iMonth1, $iYear1, $iMonth2, $iYear2) __DateRange_ShowMonth($aDay1, $iMonth1, $iYear1, $idMonth1) __DateRange_ShowMonth($aDay2, $iMonth2, $iYear2, $idMonth2) Case $aDay1[0] To $aDay1[UBound($aDay1) - 1], $aDay2[0] To $aDay2[UBound($aDay2) - 1] If _IsPressed("10") Then If $iStart And $nMsg > $iStart Then __DateRange_SelectDate($aDay1, $aDay2, $nMsg, $iEnd, False) $iEnd = $nMsg __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, True) ContinueLoop EndIf EndIf If $iStart Then __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, False) $iStart = $nMsg $iEnd = 0 __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, True) Case $idSelect If Not $iStart Then $aReturn = 0 ExitLoop EndIf $aReturn[0] = String($iStart < $aDay2[0] ? $iYear1 : $iYear2) & "/" & _ StringFormat("%02i", $iStart < $aDay2[0] ? $iMonth1 : $iMonth2) & "/" & _ StringFormat("%02i", GUICtrlRead($iStart)) If Not $iEnd Then $iEnd = $iStart $aReturn[1] = String($iEnd < $aDay2[0] ? $iYear1 : $iYear2) & "/" & _ StringFormat("%02i", $iEnd < $aDay2[0] ? $iMonth1 : $iMonth2) & "/" & _ StringFormat("%02i", GUICtrlRead($iEnd)) ExitLoop Case $idMonth1 If $iStart Then __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, False) __DateRange_SelectMonth($iMonth1, $iYear1, $aDay1[0], $iStart, $iEnd) __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, True) Case $idMonth2 If $iStart Then __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, False) __DateRange_SelectMonth($iMonth2, $iYear2, $aDay2[0], $iStart, $iEnd) __DateRange_SelectDate($aDay1, $aDay2, $iStart, $iEnd, True) EndSwitch WEnd GUIDelete() Return $aReturn EndFunc ;==>_DateRange_Picker Func __DateRange_CreateMonth($iPosX, $iPosY, ByRef $aDays, $iMonth, $iYear, ByRef $idMonth) Local $iFirst = _DateToDayOfWeek(String($iYear), StringFormat("%02i", $iMonth), "01") Local $iNumDays = _DateDaysInMonth($iYear, $iMonth) $idMonth = GUICtrlCreateLabel($DATERANGE_MONTHS[$iMonth - 1] & " " & $iYear, $iPosX, $iPosY, 250, 30, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 18, $FW_BOLD, $GUI_FONTNORMAL, "Comic Sans MS") GUICtrlSetBkColor(-1, 0xCE04BA) For $i = 0 To UBound($DATERANGE_DAYS) - 1 GUICtrlCreateLabel($DATERANGE_DAYS[$i], $iPosX + 5 + 35 * $i, $iPosY + 35, 30, 25, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTNORMAL, "Comic Sans MS") GUICtrlSetBkColor(-1, 0x808080) Next For $i = 0 To UBound($aDays) - 1 $aDays[$i] = GUICtrlCreateLabel("", $iPosX + 5 + Mod($i, 7) * 35, $iPosY + 65 + Floor($i / 7) * 30, 30, 25, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetFont(-1, 10, $FW_NORMAL, $GUI_FONTNORMAL, "Comic Sans MS") If Mod($i, 7) >= 1 And Mod($i, 7) <= 5 Then GUICtrlSetBkColor(-1, 0xFFFFFF) Else GUICtrlSetBkColor(-1, 0xA0A0A0) EndIf Next For $i = 0 To $iFirst - 2 GUICtrlSetState($aDays[$i], $GUI_HIDE) Next For $i = 0 To $iNumDays - 1 GUICtrlSetData($aDays[$i + $iFirst - 1], $i + 1) Next For $i = $iFirst + $iNumDays - 1 To UBound($aDays) - 1 GUICtrlSetState($aDays[$i], $GUI_HIDE) Next EndFunc ;==>__DateRange_CreateMonth Func __DateRange_ShowMonth(ByRef $aDays, $iMonth, $iYear, $idMonth) Local $iFirst = _DateToDayOfWeek(String($iYear), StringFormat("%02i", $iMonth), "01") Local $iNumDays = _DateDaysInMonth($iYear, $iMonth) GUICtrlSetData($idMonth, $DATERANGE_MONTHS[$iMonth - 1] & " " & $iYear) For $i = 0 To $iFirst - 2 GUICtrlSetState($aDays[$i], $GUI_HIDE) Next For $i = 0 To $iNumDays - 1 GUICtrlSetData($aDays[$i + $iFirst - 1], $i + 1) GUICtrlSetState($aDays[$i + $iFirst - 1], $GUI_SHOW) Next For $i = $iFirst + $iNumDays - 1 To UBound($aDays) - 1 GUICtrlSetState($aDays[$i], $GUI_HIDE) Next EndFunc ;==>__DateRange_ShowMonth Func __DateRange_SelectMonth($iMonth, $iYear, $iBegin, ByRef $iStart, ByRef $iEnd) Local $iFirst = _DateToDayOfWeek(String($iYear), StringFormat("%02i", $iMonth), "01") Local $iNumDays = _DateDaysInMonth($iYear, $iMonth) $iStart = $iBegin + $iFirst - 1 $iEnd = $iStart + $iNumDays - 1 EndFunc ;==>__DateRange_SelectMonth Func __DateRange_SelectDate(ByRef $aDay1, ByRef $aDay2, $iStart, $iEnd, $bSelect) Local $iDay If Not $iEnd Then $iEnd = $iStart For $i = $iStart To $iEnd If ($i >= $aDay1[0] And $i <= $aDay1[UBound($aDay1) - 1]) Or ($i >= $aDay2[0] And $i <= $aDay2[UBound($aDay2) - 1]) Then If $bSelect Then GUICtrlSetBkColor($i, 0xFF0000) Else $iDay = $i < $aDay2[0] ? Mod($i - $aDay1[0], 7) : Mod($i - $aDay2[0], 7) If $iDay >= 1 And $iDay <= 5 Then GUICtrlSetBkColor($i, 0xFFFFFF) Else GUICtrlSetBkColor($i, 0xA0A0A0) EndIf EndIf EndIf Next EndFunc ;==>__DateRange_SelectDate Func __DateRange_FormatMonths() Local $aMonth[12] For $i = 1 To 12 $aMonth[$i - 1] = _StringTitleCase(_DateToMonth($i, $DMW_LOCALE_LONGNAME)) Next Return $aMonth EndFunc ;==>__DateRange_FormatMonths Func __DateRange_FormatDays() Local $aDay[7] For $i = 1 To 7 $aDay[$i - 1] = _StringTitleCase(StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_SHORTNAME), 2)) Next Return $aDay EndFunc ;==>__DateRange_FormatDays Func __DateRange_AdjustDate($iAdjust, ByRef $iMonth1, ByRef $iYear1, ByRef $iMonth2, ByRef $iYear2) Local $sDate1 = $iYear1 & "/" & StringFormat("%02i", $iMonth1) & "/01" Local $sDate2 = $iYear2 & "/" & StringFormat("%02i", $iMonth2) & "/01" Switch $iAdjust Case 1 $sDate1 = _DateAdd('M', -1, $sDate1) Case 2 $sDate1 = _DateAdd('M', +1, $sDate1) If $sDate1 >= $sDate2 Then $sDate2 = _DateAdd('M', +1, $sDate2) Case 3 $sDate2 = _DateAdd('M', -1, $sDate2) If $sDate1 >= $sDate2 Then $sDate1 = _DateAdd('M', -1, $sDate1) Case 4 $sDate2 = _DateAdd('M', +1, $sDate2) EndSwitch $iMonth1 = Number(StringMid($sDate1, 6, 2)) $iYear1 = Number(StringMid($sDate1, 1, 4)) $iMonth2 = Number(StringMid($sDate2, 6, 2)) $iYear2 = Number(StringMid($sDate2, 1, 4)) EndFunc ;==>__DateRange_AdjustDate Func __DateRange_GetString($iNum) Local $hInstance = _WinAPI_LoadLibraryEx("user32.dll", $LOAD_LIBRARY_AS_DATAFILE) If Not $hInstance Then Return SetError(1, 0, "") Local $sText = _WinAPI_LoadString($hInstance, $iNum) Local $iErr = @error $iNum = @extended _WinAPI_FreeLibrary($hInstance) If $iErr Then Return SetError(2, 0, "") Return SetError(0, $iNum, $sText) EndFunc ;==>__DateRange_GetString