Hallo.
Ich nutze seit geraumer Zeit eine Funktion eines Freundes um Progresse selber zu malen. Das ganze passiert mit GDI+. Die Progresse sehen auch gut aus, allerdings ist der Text auf den Progressen nicht mittig, sondern man bestimmt die Position durch eine X-Koordinate.
Zeile 45-50 sind die, wo der Text geschrieben wird. Ich weiß aber nicht, wie ich da soetwas wie einen Centerstyle einbauen könnte.
In dem Beispiel läuft der Text nach rechts, wo sich der Text befindet, wird durch den letzten Parameter in der Funktion _ProgressCreate angegeben.
Hier die der Code:
Spoiler anzeigen
#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]$hGUI = GUICreate("Progress", 200, 30)
$hGUIProgress = GUICtrlCreatePic("", 10, 10, 180, 17)
GUISetState()
Sleep(1000)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]For $i = 1 To 100
$hBitmap = _WinAPI_CreateBitmap(180, 17, 1, 32)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_ProgressCreate($hGraphic, 0x6FFF0000, "Procedure: " & $i & "%", $i * 1.8, 180, $i * 0.85)
$hNewBitmapHandle = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_SetBitmapToCtrl($hGUIProgress, $hNewBitmapHandle)
Sleep(50)
Next
Sleep(2000)
_GDIPlus_Shutdown()
;Creates progresses
Func _ProgressCreate($hGraphic, $vColor, $vText, $vPercent, $vWidth, $vTextWidth)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
Dim $hPenProgress[99]
For $i = 0 To 8
$vSWColor = "0xFF" & Hex($i * 2 * 10, 2) & Hex($i *2* 10, 2) & Hex($i * 2 * 10, 2)
$hPenProgress[$i] = _GDIPlus_PenCreate($vSWColor)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, $i, $vWidth, $i, $hPenProgress[$i])
_GDIPlus_PenDispose($hPenProgress[$i])
Next
For $i = 0 To 7
$vSWColor = "0xFF" & Hex($i*2 * 10, 2) & Hex($i *2* 10, 2) & Hex($i *2* 10, 2)
$hPenProgress[$i] = _GDIPlus_PenCreate($vSWColor)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 16 - $i, $vWidth, 16 - $i, $hPenProgress[$i])
_GDIPlus_PenDispose($hPenProgress[$i])
Next
$hBrushProgress = _GDIPlus_BrushCreateSolid($vColor)
_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $vPercent, 17, $hBrushProgress)
$hFontFamilyProgress = _GDIPlus_FontFamilyCreate("Arial")
$hFontProgress = _GDIPlus_FontCreate($hFontFamilyProgress, 8, 1)
$hLayoutProgress = _GDIPlus_RectFCreate($vTextWidth, 1, $vWidth, 17)
$hFormatProgress = _GDIPlus_StringFormatCreate()
$hBrushTextProgress = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $vText, $hFontProgress, $hLayoutProgress, $hFormatProgress, $hBrushTextProgress)
$hPenOutLineTL = _GDIPlus_PenCreate(0xFF666666)
$hPenOutLineBR = _GDIPlus_PenCreate(0xFFDDDDDD)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 0, $vWidth, 0, $hPenOutLineTL)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 0, 0, 16, $hPenOutLineTL)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 16, $vWidth, 16, $hPenOutLineBR)
_GDIPlus_GraphicsDrawLine($hGraphic, $vWidth - 1, 0, $vWidth - 1, 16, $hPenOutLineBR)
_GDIPlus_PenDispose($hPenOutLineTL)
_GDIPlus_PenDispose($hPenOutLineBR)
_GDIPlus_BrushDispose($hBrushProgress)
_GDIPlus_FontFamilyDispose($hFontFamilyProgress)
_GDIPlus_FontDispose($hFontProgress)
_GDIPlus_StringFormatDispose($hFormatProgress)
_GDIPlus_BrushDispose($hBrushTextProgress)
EndFunc ;==>_SM_ProgressCreate
;Set a bitmap to a control - by Zedna
Func _SetBitmapToCtrl($vCtrlID, $h_Bitmap)
Local $hWnd = GUICtrlGetHandle($vCtrlID)
If $hWnd = 0 Then Return SetError(1, 0, 0)
Local $vOldStyle = _WinAPI_GetWindowLong($hWnd, -16)
_WinAPI_SetWindowLong($hWnd, -16, BitOR($vOldStyle, 0xE))
Local $vOldBmp = _SendMessage($hWnd, 0x0172, 0, $h_Bitmap)
If $vOldBmp <> 0 Then _WinAPI_DeleteObject($vOldBmp)
EndFunc ;==>_SM_SetBitmapToCtrl
Wenn ihr Ideen habt, wie ich das bei mir einbauen könnte oder anders machen kann, dann her damit =)
MfG NoName