Home » Windows API

SetWindowText

說明:
SetWindowText 函式可設定指定視窗代碼(Handle)的標題列文字,或是控制項裡面的文字內容


引用函式庫:
User32


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


函式原型:

Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" ( _
    ByVal hwnd As Long, _
    ByVal lpString As String _
    ) As Long



參數型態及說明:
hwndLong 要設定文字的視窗代碼(Handle)
lpStringString 要設定的文字

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

.NET Framework API:
System.Windows.Forms.Form.Text


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
9
10
'VB的宣告
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" ( _
	ByVal hwnd As Long, _
	ByVal lpString As String _
	) As Long
 
Dim rtvl As Long
 
'設定目前執行視窗(Handle)的標題列為-SetWindowText
rtvl = SetWindowText(Form1.hwnd, "SetWindowText")

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
9
10
'RB的宣告
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" ( _
	hwnd As Integer, _
	lpString As CString _
	) As Integer
 
Dim rtvl As Integer
 
'設定目前執行視窗(Handle)的標題列為-SetWindowText
rtvl = SetWindowText(Window1.WinHWND, "SetWindowText")

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
11
12
'VB.NET的宣告
<DllImport("user32.dll")> _
Shared Function SetWindowText( _
	ByVal hwnd As IntPtr, _
	ByVal lpString As String _
	) As Integer
End Function
 
Dim rtvl As Integer
 
'設定目前執行視窗(Handle)的標題列為-SetWindowText
rtvl = SetWindowText(Me.Handle, "SetWindowText")

C#範例:

1
2
3
4
5
6
7
8
9
10
11
//C#的宣告
[DllImport("user32")]
public static extern int SetWindowText(
	IntPtr hwnd, 
	string lpString
	);
 
int rtvl;
 
//設定目前執行視窗(Handle)的標題列為-SetWindowText
rtvl = SetWindowText(this.Handle, "SetWindowText");

發表迴響