Hallo Alle,
ich habe mir eine Uhr mit GDI+ gebastelt. (Analog + Digital). Nur wird die Anzeige für die digitale Anzeige immer fetter und unlesericher. Woran liegt das? Ich bitte um Hilfe.
Spoiler anzeigen
; all credits to WideBoyDixon, i just reordered his code.
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)
$width = 240
$height = 240
$hWnd = GUICreate("Clock", $width, $height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromFile (@MyDocumentsDir & "\GDIPlus_Image.bmp")
;- $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)
$inc = 0
AdlibRegister("_DrawClock",200)
$lgBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0xFF7878FF, 0x00000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0x00000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)
$hourBrush = _GDIPlus_BrushCreateSolid(0xFF7878FF)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFF7878FF)
$secondPen = _GDIPlus_PenCreate(0xCC330000, 1)
;- $bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$bitmap2 = _GDIPlus_BitmapCreateFromFile (@MyDocumentsDir & "\GDIPlus_Image.bmp")
$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)
;- _GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)
;- _GDIPlus_GraphicsFillEllipse($backbuffer2, 20, 20, 200, 200, $lgBrush)
;- _GDIPlus_GraphicsFillEllipse($backbuffer2, 30, 30, 180, 180, $irBrush)
;- _GDIPlus_GraphicsFillEllipse($backbuffer2, 33, 33, 174, 174, $lgBrush)
_DrawMyText("12", 109, 40)
_DrawMyText("11", 75, 50)
_DrawMyText("10", 47, 75)
_DrawMyText("9", 43, 110)
_DrawMyText("8", 52, 145)
_DrawMyText("7", 75, 170)
_DrawMyText("6", 113, 180)
_DrawMyText("5", 150, 170)
_DrawMyText("4", 173, 145)
_DrawMyText("3", 182, 110)
_DrawMyText("2", 173, 75)
_DrawMyText("1", 150, 50)
_DrawMyText("PM", 105, 155)
GUIRegisterMsg($WM_PAINT,"MY_PAINT")
GUISetState()
Do
Until Not Sleep(100)
Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)
_DrawClock()
Return $GUI_RUNDEFMSG
EndFunc
Func _DrawClock()
_GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)
_DrawMyTime()
;Create angles
$secondAngle = 8.0 * ATan(1) * @SEC / 60.0
$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0
;Draw Hour Hand
Local $HourArrow[5][2] = [[4, 0], _
[Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120], _
[Int(-5 * Cos($hourAngle)) + 120, Int(-5 * Sin($hourAngle)) + 120], _
[Int(5 * Cos($hourAngle)) + 120, Int(5 * Sin($hourAngle)) + 120], _
[Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120]]
_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
;~ _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)
Local $MinuteArrow[5][2] = [[4, 0], _
[Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120], _
[Int(-5 * Cos($minuteAngle)) + 120, Int(-5 * Sin($minuteAngle)) + 120], _
[Int(5 * Cos($minuteAngle)) + 120, Int(5 * Sin($minuteAngle)) + 120], _
[Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120]]
_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)
_GDIPlus_GraphicsDrawLine($backbuffer, 120, 120, Int(70 * Sin($secondAngle)) + 120, _
Int(-70 * Cos($secondAngle)) + 120, $secondPen)
_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
EndFunc
Func _DrawMyText($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc ;==>_DrawMyText
Func _DrawMyTime()
$tLayout = _GDIPlus_RectFCreate(20, 20,0,0)
$text = @HOUR & ":" & @MIN & ":" & @SEC
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawString($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc ;==>_DrawMyText
Func close()
_GDIPlus_GraphicsDispose($backbuffer2)
_GDIPlus_BitmapDispose($bitmap2)
_GDIPlus_PenDispose($secondPen)
_GDIPlus_BrushDispose($minuteBrush)
_GDIPlus_BrushDispose($hourBrush)
_GDIPlus_FontDispose($nuFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($nuBrush)
_GDIPlus_BrushDispose($irBrush)
_GDIPlus_BrushDispose($lgBrush)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>close
;==== GDIPlus_CreateLineBrushFromRect ===
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors. Each number in the array
; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
; indicates a percentage of the distance between the starting boundary and the ending boundary
; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
; gradient and 1.0 indicates the ending boundary. There must be at least two positions
; specified: the first position, which is always 0.0, and the last position, which is always
; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
; line, parallel to the boundary lines, that is a certain fraction of the distance from the
; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
; the line that is 70 percent of the distance from the starting boundary to the ending boundary.
; The color is constant on lines that are parallel to the boundary lines.
; $iArgb1 - First Top color in 0xAARRGGBB format
; $iArgb2 - Second color in 0xAARRGGBB format
; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000,
; LinearGradientModeVertical = 0x00000001,
; LinearGradientModeForwardDiagonal = 0x00000002,
; LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode - WrapModeTile = 0,
; WrapModeTileFlipX = 1,
; WrapModeTileFlipY = 2,
; WrapModeTileFlipXY = 3,
; WrapModeClamp = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference: http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx
;
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
$iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)
Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount
If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
If $WrapMode = -1 Then $WrapMode = 1
$tRect = DllStructCreate("float X;float Y;float Width;float Height")
$pRect = DllStructGetPtr($tRect)
DllStructSetData($tRect, "X", $iX)
DllStructSetData($tRect, "Y", $iY)
DllStructSetData($tRect, "Width", $iWidth)
DllStructSetData($tRect, "Height", $iHeight)
;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
$aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
"int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)
If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]
$iCount = UBound($aPositions)
$tFactors = DllStructCreate("float[" & $iCount & "]")
$pFactors = DllStructGetPtr($tFactors)
For $iI = 0 To $iCount - 1
DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
Next
$tPositions = DllStructCreate("float[" & $iCount & "]")
$pPositions = DllStructGetPtr($tPositions)
For $iI = 0 To $iCount - 1
DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
Next
$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6]; Handle of Line Brush
EndFunc ;==>_GDIPlus_CreateLineBrushFromRect
; #CURRENT# =====================================================================================================================
; _GUICreate_Transparent
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICreate_Transparent
; Description ...: Transparente Popup-GUIs aus Bildern (z.B. PNG) erstellen
; Syntax.........: _GUICreate_Transparent($sImage, $iLeft = -1, $iTop = -1, $iOpacity = 255)
; Parameters ....: $sImage - Pfad zur Bilddatei
; $iLeft - Bidschirmposition der linken Seite des GUI in Pixeln
; |Default - -1 (zentriert)
; $iTop - Bidschirmposition der oberen Seite des GUI in Pixeln
; |Default - -1 (zentriert)
; $iOpacity - Transparenz für das gesamte GUI (siehe WinSetTrans())
; |Default - 255 (nicht transparent)
; Return values .: Im Erfolgsfall: HWND des GUI aus GUICreate()
; Im Fehlerfall: False, @error wird gesetzt:
; |1 = GDIPlus konnte nicht gestartet werden
; |2 = Die Bilddatei konnte nicht geladen werden
; Author ........: UEZ (http://www.autoit.de/index.php?page…9839#post199839)
; Modified.......: Großvater (http://www.autoit.de/)
; Remarks .......: Das GUI wird immer in der Originalgröße des Bildes mit dem Style $WS_POPUP und dem
; Exstyle $WS_EX_LAYERED erstellt. Der Exstyle $WS_EX_LAYERED verträgt sich offenbar
; nicht mit normalen Child-GUIs. Controls müssen deshalb in (einer) eigenen GUI(s)
; mit den Exstyles $WS_EX_MDICHILD und $WS_EX_LAYERED und der HWND des Bild-GUI
; als Parent erstellt werden. Dafür liefert UEZ im o.a. Thread ein Beispiel.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICreate_Transparent($sImage, $iLeft = -1, $iTop = -1, $iOpacity = 255)
; GDIPlus starten
If NotNot _GDIPlus_Startup() Then Return SetError(1, 0, 0)
; Bild laden
Local $hImage = _GDIPlus_ImageLoadFromFile($sImage)
If @error Then
_GDIPlus_Shutdown()
Return SetError(2, 0, 0)
EndIf
Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
; GUI erstellen
Local $hGUI = GUICreate("", $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, $WS_EX_LAYERED)
Local $hDCDst = _WinAPI_GetDC($hGUI)
Local $hDCSrc = _WinAPI_CreateCompatibleDC($hDCDst)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_SelectObject($hDCSrc, $hBitmap)
Local $tSize = DllStructCreate($tagSIZE)
Local $pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $iWidth)
DllStructSetData($tSize, "Y", $iHeight)
Local $tSource = DllStructCreate($tagPOINT)
Local $pSource = DllStructGetPtr($tSource)
Local $tBlend = DllStructCreate($tagBLENDFUNCTION)
Local $pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hDCDst, 0, $pSize, $hDCSrc, $pSource, 0, $pBlend, $ULW_ALPHA)
; Ressourcen freigeben
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hDCSrc)
_WinAPI_ReleaseDC($hGUI, $hDCDst)
_GDIPlus_Shutdown()
; HWND des GUI zurückgeben
Return $hGUI
EndFunc ;==>_GUICreate_Transparent