Home » Windows API

SetTextCharacterExtra

說明:
SetTextCharacterExtra 函式可在裝置環境代碼(Device Context)中輸出文字時,在字元間插入額外的間距


引用函式庫:
GDI32


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


函式原型:

Declare Function SetTextCharacterExtra Lib "gdi32" Alias "SetTextCharacterExtra" ( _
    ByVal hdc As Long ,_
    ByVal nCharExtra As Long _
    ) As Long



參數型態及說明:
hdcLong 要輸出文字的裝置環境代碼(Device Context)
nCharExtraLong 字元間要插入的間距

回傳值:
Long 呼叫成功的話,將會回傳前一個字元間距的大小;若呼叫失敗的話,則回傳 0x80000000

.NET Framework API:


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'VB的宣告
Private Declare Function SetTextCharacterExtra Lib "gdi32" ( _
	ByVal hdc As Long, _
	ByVal nCharExtra 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
 
'設定字元間距為10
rtvl = SetTextCharacterExtra(hdc, 10)

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'RB的宣告
Declare Function SetTextCharacterExtra Lib "gdi32" ( _
	hdc As Integer, _
	nCharExtra 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 Integer
 
'設定字元間距為10
rtvl = SetTextCharacterExtra(hdc, 10)

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'VB.NET的宣告
<DllImport("gdi32.dll")> _
Shared Function SetTextCharacterExtra( _
	ByVal hdc As IntPtr, _
	ByVal nCharExtra As Integer _
	) As Integer
End Function
<DllImport("user32.dll")> _
Shared Function GetDC( _
	ByVal hwnd As IntPtr _
	) As IntPtr
End Function
 
Dim hdc As Integer
 
'取得目前執行視窗的裝置環境代碼(Device Context)
hdc = GetDC(Me.Handle)
 
Dim rtvl As Integer
 
'設定字元間距為10
rtvl = SetTextCharacterExtra(hdc, 10)

C#範例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//C#的宣告
[DllImport("gdi32")]
public static extern int SetTextCharacterExtra(
	IntPtr hdc, 
	int nCharExtra
	);
[DllImport("user32")]
public static extern IntPtr GetDC(
	IntPtr hwnd
	);
 
IntPtr hdc;
 
//取得目前執行視窗的裝置環境代碼(Device Context)
hdc = GetDC(this.Handle);
 
int rtvl;
 
//設定字元間距為10
rtvl = SetTextCharacterExtra(hdc, 10);

發表迴響