#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
AutoItSetOption("GUIOnEventMode", 1)
Global Const $ix = "800", $iy = "500", $title = "柱状图 GDI+ (GDI+新人 yamakawa)"
Global $Color = [0xFF1FF4FB, 0xFF07F98C, 0xFF91A804, 0xFFCC9302, 0xFFAF5801, 0xFF9C426B, 0xFF9744A7, 0xFF9841E4, 0xFF241BEE, 0xFF2472F5, 0xFF2190F4, 0xFF12C2FF]
Global $data = ["80","110.5","200","150.3","220","110","150","400","250","180.4","300","480"]
Global $ydata = [0,100,200,300,400,500]
Global $month = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
Global $pen1,$hBitmap1,$hBackbuffer1,$hBrush
#Region GUI
Global $mGui = GUICreate($title, $ix + 100, $iy + 100)
Global $pic1 = GUICtrlCreatePic("", 40, 40, $ix + 60, $iy + 60)
Global $hpic1 = GUICtrlGetHandle($pic1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
#EndRegion
_GDIPlus_Startup()
_draw()
Func _draw()
Local $shift = "30"
Local $hGraphics1 = _GDIPlus_GraphicsCreateFromHWND($hpic1)
$hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($ix + 60, $iy + 60, $hGraphics1)
$hBackbuffer1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer1, 2)
_GDIPlus_GraphicsClear($hBackbuffer1, 0xF2000000 + 0x00FF00)
Local $pen1 = _GDIPlus_PenCreate(0xFF000000,2)
;画XY线
_GDIPlus_GraphicsDrawLine($hBackbuffer1, $shift, 0, $shift, $iy, $Pen1);Y轴
;
For $i = 0 To 5
_GDIPlus_GraphicsDrawString($hBackbuffer1, $ydata[$i], $shift / 2 - 10, $iy - $i * 100)
Next
_GDIPlus_GraphicsDrawLine($hBackbuffer1, $shift, $iy, $ix + $shift, $iy, $Pen1);X轴
For $i = 0 To 11
_GDIPlus_GraphicsDrawString($hBackbuffer1, $month[$i], $shift + 20 + $i * 65, $iy + 10)
Next
;填入数据
For $i = 0 To 11
$hBrush = _GDIPlus_BrushCreateSolid($Color[$i])
_GDIPlus_GraphicsFillRect($hBackbuffer1,$shift + 20 + $i * 65,$iy - $data[$i],50,$data[$i],$hBrush)
_GDIPlus_GraphicsDrawString($hBackbuffer1,$data[$i],$shift + 30 + $i * 65,$iy - $data[$i] - 20)
_GDIPlus_BrushDispose($hBrush)
Next
;草稿好了,绘图
_GDIPlus_GraphicsDrawImageRect($hGraphics1, $hBitmap1, 0, 0, $ix, $iy)
EndFunc ;==>_draw
While 1
Sleep(20)
WEnd
Func _Exit() ;
_GDIPlus_PenDispose($pen1)
_GDIPlus_BitmapDispose($hBitmap1)
_GDIPlus_Shutdown()
GUIDelete($mGui)
Exit
EndFunc ;==>_Exit
GDI+新人练手