#include <GDIPlus.au3>

Opt('GUIOnEventMode', 1)

Global $Titel = 'Pixelsalat'
Global $Breite = 407, $Hoehe = 407
Global $FPS_Timer, $FPS

_GDIPlus_Startup()

$hGUI = GUICreate($Titel, $Breite, $Hoehe, _Center_X($Breite), _Center_Y($Hoehe))
GUISetOnEvent(-3, '_Exit')
GUISetState(@SW_SHOW, $hGUI)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($Breite, $Hoehe, $hGraphic)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

DllCall($ghGDIPDll, "int", "GdipGraphicsClear", "handle", $hBackbuffer, "dword", 0xFF000000)

While WinSetTitle($hGUI, '', $Titel & ' FPS: ' & $FPS)
	$FPS = Round(1000 / TimerDiff($FPS_Timer), 2)
	$FPS_Timer = TimerInit()
		For $x = 2 To 401 Step 7
		For $y = 2 To 401 Step 7
			Switch Random(0, 1, 1)
				Case 1
					DllCall($ghGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", 0x77002200)
				Case Else
					DllCall($ghGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", 0x77DDFFDD)
			EndSwitch
		DllCall($ghGDIPDll, "int", "GdipFillRectangleI", "handle", $hBackbuffer, "handle", $hBrush, "int", $x, "int", $y, "int", 3, "int", 3)
		Next
	Next
	DllCall($ghGDIPDll, "int", "GdipDrawImageI", "handle", $hGraphic, "handle", $hBitmap, "int", 0, "int", 0)
WEnd

Func _Exit()
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_BitmapDispose($hBitmap)
	_GDIPlus_GraphicsDispose($hBackbuffer)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_Shutdown()
	Exit
EndFunc   ;==>_Exit

Func _Center_X($a)
	Return @DesktopWidth / 2 - $a / 2
EndFunc   ;==>_Abstand_X

Func _Center_Y($a)
	Return @DesktopHeight / 2 - $a / 2
EndFunc   ;==>_Abstand_Y