說明:
PolylineTo 函式可在指定的裝置環境代碼(Device Context)上繪製一條或多條直線
引用函式庫:
GDI32
適用系統:
Windows NT 3.1 或 Windows 95以上
函式原型:
Declare Function PolylineTo Lib "gdi32" Alias "PolylineTo" ( _ ByVal hdc As Long, _ ByVal lppt As POINTAPI, _ ByVal cCount As Long _ ) As Long
參數型態及說明:
hdc:Long 要繪製的裝置環境代碼(Device Context)
lppt:POINTAPI 直線的 POINT 座標結構陣列
cCount:Long lppt 陣列中要繪製直線的點的數量(會從第一個與第二個點之間繪製一條直線,其它依此類推)
回傳值:
Long 繪製成功的話,將會回傳非零的數值;若繪製失敗的話,則回傳 0
.NET Framework API:
System.Drawing.Graphics.DrawLines
VB範例:
檢視原始碼 Visual Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 'VB的宣告 Private Declare Function PolylineTo Lib "gdi32" ( _ ByVal hdc As Long, _ ByRef lppt As POINTAPI, _ ByVal cCount As Long _ ) As Long Private Declare Function ReleaseDC Lib "user32" ( _ ByVal hwnd As Long, _ ByVal hdc As Long _ ) As Long Private Declare Function GetDC Lib "user32" ( _ ByVal hwnd As Long _ ) As Long Dim hdc As Long '取得目前執行視窗的裝置環境代碼(Device Context) hdc = GetDC(Form1.hwnd) '設定POINTAPI陣列 Dim pts(0 To 2) As POINTAPI pts(0).x = 10: pts(0).y = 20 pts(1).x = 50: pts(1).y = 40 pts(2).x = 110: pts(2).y = 130 Dim rtvl As Long '在目前執行視窗上依pts陣列中的座標來產生線段 rtvl = PolylineTo(hdc, pts(0), UBound(pts) + 1) Dim r As Long '釋放目前執行視窗的裝置環境代碼(Device Context) r = ReleaseDC(Form1.hwnd, hdc) |
RB範例:
檢視原始碼 REALBasic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 'RB的宣告 Declare Function PolylineTo Lib "gdi32" ( _ hdc As Integer, _ lppt As Ptr, _ cCount As Integer _ ) As Boolean Declare Function ReleaseDC Lib "user32" ( _ hwnd As Integer, _ hdc As Integer _ ) As Integer Declare Function GetDC Lib "user32" ( _ hwnd As Integer _ ) As Integer Dim hdc As Integer '取得目前執行視窗的裝置環境代碼(Device Context) hdc = GetDC(Window1.WinHWND) Dim pts(3) As MemoryBlock pts(0) = New MemoryBlock(8) pts(0).Long(0) = 10 pts(0).Long(4) = 20 pts(1) = New MemoryBlock(8) pts(1).Long(0) = 50 pts(1).Long(4) = 40 pts(2) = New MemoryBlock(8) pts(2).Long(0) = 110 pts(2).Long(4) = 130 Dim rtvl As Boolean '在目前執行視窗上的(0, 0)畫一個長高為100的矩形 rtvl = PolylineTo(hdc, pts(1), 1) Dim r As Integer '釋放目前執行視窗的裝置環境代碼(Device Context) r = ReleaseDC(Window1.WinHWND, hdc) |
VB.NET範例:
檢視原始碼 VB.NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | '宣告一個POINTAPI Public Structure POINTAPI Dim x As UInteger Dim y As UInteger End Structure 'VB.NET的宣告 <DllImport("gdi32.dll")> _ Shared Function PolylineTo( _ ByVal hdc As IntPtr, _ ByVal lppt As POINTAPI(), _ ByVal cCount As UInteger _ ) As Boolean End Function <DllImport("user32.dll")> _ Shared Function ReleaseDC( _ ByVal hwnd As IntPtr, _ ByVal hdc As IntPtr _ ) As UInteger End Function <DllImport("user32.dll")> _ Shared Function GetDC( _ ByVal hwnd As IntPtr _ ) As IntPtr End Function Dim hdc As IntPtr '取得目前執行視窗的裝置環境代碼(Device Context) hdc = GetDC(Me.Handle) '設定POINTAPI陣列 Dim pts(2) As POINTAPI pts(0).x = 10 : pts(0).y = 20 pts(1).x = 50 : pts(1).y = 40 pts(2).x = 110 : pts(2).y = 130 Dim rtvl As Boolean '在目前執行視窗上依pts陣列中的座標來產生線段 rtvl = PolylineTo(hdc, pts, pts.Length) Dim r As Integer '釋放目前執行視窗的裝置環境代碼(Device Context) r = ReleaseDC(Me.Handle, hdc) |
C#範例:
檢視原始碼 C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //宣告一個POINTAPI public struct POINTAPI { public uint x; public uint y; } //C#的宣告 [DllImport("gdi32")] public static extern bool PolylineTo( IntPtr hdc, POINTAPI[] lppt, uint cCount ); [DllImport("user32")] public static extern uint ReleaseDC( IntPtr hwnd, IntPtr hdc ); [DllImport("user32")] public static extern IntPtr GetDC( IntPtr hwnd ); IntPtr hdc; //取得目前執行視窗的裝置環境代碼(Device Context) hdc = GetDC(this.Handle); //設定POINTAPI陣列 POINTAPI[] pts = new POINTAPI[3]; pts[0].x = 10; pts[0].y = 20; pts[1].x = 50; pts[1].y = 40; pts[2].x = 110; pts[2].y = 130; bool rtvl; //在目前執行視窗上依pts陣列中的座標來產生線段 rtvl = PolylineTo(hdc, pts, (uint)pts.Length); uint r; //釋放目前執行視窗的裝置環境代碼(Device Context) r = ReleaseDC(this.Handle, hdc); |
註釋:
REALbasic 在呼叫 PolylineTo 函式時,單一點還能正常執行;但是多點的話,執行出來的結果就有點不正常。