#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Global Const $iPi = ACos(-1)
Global Const $iDegToRad = $iPi / 180
Global $iR = 100, $iAngleOld = -1, $iWp = 200, $iHp = 200, $iWm = 500, $iHm = 400
$hGUI = GUICreate('Test', $iWm, $iHm)
GUISetBkColor(0xF0F0F0)
$nButton = GUICtrlCreateButton('Exit', 50, 10, 100, 30)
$hGUI_Parent = GUICreate('', $iWp, $iHp, ($iWm - $iWp) / 2, ($iHm - $iHp) / 2, $WS_POPUP)
GUISetBkColor(0xF0F0F0)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Parent)
_WinAPI_SetParent($hGUI_Parent, $hGUI)
_GDIPlus_Startup()
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI_Parent)
While 1
$aWinPos = WinGetPos($hGUI_Parent)
$iAngle = _Angle(MouseGetPos(0), MouseGetPos(1), $aWinPos[0] + $iWp / 2, $aWinPos[1] + $iHp / 2)
If Not @error Then
If $iAngleOld <> $iAngle Then
$iAngleOld = $iAngle
_GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
$iX = $aWinPos[0] + $iWp / 2 - $iR * Cos($iAngle * $iDegToRad) - $aWinPos[0]
$iY = $aWinPos[1] + $iHp / 2 - $iR * Sin($iAngle * $iDegToRad) - $aWinPos[1]
_GDIPlus_GraphicsDrawLine($hGraphic, $iWp / 2, $iHp / 2, $iX, $iY, $hPen)
EndIf
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $nButton
_Exit()
EndSwitch
WEnd
Func _Angle($i_X, $i_Y, $i_Xcenter, $i_Ycenter)
;Yashied, http://autoit-script.ru/index.php/topic,333.0.html
Local $i_Grad
If ($i_X = $i_Xcenter) And ($i_Y = $i_Ycenter) Then
Return SetError(1, 0, -1)
EndIf
$i_Grad = ($i_Y > $i_Ycenter) * 180 - ATan(($i_Xcenter - $i_X) / ($i_Ycenter - $i_Y)) * 180 / $iPi + 90
If $i_Grad = 360 Then
$i_Grad = 0
EndIf
Return $i_Grad
EndFunc ;==>_Angle
Func _Exit()
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit