[Widget]Zeit auf dem Desktop

    • Offizieller Beitrag

    Heyho,

    Hier ein kleines Widget, welches einfach die Zeit auf dem Desktop anzeigt (Inspiriert von Rainmeter). Dies sieht nicht nur ganz gut aus, sondern ist auch ungemein praktisch wenn man etwas weiter weg ist, oder mal auf dem zweiten Desktop die Zeit nachgucken will ;)
    Aber seht selbst:
    autoit.de/wcf/attachment/12289/

    Spoiler anzeigen
    [autoit]

    #include <Constants.au3>
    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    ;~ #NoTrayIcon
    Opt("GUIOnEventMode", 1)

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

    Dim $Title, $OldTitle
    Dim $song
    Dim $hwnd

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

    Global $h_Desktop_SysListView32
    _GetDesktopHandle()

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

    $hwnd = GUICreate("Zeit", 500,150, @DesktopWidth-500, @DesktopHeight-150-50, $WS_POPUP, $WS_EX_TOOLWINDOW)
    GUISetCursor(9)
    GUISetOnEvent(-3,"_exit")
    $context = GUICtrlCreateContextMenu()
    GUICtrlCreateMenuItem("Exit",$context)
    GUICtrlSetOnEvent(-1,"_exit")
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_Drag', $hwnd)
    DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hwnd, "hwnd", $h_Desktop_SysListView32)
    GUISetState(@SW_SHOWNOACTIVATE, $hwnd)
    GUISetBkColor(0xffffff)
    GUISetState()
    $sOldTime = ""
    While 1
    $sTime = @HOUR&":"&@MIN&":"&@SEC
    If $sOldTime <> $sTime Then
    $sOldTime = $sTime
    $rgn = CreateTextRgn($hwnd, $sTime, 150, "Century Gothic", 600)
    SetWindowRgn($hwnd, $rgn)
    EndIf
    Sleep(200)
    WEnd

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

    Func _exit()
    Exit
    EndFunc

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

    Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
    EndFunc ;==>SetWindowRgn

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

    ;Func CombineRgn(ByRef $rgn1, ByRef $rgn2)
    ; DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 2)
    ;EndFunc
    ;~ ControlCommand
    Func CreateTextRgn(ByRef $CTR_hwnd, $CTR_Text, $CTR_height, $CTR_font = "Microsoft Sans Serif", $CTR_weight = 800)
    Local Const $OUT_CHARACTER_PRECIS = 4
    Local Const $CLIP_DEFAULT_PRECIS = 4
    Local Const $PROOF_QUALITY = 4
    Local Const $FIXED_PITCH = 1
    Local Const $RGN_XOR = 3

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

    ;~ If $CTR_font = "" Then $CTR_font = "Microsoft Sans Serif"
    If $CTR_weight = -1 Then $CTR_weight = 1000
    Local $gdi_dll = DllOpen("gdi32.dll")
    Local $CTR_hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $CTR_hwnd)
    Local $CTR_hMyFont = DllCall($gdi_dll, "hwnd", "CreateFont", "int", $CTR_height, "int", 0, "int", 0, "int", 0, _
    "int", $CTR_weight, "int", 0, "int", 0, "int", 0, "int", $ANSI_CHARSET, "int", $OUT_CHARACTER_PRECIS, _
    "int", $CLIP_DEFAULT_PRECIS, "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $CTR_font)
    Local $CTR_hOldFont = DllCall($gdi_dll, "hwnd", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hMyFont[0])
    DllCall($gdi_dll, "int", "BeginPath", "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "TextOut", "int", $CTR_hDC[0], "int", 0, "int", 0, "str", $CTR_Text, "int", StringLen($CTR_Text))
    DllCall($gdi_dll, "int", "EndPath", "int", $CTR_hDC[0])
    Local $CTR_hRgn1 = DllCall($gdi_dll, "hwnd", "PathToRegion", "int", $CTR_hDC[0])
    Local $CTR_rc = DllStructCreate("int;int;int;int")
    DllCall($gdi_dll, "int", "GetRgnBox", "hwnd", $CTR_hRgn1[0], "ptr", DllStructGetPtr($CTR_rc))
    Local $CTR_hRgn2 = DllCall($gdi_dll, "hwnd", "CreateRectRgnIndirect", "ptr", DllStructGetPtr($CTR_rc))
    DllCall($gdi_dll, "int", "CombineRgn", "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn1[0], "int", $RGN_XOR)
    DllCall($gdi_dll, "int", "DeleteObject", "hwnd", $CTR_hRgn1[0])
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $CTR_hwnd, "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hOldFont[0])
    DllClose($gdi_dll)
    Return $CTR_hRgn2[0]
    EndFunc ;==>CreateTextRgn

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

    Func _Drag()
    DllCall("user32.dll", 'int', _
    'SendMessage', 'hWnd', @GUI_WinHandle, _
    'int', 0x00A1, 'int', 2, 'int', 0)
    EndFunc ;==>_ChangeCursorOnDrag

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

    Func _GetDesktopHandle()
    $h_Desktop_SysListView32 = 0

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

    Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
    Local $sChkAero = DllStructCreate("int;")
    DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
    Local $aero_on = DllStructGetData($sChkAero, 1)

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

    If Not $aero_on Then
    $h_Desktop_SysListView32 = WinGetHandle("Program Manager")
    Return 1
    Else
    Local $hCBReg = DllCallbackRegister("_GetDesktopHandle_EnumChildWinProc", "hwnd", "hwnd;lparam")
    If $hCBReg = 0 Then Return SetError(2)
    DllCall("user32.dll", "int", "EnumChildWindows", "hwnd", _WinAPI_GetDesktopWindow(), "ptr", DllCallbackGetPtr($hCBReg), "lparam", 101)
    Local $iErr = @error
    DllCallbackFree($hCBReg)
    If $iErr Then
    Return SetError(3, $iErr, "")
    EndIf
    Return 2
    EndIf
    EndFunc ;==>_GetDesktopHandle

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

    Func _GetDesktopHandle_EnumChildWinProc($hWnd, $lParam)
    If _WinAPI_GetClassName($hWnd) = "SysListView32" And _WinAPI_GetWindowLong($hWnd, $GWL_ID) = 1 Then
    $h_Desktop_SysListView32 = $hWnd
    Return False
    EndIf
    Return True
    EndFunc ;==>_GetDesktopHandle_EnumChildWinProc

    [/autoit]

    Das Script allgemein ist ein Mix aus allen möglichen Scripten, ich hab den überblick verloren, was nun wirklich von mir ist... Also: Credit goes to everyone ;)

    Gruß
    Spider