Hey,
Hatte ein wenig langeweile und wollt mal versuchen auf einem transparenten Fenster mit GDI+ zu arbeiten.
Aufgebaut ist es in 3 Spalten (Stunden, Minuten, Sekunden) wobei die Lowbits unten sind.
Schauts euch einfach an, vllt gefällts euch ja
Code
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WinApi.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]Global Const $SC_DRAGMOVE = 0xF012
[/autoit] [autoit][/autoit] [autoit]Global $nWidth = 100, $nHeight = 130, $nWnd_X = 1066, $nWnd_Y = 46
[/autoit] [autoit][/autoit] [autoit]Global $Kreis_size = 15
[/autoit] [autoit][/autoit] [autoit]Global $Sec, $Type = 1
[/autoit] [autoit][/autoit] [autoit]$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", 500)
DllStructSetData($tSize, "Y", 500)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 255)
DllStructSetData($tBlend, "Format", 1)
Dim $aHour[5]
_FillArrayWithBinary($aHour, @HOUR)
Dim $aMin[6]
_FillArrayWithBinary($aMin, @MIN)
Dim $aSec[6]
_FillArrayWithBinary($aSec, @SEC)
Dim $aAll[17]
[/autoit] [autoit][/autoit] [autoit]$hWnd = GUICreate("Binary-Clock", 500, 500, $nWnd_X, $nWnd_Y, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_FollowMouse")
$nMenu = GUICtrlCreateContextMenu(-1)
GUICtrlSetOnEvent(GUICtrlCreateMenuItem("Exit", $nMenu), "_Exit")
GUISetState()
GUIRegisterMsg($WM_LBUTTONDBLCLK, "_ChangeType")
[/autoit] [autoit][/autoit] [autoit]$hDC_Window = _WinAPI_GetDC($hWnd)
$hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC_Window)
$hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Window, 500, 500)
_WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]$hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphics, "int", 4);; Macht durchsichtig ?!
$hPen_Hour = _GDIPlus_PenCreate(0xFF000000)
$hBrush_Hour = _GDIPlus_BrushCreateSolid(0xAAFF0000)
$hPen_Min = _GDIPlus_PenCreate(0xFF000000)
$hBrush_Min = _GDIPlus_BrushCreateSolid(0xAA00FF00)
$hPen_Sec = _GDIPlus_PenCreate(0xFF000000)
$hBrush_Sec = _GDIPlus_BrushCreateSolid(0xAA0000FF)
$hBrush_BG = _GDIPlus_BrushCreateSolid(0x30000000)
[/autoit] [autoit][/autoit] [autoit]While Sleep(100)
If $Sec <> @SEC Then
$Sec = @SEC
_DRAW()
EndIf
WEnd
Func _DRAW()
_GDIPlus_GraphicsClear($hGraphics, 0x0)
_GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $nWidth, $nHeight, $hBrush_BG)
_FillArrayWithBinary($aHour, @HOUR)
_FillArrayWithBinary($aMin, @MIN)
_FillArrayWithBinary($aSec, @SEC)
Switch $Type
Case 1
_DrawDisplay1()
Case 2
_DrawDisplay2()
Case 3
_DrawDisplay3()
EndSwitch
_WinAPI_UpdateLayeredWindow($hWnd, $hDC_Window, 0, $pSize, $hDC_Buffer, $pSource, 0, $pBlend, 2)
EndFunc ;==>_DRAW
Func _DrawDisplay3()
_GDIPlus_GraphicsDrawString($hGraphics, "EMPTY", 0, 0)
EndFunc ;==>_DrawDisplay3
Func _DrawDisplay2()
For $i = 0 To 4
$aAll[$i] = $aHour[$i]
Next
For $i = 5 To 10
$aAll[$i] = $aMin[$i - 5]
Next
For $i = 11 To 16
$aAll[$i] = $aSec[$i - 11]
Next
For $i = 1 To 17
If $aAll[$i - 1] = 1 Then
If $i >= 1 And $i <= 5 Then ;; Hour
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($Kreis_size * $i), $nHeight / 2, $Kreis_size, $hBrush_Hour)
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i), $nHeight / 2, $Kreis_size, $hPen_Hour)
ElseIf $i >= 6 And $i <= 11 Then ;; Min
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size, $nHeight / 2, $Kreis_size, $hBrush_Min)
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size, $nHeight / 2, $Kreis_size, $hPen_Min)
ElseIf $i >= 12 And $i <= 17 Then;; Sec
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size * 2, $nHeight / 2, $Kreis_size, $hBrush_Sec)
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size * 2, $nHeight / 2, $Kreis_size, $hPen_Sec)
EndIf
EndIf
If $aAll[$i - 1] = 0 Then
If $i >= 1 And $i <= 5 Then ;; Hour
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i), $nHeight / 2, $Kreis_size, $hPen_Hour)
ElseIf $i >= 6 And $i <= 11 Then ;; Min
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size, $nHeight / 2, $Kreis_size, $hPen_Min)
ElseIf $i >= 12 And $i <= 17 Then;; Sec
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($Kreis_size * $i) + $Kreis_size * 2, $nHeight / 2, $Kreis_size, $hPen_Sec)
EndIf
EndIf
Next
EndFunc ;==>_DrawDisplay2
Func _DrawDisplay1()
[/autoit] [autoit][/autoit] [autoit];; Stunden
For $i = 0 To UBound($aHour) - 1
If $aHour[$i] = 1 Then
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($nWidth / 4) * 1, ($i + 2) * $Kreis_size, $Kreis_size, $hBrush_Hour)
EndIf
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($nWidth / 4) * 1, ($i + 2) * $Kreis_size, $Kreis_size, $hPen_Hour)
Next
;; Minuten
For $i = 0 To UBound($aMin) - 1
If $aMin[$i] = 1 Then
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($nWidth / 4) * 2, ($i + 1) * $Kreis_size, $Kreis_size, $hBrush_Min)
EndIf
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($nWidth / 4) * 2, ($i + 1) * $Kreis_size, $Kreis_size, $hPen_Min)
Next
;; Sekunden
For $i = 0 To UBound($aSec) - 1
If $aSec[$i] = 1 Then
_GDIPlus_GraphicsFillEllipseMid($hGraphics, ($nWidth / 4) * 3, ($i + 1) * $Kreis_size, $Kreis_size, $hBrush_Sec)
EndIf
_GDIPlus_GraphicsDrawEllipseMid($hGraphics, ($nWidth / 4) * 3, ($i + 1) * $Kreis_size, $Kreis_size, $hPen_Sec)
Next
;; Digitale Uhrzeit
;; Kasten
$Time = @HOUR & ":" & @MIN & ":" & @SEC
_GDIPlus_GraphicsDrawString($hGraphics, $Time, $nWidth / 2 - 25, $nHeight - 20, "Arial", 10)
EndFunc ;==>_DrawDisplay1
Func _ChangeType()
$Pos = WinGetPos("Binary-Clock")
$Type += 1
If $Type >= 4 Then $Type = 1
Switch $Type
Case 1
$nWidth = 100
$nHeight = 130
Case 2
$nWidth = $Kreis_size * 20
$nHeight = $Kreis_size * 2
Case 3
$nWidth = 130
$nHeight = 130
EndSwitch
_GDIPlus_GraphicsClear($hGraphics, 0xABCDEF)
_Draw()
EndFunc ;==>_ChangeType
Func _GDIPlus_GraphicsDrawEllipseMid($hGraphic, $x, $y, $Durchmesser, $hPen = 0)
_GDIPlus_GraphicsDrawEllipse($hGraphic, $x - $Durchmesser / 2, $y - $Durchmesser / 2, $Durchmesser, $Durchmesser, $hPen)
EndFunc ;==>_GDIPlus_GraphicsDrawEllipseMid
Func _GDIPlus_GraphicsFillEllipseMid($hGraphic, $x, $y, $Durchmesser, $hBrush = 0)
_GDIPlus_GraphicsFillEllipse($hGraphic, $x - $Durchmesser / 2, $y - $Durchmesser / 2, $Durchmesser, $Durchmesser, $hBrush)
EndFunc ;==>_GDIPlus_GraphicsFillEllipseMid
Func _FillArrayWithBinary(ByRef $aArray, $nDec)
$aBits = StringSplit(_TranslateBase($nDec), "", 2)
For $i = 0 To UBound($aArray) - 1 - UBound($aBits)
$aArray[$i] = 0
Next
For $i = UBound($aArray) - UBound($aBits) To UBound($aArray) - 1
$aArray[$i] = $aBits[$i - (UBound($aArray) - UBound($aBits))]
Next
EndFunc ;==>_FillArrayWithBinary
Func _FollowMouse()
_SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc ;==>_FollowMouse
Func _Exit()
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_PenDispose($hPen_Hour)
_GDIPlus_PenDispose($hPen_Min)
_GDIPlus_PenDispose($hPen_Sec)
_WinAPI_ReleaseDC($hWnd, $hDC_Window)
_WinAPI_DeleteDC($hDC_Buffer)
_WinAPI_DeleteObject($hBitmap_Buffer)
_GDIPlus_BrushDispose($hBrush_Hour)
_GDIPlus_BrushDispose($hBrush_Min)
_GDIPlus_BrushDispose($hBrush_Sec)
_GDIPlus_BrushDispose($hBrush_BG)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit
Func _TranslateBase($sNumber, $iOldBase = 10, $iNewBase = 2)
;!!by eukalyptus!!
If $iOldBase < 2 Or $iOldBase > 36 Or $iNewBase < 2 Or $iNewBase > 36 Then Return SetError(1, 1, False)
Local $iNum, $aRes, $tChr = DllStructCreate("char[64];")
If $iOldBase <> 10 Then
$aRes = DllCall("msvcrt.dll", "uint64:cdecl", "_strtoui64", "str", $sNumber, "ptr", 0, "int", $iOldBase)
If @error Then Return SetError(1, 2, False)
$iNum = $aRes[0]
Else
$iNum = Int($sNumber)
EndIf
$aRes = DllCall("msvcrt.dll", "ptr:cdecl", "_i64toa", "int64", $iNum, "ptr", DllStructGetPtr($tChr), "int", $iNewBase)
If @error Then Return SetError(1, 3, False)
Return DllStructGetData($tChr, 1)
EndFunc ;==>_TranslateBase
Changelog:
* 2. Binäransicht verschönert (Platz zwischen den Bit-Blöcken gelassen)
_____________________________________________________________________________________
+ Binäransicht wechselbar mit Doppelklick
+ Neue Binäransicht
* Schrift verschönert (Danke an name22 (Kann mir jmd sagen warum RenderingHint auf 3 die Bitmap in dem Fall durchsichtig macht?!)
* Draw-Funktion ruckelt nichtmehr (Danke Marsi ;))
* Vollständige Resourcen Freigabe
PS: Beenden kann man es mit Rechter Maustaste->Exit
Ich bau vllt noch ein, das die Position gespeichert wird in der das Fenster geschlossen wird, damit es immer richtig öffnet.