扇形の描画 <TOP>
扇形を描画します。
Pie 扇形を描画する
例では、座標を変て描画される図形の確認をしています。
扇を形成する円(楕円)は、・1と・2で表される矩形領域に内接します。
扇の開始位置は、円(楕円)の中心と・3を結ぶ延長線上の交点、扇の終了位置は、中心と・4を結ぶ延長線上の交点です。
起動時
値を変えてみます
'================================================================ '= 扇形の描画 '= (Pie.bas) '================================================================ #include "Windows.bi" ' 扇形を描画する Declare Function Api_Pie& Lib "gdi32" Alias "Pie" (ByVal hDC&, ByVal X1&, ByVal Y1&, ByVal X2&, ByVal Y2&, ByVal X3&, ByVal Y3&, ByVal X4&, ByVal Y4&) ' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得 Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&) ' デバイスコンテキストを解放 Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&) Var Shared Text(6) As Object Var Shared Edit(7) As Object Var Shared Picture1 As Object Var Shared Group1 As Object Var Shared Timer1 As Object For i = 0 To 7 If i < 6 Then Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1))) : Text(i).SetFontSize 14 End If Edit(i).Attach GetDlgItem("Edit" & Trim$(Str$(i + 1))) : Edit(i).SetFontSize 14 Next Picture1.Attach GetDlgItem("Picture1") Group1.Attach GetDlgItem("Group1") : Group1.SetFontSize 14 Timer1.Attach GetDlgItem("Timer1") Var Shared hDC As Long '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() ShowWindow -1 Cls hDC = Api_GetDC(Picture1.GethWnd) Timer1.SetInterval 100 Timer1.Enable -1 End Sub '================================================================ '= '================================================================ Declare Sub Timer1_Timer edecl () Sub Timer1_Timer() Var x(3) As Long Var y(3) As Long Var Ret As Long Picture1.Cls For i = 0 To 3 x(i) = Val(GetDlgItemText("Edit" & Trim$(Str$(i + 1)))) y(i) = Val(GetDlgItemText("Edit" & Trim$(Str$(i + 5)))) Next Picture1.Line(x(0), y(0)) - (x(1), y(1)), , 14, b Ret = Api_Pie(hDC, x(0), y(0), x(1), y(1), x(2), y(2), x(3), y(3)) For i = 0 To 3 Picture1.SetDrawWidth 4 Picture1.Pset(x(i), y(i)), 5 Picture1.SetDrawWidth 0 Picture1.Symbol(x(i) - 1, y(i) + 1), Trim$(Str$(i + 1)), 1, 1, 2 Next End Sub '================================================================ '= '================================================================ Declare Sub MainForm_QueryClose edecl () Sub MainForm_QueryClose() Var Ret As Long Ret = Api_ReleaseDC(Picture1.GethWnd, hDC) End End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End