Code : Tout sélectionner
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
Global $hGUI = GUICreate("", 400, 400,500)
GUISetOnEvent(-3, "SpecialEvents")
GUISetState()
drawline()
While 1
Sleep(100)
WEnd
Func SpecialEvents()
Exit
EndFunc
Func drawline()
$ptX = 200 ;centre du graphe
$ptY = 200
$pas = 1
$trait = 4
$cycle = 0
;---------------------------------------------------------------------------------------
$hDC = _WinAPI_GetDC($hGUI)
$hPen0 = _WinAPI_CreatePen($PS_SOLID, $trait, _WinAPI_RGB(120,120, 120))
$hPen = _WinAPI_CreatePen($PS_SOLID, $trait, _WinAPI_RGB(255,0, 0))
$hPen1 = _WinAPI_CreatePen($PS_SOLID, $trait, _WinAPI_RGB(51,51, 204))
$hPen2 = _WinAPI_CreatePen($PS_SOLID, $trait, _WinAPI_RGB(0,255, 255))
$hPen3 = _WinAPI_CreatePen($PS_SOLID, $trait, _WinAPI_RGB(0,138, 0))
Local $X = 400, $Y = 400
Local Const $PI = 3.141592653589793
Local $fDegToRad = $PI / 180
;----------------------------------------------------------------------------------------
$X1 = 150 ;diametre du graphe
$Y1 = 150
$g_tRECT = DllStructCreate($tagRect)
Local $array[6][5] ;position des étiquettes 6 lignes pour 6 valeurs >> de 0 à 360°
Local $i = 0
For $A = 0 To 360 Step $pas
If $A = 0 Then ; choix couleurs selon les degrés
$Orig1 = _WinAPI_SelectObject($hDC, $hPen0)
EndIf
If $A = 50 Then
$Orig1 = _WinAPI_SelectObject($hDC, $hPen)
$cycle = $A
EndIf
If $A = 130 Then
$Orig1 = _WinAPI_SelectObject($hDC, $hPen1)
$cycle = $A
EndIf
If $A = 180 Then
$Orig1 = _WinAPI_SelectObject($hDC, $hPen2)
$cycle = $A
EndIf
If $A = 279 Then
$Orig1 = _WinAPI_SelectObject($hDC, $hPen3)
$cycle = $A
EndIf
If $A = 360 Then
$cycle = 360
EndIf
_WinAPI_DrawLine($hDC, $ptX, $ptY, $ptX, $ptY )
$recupX = 0
$recupY = 0
If $A > 90 And $A <= 270 Then $recupX = - 40 ;décale les étiquettes selon l'angle
If $A > 270 And $A < 360 Then $recupY = - 20
;------------------------------------------------------------------------
Local $Cos2 = Round($X1 * Cos($A * $fDegToRad),2)
Local $Sin2 = Round($Y1 * Sin($A * $fDegToRad),2)
_WinAPI_LineTo($hDC, $ptX + $Cos2 ,$ptY + $Sin2 )
_WinAPI_MoveTo($hDC, $ptX ,$ptY )
If $A = $cycle Then ;enregistre position des étiquettes
$array[$i][0] = $ptX + $Cos2 + $recupX
$array[$i][1] = $ptY + $Sin2 + $recupY
$array[$i][2] = $ptX + $Cos2 + 50
$array[$i][3] = $ptY + $Sin2 + 50
$array[$i][4] = $cycle
$i += 1
EndIf
;---------------------------------------------------------------------------
Next
For $ii = 0 To UBound($array) - 1 ;écriture des étiquettes
DllStructSetData($g_tRECT, "Left", $array[$ii][0])
DllStructSetData($g_tRECT, "Top", $array[$ii][1] )
DllStructSetData($g_tRECT, "Right", $array[$ii][2])
DllStructSetData($g_tRECT, "Bottom", $array[$ii][3])
_WinAPI_DrawText($hDC,"-> " & $array[$ii][4], $g_tRECT, $DT_LEFT )
Next
_WinAPI_DeleteObject($hPen3)
_WinAPI_DeleteObject($hPen2)
_WinAPI_DeleteObject($hPen1)
_WinAPI_DeleteObject($hPen)
_WinAPI_DeleteObject($hPen0)
_WinAPI_ReleaseDC($hGUI, $hDC)
;_ArrayDisplay($array,"Etiquettes")
EndFunc