我收集的
#include <GDIplus.au3>
#include <GuiConstants.au3>
Global $ChartArray[0]
_GDIPlus_Startup()
$hGui = GUICreate("BalkenDiagramm", 550, 200)
GUISetState()
Global $array = [["voltagedrop [U] Bronze", 1.77], ["voltagedrop [U] Stahl", 2.02]]
_showChart($hGui, 20, 20, 484, 113, $array, 9, 1.65, 2.05)
While Sleep(10)
If GUIGetMsg() = -3 Then
Exit
EndIf
WEnd
Func _showChart($hGui, $X, $Y, $Width, $Height, $Names, $Entrys, $start, $end)
Local $gWidth = WinGetPos($hGui)[2], $gHeight = WinGetPos($hGui)[3]
Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Local $Abstand = 39
Local $Balkenbreite = 15
$white = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
_GDIPlus_GraphicsFillRect($graphics, $X, $Y, $Width, $Height, $white)
;Zeichne Balkennamen
$MaxWidth = 0
For $i = 0 To UBound($Names) - 1 Step 1
_GDIPlus_GraphicsDrawString($graphics, $Names[$i][0], $X + 5, $Y + 5 + $Abstand * $i)
$MaxSize = _GetTextLabelWidth($Names[$i][0], "Arial", 10)
If $MaxWidth < $MaxSize Then
$MaxWidth = $MaxSize
EndIf
Next
;Zeichne kleine Balkentrenner
$MaxSize += 4
$count = 0
For $i = 0 To UBound($Names) - 1 Step 1
_GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $i * $Abstand, $X + $MaxSize + 4, $Y + 2 + $i * $Abstand)
$count += 1
Next
_GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize, $Y + 2 + $count * $Abstand, $X + $Width - 20, $Y + 2 + $count * $Abstand)
;Gebe Breite
$luecke = (($Abstand - $Balkenbreite) / 2)
$MaxNumber = 0
For $i = 0 To UBound($Names) - 1 Step 1
$Names[$i][1] -= $start
$MaxNumber = $Names[$i][1] > $MaxNumber ? $Names[$i][1] : $MaxNumber
Next
;Zeichne Balken
$MaxBalkenSize = ($Width - ($X + $MaxSize + 6)) / ($end - $start)
;$MaxBalkenSize-=10
For $i = 0 To UBound($Names) - 1 Step 1
If $Names[$i][1] >= 0 Then
$white = _GDIPlus_BrushCreateSolid(0xFF4f81bd)
_GDIPlus_GraphicsFillRect($graphics, $X + $MaxSize + 6, $Y + $luecke * ($i + 1) + $luecke * $i + $i * $Balkenbreite, $MaxBalkenSize * $Names[$i][1], $Balkenbreite, $white)
EndIf
Next
;Zeichne Texte
$oneEntry = ($end - $start) / $Entrys
$oneEntryWidth = ($Width - ($X + $MaxSize + 5)) / $Entrys
$MaxWidthText = 0
For $i = 0 To $Entrys Step 1
$MaxSizeTmp = _GetTextLabelWidth(Round($start + $oneEntry * $i, 2), "Arial", 10)
If $MaxWidthText < $MaxSizeTmp Then
$MaxWidthText = $MaxSizeTmp
EndIf
Next
$MaxWidthText /= 2
For $i = 0 To $Entrys Step 1
_GDIPlus_GraphicsDrawString($graphics, Round($start + $oneEntry * $i, 2), $X + $MaxSize + 5 + $oneEntryWidth * $i - $MaxWidthText, $Y + 2 + $count * $Abstand + 4 + 5)
_GDIPlus_GraphicsDrawLine($graphics, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2, $X + $MaxSize + 5 + $oneEntryWidth * $i, $Y + 2 + $count * $Abstand + 4)
Next
;Aktualisiere ChartArray
For $i = 0 To UBound($ChartArray) - 1 Step 1
If $ChartArray[$i] = "" Then
$ChartArray[$i] = $graphics
Return $i
EndIf
Next
ReDim $ChartArray[UBound($ChartArray) + 1]
$ChartArray[UBound($ChartArray) - 1] = $graphics
Return UBound($ChartArray) - 1
EndFunc ;==>_showChart
Func _deleteChart($hGui, $Number)
;GUICtrlGetBkColor($hWnd)
_WinAPI_RedrawWindow($hGui)
_GDIPlus_GraphicsDispose($ChartArray[$Number])
$ChartArray[$Number] = ""
EndFunc ;==>_deleteChart
;Author: b8bboi@www.autoitscript.com
Func _GetTextLabelWidth($s_WinText, $s_TextFont, $i_FontSize, $i_FontWeight = -1)
Local Const $DEFAULT_CHARSET = 0 ; ANSI character set
Local Const $OUT_CHARACTER_PRECIS = 2
Local Const $CLIP_DEFAULT_PRECIS = 0
Local Const $PROOF_QUALITY = 2
Local Const $FIXED_PITCH = 1
Local Const $RGN_XOR = 3
Local Const $LOGPIXELSY = 90
$h_WinTitle = "Get Label Width"
If $i_FontWeight = "" Or $i_FontWeight = -1 Then $i_FontWeight = 600 ; default Font weight
Local $h_GUI = GUICreate($h_WinTitle, 10, 10, -100, -100, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW)
Local $hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $h_GUI)
Local $intDeviceCap = DllCall("gdi32.dll", "long", "GetDeviceCaps", "int", $hDC[0], "long", $LOGPIXELSY)
$intDeviceCap = $intDeviceCap[0]
Local $intFontHeight = DllCall("kernel32.dll", "long", "MulDiv", "long", $i_FontSize, "long", $intDeviceCap, "long", 72)
$intFontHeight = -$intFontHeight[0]
Local $hMyFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $intFontHeight, _
"int", 0, "int", 0, "int", 0, "int", $i_FontWeight, "int", 0, _
"int", 0, "int", 0, "int", $DEFAULT_CHARSET, _
"int", $OUT_CHARACTER_PRECIS, "int", $CLIP_DEFAULT_PRECIS, _
"int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $s_TextFont)
DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hDC[0], "hwnd", $hMyFont[0])
Local $res = DllStructCreate("int;int")
Local $ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC[0], "str", $s_WinText, "long", StringLen($s_WinText), "ptr", DllStructGetPtr($res))
Local $intLabelWidth = DllStructGetData($res, 1)
GUIDelete($h_GUI)
Return $intLabelWidth
EndFunc ;==>_GetTextLabelWidth
|