Hallo @all
Da ich mich schun Ewigkeiten an GDIPlus versuchen wollte, hab ich hier mal eine kleine Analoguhr gemacht!
Ist es so gut genug oder gibt es bessere Wege zu zeichnen?
Funktionen:
- Wenn die Maus die GUI berührt, kann man mit den Arrowkeys(left/right) die Transparenz ändern
- Man kann die Gui per Grad/Drop bewegen
- Roter Zeiger: Stunden
- Blauer zeiger: Minuten
- ESC zum Beenden
Ich bitte um Kritik und Tipps
Bild/Script/Exe: autoit.de/wcf/attachment/8948/ (18:56)
Script!
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GdiPlus.au3>
#include <StaticConstants.au3>
#include <WinApi.au3>
#include <Array.au3>
#include <Misc.au3>
_GDIPlus_Startup()
; Allgemein ===========================================================
OnAutoItExitRegister("_EndGdi")
HotKeySet("{ESC}", "_Exit")
Opt("GUIOnEventMode", 1)
; Variablen =============================================================
Global $trans = 255
Global $Width = 150, $Height = 150
Global $GUI_X = @DesktopWidth/2-$Width, $GUI_Y = @DesktopHeight/2-$Height
Global $aMin[60] = ["75 5", "82 6", "88 6", "95 9", "102 11", "107 14", "114 17", "121 22", "125 27", "131, 32", "135 40", "137 46", "140 53", "142 60", "143 66", "143 75", "143 81", "142 88","141 96", "138 102", "135 109", "131 115", "127 121", "122 126", "116 131", "109 134", "103 139", "96 141", "89 143", "82 145", "75 145", "67 145", "60 144", "53 142", "46 139", "39 137", "33 131", "28 127", "23 121", "17 116", "14 110", "11 104", "7 96", "5 89", "4 82", "4 75", "5 67", "6 60", "7 53", "10 46", "14 40", "18 34", "22 28", "28 23", "34 18", "40 15", "46 12", "52 7", "59 5", "67 5"]
Global $aHour[12] = ["75 5", "107 14", "135 40", "143 75", "135 109", "109 134", "75 145", "39 137", "14 110", "4 75", "14 40", "40 15"]
; GUI ===============================================================
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("AnalogUhr", $Width, $Height, $GUI_X, $GUI_Y, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;GDI+ ===============================================================================
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(150, 150, $hGraphic)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$image = _GDIPlus_ImageLoadFromFile(@ScriptDir &"/Analoguhr.jpg")
$penMIN = _GDIPlus_PenCreate(0xFF0000CD)
$penHOUR = _GDIPlus_PenCreate(0xFFA52A2A)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
;While-Schleife =======================================================================
While 1
_Draw()
_GuiMove()
_TransMinus()
_TransPlus()
Sleep(100)
WEnd
; Funktionen ============================================================================
Func WM_PAINT()
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $Width, $Height)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINT
Func _GetHour()
Local $hour = @HOUR
if $hour <= 12 Then Return $hour
if $hour = 13 Then $hour = 1
if $hour = 14 Then $hour = 2
if $hour = 15 Then $hour = 3
if $hour = 16 Then $hour = 4
if $hour = 17 Then $hour = 5
if $hour = 18 Then $hour = 6
if $hour = 19 Then $hour = 7
if $hour = 20 Then $hour = 8
if $hour = 21 Then $hour = 9
if $hour = 22 Then $hour = 10
if $hour = 23 Then $hour = 11
if $hour = 24 Then $hour = 12
Return $hour
EndFunc
Func _EndGdi()
_GDIPlus_ImageDispose($image)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hBackBuffer)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_PenDispose($penHOUR)
_GDIPlus_PenDispose($penMIN)
_GDIPlus_Shutdown()
EndFunc
Func _Exit()
Exit
EndFunc
Func _GuiMove()
if MouseGetPos(0) >= $gui_X and <= MouseGetPos(0) $gui_X + $Width and MouseGetPos(1) >= $GUI_Y and MouseGetPos(1) <= $gui_Y + $Height Then
While _IsPressed(01)
WinMove("AnalogUhr", "", MouseGetPos(0)-$Width, MouseGetPos(1)-$Height)
$gui_X = MouseGetPos(0) - $Width
$GUI_Y = MouseGetPos(1) - $Height
Sleep(1)
WEnd
EndIf
EndFunc
Func _TransMinus()
if MouseGetPos(0) >= $gui_X and <= MouseGetPos(0) $gui_X + $Width and MouseGetPos(1) >= $GUI_Y and MouseGetPos(1) <= $gui_Y + $Height Then
if _IsPressed(25) Then
$trans -= 5
if $trans < 0 Then $trans = 0
WinSetTrans("AnalogUhr", "", $trans)
EndIf
EndIf
EndFunc
Func _TransPlus()
if MouseGetPos(0) >= $gui_X and <= MouseGetPos(0) $gui_X + $Width and MouseGetPos(1) >= $GUI_Y and MouseGetPos(1) <= $gui_Y + $Height Then
if _IsPressed(27) Then
$trans += 5
if $trans > 255 Then $trans = 255
WinSetTrans("AnalogUhr", "", $trans)
EndIf
EndIf
EndFunc
Func _Draw()
_GDIPlus_GraphicsClear($hBackBuffer)
$aCoordMin = StringSplit($aMin[@MIN], " ")
$aCoordHour = StringSplit($aHour[_GetHour()], " ")
_GDIPlus_GraphicsDrawImageRect($hBackBuffer, $image, 0, 0, 150, 150)
_GDIPlus_GraphicsDrawLine($hBackBuffer, 75, 75, $aCoordMin[1], $aCoordMin[2], $penMIN)
_GDIPlus_GraphicsDrawLine($hBackBuffer, 75, 75, $aCoordHour[1], $aCoordHour[2], $penHOUR)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INTERNALPAINT)
EndFunc