Home » Windows API

Pie

說明:
Pie 函式會在指定的裝置環境代碼(Device Context)上繪製一個Pie形的圓餅圖


引用函式庫:
GDI32


適用系統:
Windows NT 3.1 或 Windows 95以上


函式原型:

Declare Function Pie Lib "gdi32" Alias "Pie" ( _
    ByVal hdc As Long, _
    ByVal nLeftRect As Long, _
    ByVal nTopRect As Long, _
    ByVal nRightRect As Long, _
    ByVal nBottomRect As Long, _
    ByVal nXRadial1 As Long, _
    ByVal nYRadial1 As Long, _
    ByVal nXRadial2 As Long, _
    ByVal nYRadial2 As Long _
    ) As Long



參數型態及說明:
hdcLong 要繪製弧形的裝置環境代碼(Device Context)
nLeftRectLong 弧線形的左上方 X 座標
nTopRectLong 弧線的左上方 Y 座標
nRightRectLong 弧線的右下方 X 座標
nBottomRectLong 弧線的右下方 Y 座標
nXRadial1Long 弧線起始點的 X 座標
nYRadial1Long 弧線起始點的 Y 座標
nXRadial2Long 弧線終點的 X 座標
nYRadial2Long 弧線終點的 Y 座標

回傳值:
Long 繪製成功的話,將會回傳非零的數值;若繪製失敗的話,則回傳 0

.NET Framework API:
System.Drawing.Graphics.DrawPie
System.Drawing.Graphics.FillPie


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 Pie Lib "gdi32" ( _
	ByVal hdc As Long, _
	ByVal nLeftRect As Long, _
	ByVal nTopRect As Long, _
	ByVal nRightRect As Long, _
	ByVal nBottomRect As Long, _
	ByVal nXRadial1 As Long, _
	ByVal nYRadial1 As Long, _
	ByVal nXRadial2 As Long, _
	ByVal nYRadial2 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)
 
Dim rtvl As Long
 
'在目前執行視窗上繪製一個圓餅圖
rtvl = Pie(hdc, 10, 20, 50, 60, 20, 20, 30, 30)
 
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
'RB的宣告
Declare Function Pie Lib "gdi32" ( _
	hdc As Integer, _
	nLeftRect As Integer, _
	nTopRect As Integer, _
	nRightRect As Integer, _
	nBottomRect As Integer, _
	nXRadial1 As Integer, _
	nYRadial1 As Integer, _
	nXRadial2 As Integer, _
	nYRadial2 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 rtvl As Boolean
 
'在目前執行視窗上繪製一個圓餅圖
rtvl = Pie(hdc, 10, 20, 50, 60, 20, 20, 30, 30)
 
Dim r As Integer
 
'釋放目前執行視窗的裝置環境代碼(Device Context)
r = ReleaseDC(Window1.WinHWND, hdc)

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
'VB.NET的宣告
<DllImport("gdi32.dll")> _
Shared Function Pie( _
	ByVal hdc As IntPtr, _
	ByVal nLeftRect As UInteger, _
	ByVal nTopRect As UInteger, _
	ByVal nRightRect As UInteger, _
	ByVal nBottomRect As UInteger, _
	ByVal nXRadial1 As UInteger, _
	ByVal nYRadial1 As UInteger, _
	ByVal nXRadial2 As UInteger, _
	ByVal nYRadial2 As UInteger _
	) As Boolean
End Function
<DllImport("user32.dll")> _
Shared Function ReleaseDC( _
	ByVal hwnd As IntPtr, _
	ByVal hdc As IntPtr _
	) As Boolean
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)
 
Dim rtvl As Boolean
 
'在目前執行視窗上繪製一個圓餅圖
rtvl = Pie(hdc, 10, 20, 50, 60, 20, 20, 30, 30)
 
Dim r As Boolean
 
'釋放目前執行視窗的裝置環境代碼(Device Context)
r = ReleaseDC(Me.Handle, hdc)

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
//C#的宣告
[DllImport("gdi32")]
public static extern bool Pie(
	IntPtr hdc, 
	uint nLeftRect, 
	uint nTopRect, 
	uint nRightRect, 
	uint nBottomRect, 
	uint nXRadial1, 
	uint nYRadial1, 
	uint nXRadial2, 
	uint nYRadial2
	);
[DllImport("user32")]
public static extern bool ReleaseDC(
	IntPtr hwnd, 
	IntPtr hdc
	);
[DllImport("user32")]
public static extern IntPtr GetDC(
	IntPtr hwnd
	);
 
IntPtr hdc;
 
//取得目前執行視窗的裝置環境代碼(Device Context)
hdc = GetDC(this.Handle);
 
bool rtvl;
 
//在目前執行視窗上繪製一個圓餅圖
rtvl = Pie(hdc, 10, 20, 50, 60, 20, 20, 30, 30);
 
bool r;
 
//釋放目前執行視窗的裝置環境代碼(Device Context)
r = ReleaseDC(this.Handle, hdc);

發表迴響