#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


#AutoIt3Wrapper_UseX64=n
Global $pASM_Sin = _StructCreateBCA16("0x538B5C24088D841B00000080C1FB1FF7E88D84120000008031D85BC20400")
Global $pASM_Cos = _StructCreateBCA16("0x538B5C240881C3000000408D841B00000080C1FB1FF7E88D84120000008031D85BC20400")




Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $iWidth = 800
Global $iHeight = 800

_GDIPlus_Startup()
Global $hGui = GUICreate("ASM", $iWidth, $iHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmp_Buffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfx_Buffer = _GDIPlus_ImageGetGraphicsContext($hBmp_Buffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfx_Buffer, 2)
_GDIPlus_GraphicsClear($hGfx_Buffer, 0xFF000000)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUISetState()

_DrawCircle()

While Sleep(10)
WEnd



Func _DrawCircle()
	Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2)

	Local $fDeg2Rad = ATan(1) / 45

	Local $iW = $iWidth * 0.5
	Local $iH = $iHeight * 0.5

	Local $fX1, $fY1, $fX2, $fY2
	For $i = 0 To 360 Step 0.1
		$fX1 = $iW + Cos($i * $fDeg2Rad) * $iW * 0.8
		$fY1 = $iH + Sin($i * $fDeg2Rad) * $iH * 0.8
		If $fX2 Then _GDIPlus_GraphicsDrawLine($hGfx_Buffer, $fX1, $fY1, $fX2, $fY2, $hPen)
		$fX2 = $fX1
		$fY2 = $fY1
	Next

	Local $iM = 2 ^ 31
	$fX2 = 0
	_GDIPlus_PenSetColor($hPen, 0xFFFF0044)
	For $i = 0 To 360 Step 0.1
		$fX1 = $iW + (DllCallAddress("int", $pASM_Cos, "uint", $i / 45 * $iM)[0] / -$iM) * $iW * 0.8
		$fY1 = $iH + (DllCallAddress("int", $pASM_Sin, "uint", $i / 45 * $iM)[0] / -$iM) * $iH * 0.8
		If $fX2 Then _GDIPlus_GraphicsDrawLine($hGfx_Buffer, $fX1, $fY1, $fX2, $fY2, $hPen)
		$fX2 = $fX1
		$fY2 = $fY1
	Next

	_GDIPlus_PenDispose($hPen)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmp_Buffer, 0, 0)
EndFunc   ;==>_DrawCircle





Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmp_Buffer, 0, 0)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func _Exit()
	_GDIPlus_GraphicsDispose($hGfx_Buffer)
	_GDIPlus_BitmapDispose($hBmp_Buffer)
	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_Shutdown()
	GUIDelete($hGui)
	Exit
EndFunc   ;==>_Exit


Func _StructCreateBCA16($bBinaryCode)
	Local $iSize = BinaryLen($bBinaryCode)
	Local $aResult = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", $iSize + 16, "dword", 0x00001000, "dword", 0x00000040)
	If @error Or Not $aResult[0] Then Return SetError(1, 0, False)
	Local $pStruct = Number($aResult[0])
	$pStruct = $pStruct + 16 - Mod($pStruct, 16)
	Local $tStruct = DllStructCreate("byte[" & $iSize & "];", $pStruct)
	DllStructSetData($tStruct, 1, $bBinaryCode)
	Return $pStruct
EndFunc   ;==>_StructCreateBCA16
