• Offizieller Beitrag

    Diese UDF erstellt ein Bild mit dem Datum (Wochentag, Tag. Monat, Jahr). Also quasi ein Kalenderblatt als Anzeige für das Datum.
    Da es sich um ein ganz normales Pic-Control (Größe: 72x72 Pixel) handelt, kann man es auch mit GUICtrlSetPos verschieben, mit GUICtrlSetState anzeigen/verstecken und mit GuiCtrlSetOnEvent (bzw. GuiGetMsg-Abfrage) mit einem KlickEvent belegen.
    Zum erstellen gibt es:

    [autoit]

    $ControlID = _DateImage_Create($iLeft, $iTop, $sDate, $iColor)

    [/autoit]

    Zum ändern des Datums/der Farbe:

    [autoit]

    _DateImage_SetData($ControlID, $sDate, $iColor)

    [/autoit]

    Screenshot:
    autoit.de/wcf/attachment/24661/

    UDF
    [autoit]


    #include-once
    #include <Date.au3>
    #include <DateTimeConstants.au3>
    #include <GDIPlus.au3>
    #include <MsgBoxConstants.au3>
    #include <WinAPI.au3>
    _GDIPlus_Startup()
    OnAutoItExitRegister('_DateImage_BitmapDispose')
    Global $__g_sDateImage_Version = '1.0.0.0'
    Global $__g_sDateImage_Date = '30.08.2014'
    Global $__g_hDateImage_Image = _GDIPlus_BitmapCreateFromMemory(_DateImage_Calendar())
    If @error Then Exit MsgBox($MB_ICONERROR, 'DateImage-UDF', 'Fehler! "date_big.ico" konnte nicht gelesen werden!')

    [/autoit] [autoit][/autoit] [autoit]

    Func _DateImage_BitmapDispose()
    _GDIPlus_BitmapDispose($__g_hDateImage_Image)
    _GDIPlus_Shutdown()
    EndFunc ;==>_DateImage_BitmapDispose

    [/autoit] [autoit][/autoit] [autoit]

    Func _DateImage_Create($iLeft = 0, $iTop = 0, $sDate = '', $iColor = '')
    Local $idPicControl = GUICtrlCreatePic('', $iLeft, $iTop, 72, 72)
    If $idPicControl = 0 Then Return SetError(1, 0, 0)
    If $sDate = '' Or $sDate = Default Then $sDate = StringFormat('%04i/%02i/%02i', @YEAR, @MON, @MDAY)
    If $iColor = '' Or $iColor = Default Then $iColor = 0xFF000088
    _DateImage_SetData($idPicControl, $sDate, $iColor)
    Return $idPicControl
    EndFunc ;==>_DateImage_Create

    [/autoit] [autoit][/autoit] [autoit]

    Func _DateImage_SetData($ControlID, $sDate = '', $iColor = '')
    Local $hWnd = GUICtrlGetHandle($ControlID)
    If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0)
    If $sDate = '' Or $sDate = Default Then $sDate = StringFormat('%04i/%02i/%02i', @YEAR, @MON, @MDAY)
    If $iColor = '' Or $iColor = Default Then $iColor = 0xFF000088
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iColor)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    Local $hFamily = _GDIPlus_FontFamilyCreate('Times New Roman')
    Local $hFont = _GDIPlus_FontCreate($hFamily, 12, 1)
    Local $tLayout = _GDIPlus_RectFCreate(2, 10, 68, 60)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(72, 72, $hGraphic)
    Local $hGfxCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $aDate, $aTime
    _DateTimeSplit($sDate, $aDate, $aTime)
    Local $iWeekday = _DateToDayOfWeek($aDate[1], $aDate[2], $aDate[3])
    Local $sMonth = _DateToMonth($aDate[2], $DMW_LOCALE_SHORTNAME)
    Local $sDay = StringFormat('%s.\n%2i. %s\n%04i', _DateDayOfWeek($iWeekday, $DMW_LOCALE_SHORTNAME), $aDate[3], $sMonth, $aDate[1])
    _GDIPlus_GraphicsDrawImageRect($hGfxCtx, $__g_hDateImage_Image, 0, 0, 72, 72)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sDay, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGfxCtx, $sDay, $hFont, $aInfo[0], $hFormat, $hBrush)
    Local $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($ControlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_GraphicsDispose($hGfxCtx)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    EndFunc ;==>_DateImage_SetData

    [/autoit] [autoit][/autoit] [autoit]

    Func _DateImage_Info()
    MsgBox($MB_ICONINFORMATION, 'DateImage-UDF', StringFormat('Autor:\tOscar (http://www.autoit.de)\nVersion:\t%s\nDatum:\t%s', $__g_sDateImage_Version, $__g_sDateImage_Date))
    EndFunc ;==>_DateImage_Info

    [/autoit] [autoit][/autoit] [autoit]

    ;Code below was generated by: 'File to Base64 String' Code Generator v1.18 Build 2014-08-02
    Func _DateImage_Calendar($bSaveBinary = False, $sSavePath = @ScriptDir)
    Local $Calendar
    $Calendar &= 'nrFIAAABABBISAFwIAAAiFQAABYAAMwAKAAYAJAAkAAYAVyHGAABXBoHqqej//8B//8BzQDJRz8APwA/AD8ABQD50kf+/v8A/wB/AH8AfwD7eQD0I/5gA38AfwB/AH8A338AfwB/AHMA9yP9fwB/AH9/AH8AfwB/AH8AdAD1I/38/f1/AH8AfwB/AH8AfwDPfwB0AP8R9BH8/D8APwD/PwA/AD8APwA/AD8APwA/AH8/AD8APwA/ADYA/xHzEfz/sAE/AD8APwA/AD8APwA/AP8/AD8APwA/AD8APwA/ADUA+/8R9RH7PwA/AD8APwA/AP8/AD8APwA/AD8APwA/AD8Ajz8ANgD/EfMR+/v6PwD/PwA/AD8APwA/AD8APwA/AP8/AD8APwA/AD8ANgD/EfQR/vrwAT8APwA/AD8APwA/AP8/AD8APwA/AD8APwA/AD8AxzQA/xHzEfr6+T8APwD/PwA/AD8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A/78BvwF/AbkBPwK/Az0APw55MA5I7TIQsRAxEfQRFQAXS/H/mrD4/wAQRfD/E0jy/wAMRfr/p5+L/wDAu7H/dGxZ/wAPSP3/FEnz//gVSfE/ADgAPwK/AT8A/78BvwF/AbkBPwK/Az0APw74/f8T8AIxELEQMRGxEQEwAA0XUPf/p70Q/P+lvDEA/f+fALn//5+Yif/QAMzH/21mWP+iwL3//6a9/jICPwD/NwA/Ar8BPwC/Ab8BfwG5AY8/Ar8DPQA/Dv//pfACHzEQ8QExEbERMAAEF1ck/f8xABVVMBRU/wD/CU///6CYiAD/5eHc/25mVwD/DVP//xRV///yAT8ANwA/Ar8BPwC/Ab8B/38BuQE/Ar8DPQA/DjcO9RAPsREwAA8AcBOgmov/gP789/9vaFp1FP8PAA8ADwAPAA8ADwAPAA8ADw8ADwAPAD4OQ7AA9/9vaFr/AAAMAA0AMCUABIN/ff7/BQwBHih2pQD/cX8APwD/PwA/AD8APwA/AD8APwAfACMfABIA+D//AQD8HwFsAQ=='
    $Calendar = _WinAPI_Base64Decode($Calendar)
    Local $tSource = DllStructCreate('byte[' & BinaryLen($Calendar) & ']')
    DllStructSetData($tSource, 1, $Calendar)
    Local $tDecompress
    _WinAPI_LZNTDecompress($tSource, $tDecompress, 21662)
    $tSource = 0
    Local $bString = Binary(DllStructGetData($tDecompress, 1))
    If $bSaveBinary Then
    Local $hFile = FileOpen($sSavePath & "\calendar.ico", 18)
    FileWrite($hFile, $bString)
    FileClose($hFile)
    EndIf
    Return $bString
    EndFunc ;==>_date_blank

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_Base64Decode($sB64String)
    Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
    Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
    $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($bBuffer, 1)
    EndFunc ;==>_WinAPI_Base64Decode

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iBufferSize)
    $tOutput = DllStructCreate("byte[" & $iBufferSize & "]")
    If @error Then Return SetError(1, 0, 0)
    Local $aRet = DllCall("ntdll.dll", "uint", "RtlDecompressBuffer", "ushort", 0x0002, "struct*", $tOutput, "ulong", $iBufferSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0)
    If @error Then Return SetError(2, 0, 0)
    If $aRet[0] Then Return SetError(3, $aRet[0], 0)
    Return $aRet[6]
    EndFunc ;==>_WinAPI_LZNTDecompress

    [/autoit]
    Beispiel
    [autoit]


    #include <GUIConstantsEx.au3>
    #include '_DateImage.au3'
    ;~ _DateImage_Info()
    Global $sDate = StringFormat('%04i/%02i/%02i', @YEAR, @MON, @MDAY)
    Global $iColor = 0xCC008800 ; <- Die Farbe für die Schrift im ARGB-Format

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui = GUICreate('Datumsanzeige', 400, 300)
    GUISetBkColor(0xA0A0C0)
    Global $idDateImage = _DateImage_Create(300, 20, $sDate, $iColor)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(1000)
    $sDate = StringFormat('%04i/%02i/%02i', 2014, 12, 31)
    _DateImage_SetData($idDateImage, $sDate, $iColor)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetPos($idDateImage, 170, 70)

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(500)
    GUICtrlSetState($idDateImage, $GUI_HIDE)
    Sleep(500)
    GUICtrlSetState($idDateImage, $GUI_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $idDateImage
    $sDate = _InputDateBox(0, '', '', $sDate)
    _DateImage_SetData($idDateImage, $sDate)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _InputDateBox([$iFormat][, $sTitle][, $sText][, $sDefaultDate][, $hParent])
    ; Description: Fragt den Benutzer nach Datum oder Datum und Uhrzeit und gibt dies als String zurück
    ; Parameter(s): $iFormat = 0 oder 1
    ; bei 0 wird nur nach dem Datum gefragt (Uhrzeit wird dann als "00:00:00" zurückgegeben)
    ; bei 1 wird nach Datum und Uhrzeit gefragt
    ; Requirement: -
    ; Return Value(s): bei Erfolg = String in Form von: "YYYY/MM/DD hh:mm:ss"
    ; bei Abbruch = Leerstring und @error = 1
    ; Author(s): Oscar (http://www.autoit.de)
    ;===============================================================================
    Func _InputDateBox($iFormat = 1, $sTitle = '', $sText = '', $sDefaultDate = '', $hParent = '')
    If $iFormat < 0 Or $iFormat > 1 Then $iFormat = 1
    If $sTitle = '' Or $sTitle = Default Then $sTitle = 'Datum-Box'
    If $sText = '' Or $sText = Default Then $sText = 'Bitte Datum auswählen!'
    If $iFormat Then $sText = 'Bitte Datum und Uhrzeit auswählen!'
    Local $iOnEventMode = Opt('GUIOnEventMode', 0), $sRetDate = '', $iError = 0
    Local $hGui = GUICreate($sTitle, 220 + $iFormat * 85, 130, Default, Default, Default, 8, $hParent)
    GUISetBkColor(0xCCCCCC, $hGui)
    GUISetIcon('shell32.dll', 24, $hGui)
    GUICtrlCreateGroup($sText, 10, 20, 200 + $iFormat * 85, 70)
    GUICtrlSetFont(-1, 10, 400, 0, 'Arial', 5)
    GUICtrlCreateIcon('shell32.dll', -21, 20, 48, 32, 32)
    Local $idDate = GUICtrlCreateDate($sDefaultDate, 65, 49, 135 + $iFormat * 85, 30)
    Local $hWnd = GUICtrlGetHandle($idDate)
    GUICtrlSetFont(-1, 14, 400, 0, 'Verdana', 5)
    If $iFormat Then
    Local $DTM_SETFORMAT_ = 0x1032
    Local $sFormat = 'dd.MM.yyyy HH:mm:ss'
    GUICtrlSendMsg($idDate, $DTM_SETFORMAT_, 0, $sFormat)
    Else
    GUICtrlSetStyle($idDate, 0)
    EndIf
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    Local $idOk = GUICtrlCreateButton('Ok', 60 + $iFormat * 85, 100, 60, 25, 1) ; <- Value 1 = $BS_DEFPUSHBUTTON
    Local $idCancel = GUICtrlCreateButton('Abbrechen', 130 + $iFormat * 85, 100, 80, 25)
    GUISetState(@SW_SHOW, $hGui)
    While True
    Switch GUIGetMsg()
    Case $idCancel, -3 ; <- Value -3 = $GUI_EVENT_CLOSE
    $iError = 1
    ExitLoop
    Case $idOk
    $sRetDate = StringRegExpReplace(GUICtrlRead($idDate), '(\d{2})\.(\d{2})\.(\d{4}).*', '$3/$2/$1')
    If $iFormat Then
    $sRetDate &= StringRegExpReplace(GUICtrlRead($idDate), '\d{2}\.\d{2}\.\d{4} (\d{2}):(\d{2}):(\d{2})', ' $1:$2:$3')
    Else
    $sRetDate &= ' 00:00:00'
    EndIf
    ExitLoop
    EndSwitch
    WEnd
    GUIDelete($hGui)
    Opt('GUIOnEventMode', $iOnEventMode)
    Return SetError($iError, 0, $sRetDate)
    EndFunc ;==>_InputDateBox

    [/autoit]
    • Offizieller Beitrag

    aber was ist wenn der User selber was per GDI+ zeichnet, dein Control killt und dann nicht mehr weiterzeichnen kann?


    Das kann nicht passieren, ist genau wie bei SQLite:
    Intern wird bei jedem Startup-Aufruf ein Zähler erhöht, bei Shutdown runtergezählt. Erst wenn der Zähler null erreicht, wird wirklich beendet (genau, wie auch nur ein einziges mal gestartet wird). ;)

  • Zitat

    Ab und an einen Blick in die UDF's werfen hilft ungemein

    Stimmt, dann fällt einem auch auf, dass Oscars schönes Script erst mit der (einer ? ) AutoIt-Version NACH 3.3.10.2 läuft, da

    [autoit]

    _DateToMonth

    [/autoit]

    geändert wurde...
    Beim klick auf die Funktion erkennt man, die deutsche Hilfe hängt immer weiter hinterher :D
    HIER ist die aktuelle Beschreibung

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (31. August 2014 um 08:46)

    • Offizieller Beitrag

    Das stimmt!
    Ich hätte das vielleicht noch erwähnen sollen. Das Script läuft erst ab v3.3.12.0 wegen _DateToMonth, aber auch wegen _DateDayOfWeek und $MB_ICONERROR, $MB_ICONINFORMATION bei der MsgBox.
    _DateDayOfWeek liefert aber mittlerweile auch die deutschen (bzw. lokalisierten) Wochentagsnamen.
    Für mich überwiegen die Vorteile der neuen Version, weswegen ich die Script-Breaking-Changes in Kauf nehme und ggf. meine Scripte anpasse.