連続した直線を描画(T) <TOP>
連続した直線を引きます。
Polyline 連続直線を引く
GetDC ディスプレイデバイスコンテキストのハンドルを取得
ReleaseDC デバイスコンテキストを解放
例では起動時にTOKOを描画、実行ボタンクリックで、ピクチャボックスに11角形を描画しています。
'================================================================ '= 連続した直線を引く '= (Polyline.bas)) '================================================================ #include "Windows.bi" Type POINTAPI X As Long Y As Long End Type ' 連続直線を引く Declare Function Api_Polyline& Lib "gdi32" Alias "Polyline" (ByVal hDC&, lpPoint As POINTAPI, ByVal nCount&) ' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得。その後、GDI 関数を使って、返されたデバイスコンテキスト内で描画を行える Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&) ' デバイスコンテキストを解放 Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&) Var Shared Picture1 As Object Picture1.Attach GetDlgItem("Picture1") Var Shared Pts(11) As POINTAPI '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() Var hDC As Long Var Ret As Long hDC = Api_GetDC(GethWnd) Pts(0).X = 10: Pts(0).Y = 10 Pts(1).X = 30: Pts(1).Y = 10 Pts(2).X = 20: Pts(2).Y = 10 Pts(3).X = 20: Pts(3).Y = 40 Ret = Api_Polyline(hDC, Pts(0), 4) Pts(0).X = 40: Pts(0).Y = 10 Pts(1).X = 35: Pts(1).Y = 15 Pts(2).X = 35: Pts(2).Y = 35 Pts(3).X = 40: Pts(3).Y = 40 Pts(4).X = 50: Pts(4).Y = 40 Pts(5).X = 55: Pts(5).Y = 35 Pts(6).X = 55: Pts(6).Y = 15 Pts(7).X = 50: Pts(7).Y = 10 Pts(8).X = 40: Pts(8).Y = 10 Ret = Api_Polyline(hDC, Pts(0), 9) Pts(0).X = 60: Pts(0).Y = 10 Pts(1).X = 60: Pts(1).Y = 40 Pts(2).X = 60: Pts(2).Y = 25 Pts(3).X = 80: Pts(3).Y = 10 Pts(4).X = 60: Pts(4).Y = 25 Pts(5).X = 80: Pts(5).Y = 40 Ret = Api_Polyline(hDC, Pts(0), 6) Pts(0).X = 90: Pts(0).Y = 10 Pts(1).X = 85: Pts(1).Y = 15 Pts(2).X = 85: Pts(2).Y = 35 Pts(3).X = 90: Pts(3).Y = 40 Pts(4).X = 100: Pts(4).Y = 40 Pts(5).X = 105: Pts(5).Y = 35 Pts(6).X = 105: Pts(6).Y = 15 Pts(7).X = 100: Pts(7).Y = 10 Pts(8).X = 90: Pts(8).Y = 10 Ret = Api_Polyline(hDC, Pts(0), 9) Ret = Api_ReleaseDC(GethWnd, hDC) End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var PI As single Var i As Long Var PointNum As Long Var phDC As Long Var Ret As Long phDC = Api_GetDC(Picture1.GethWnd) PI = 3.14159 PointNum = 11 For i = 0 To PointNum Pts(i).X = Cos(2 * PI * i * 2 / PointNum) * 80 + 80 Pts(i).Y = Sin(2 * PI * i * 2 / PointNum) * 80 + 80 Next Ret = Api_Polyline(phDC, Pts(0), PointNum + 1) Ret = Api_ReleaseDC(Picture1.GethWnd, phDC) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End