Home » Windows API

GetParent

說明:
GetParent 函式可取得指定視窗的父視窗代碼(Handle)


引用函式庫:
User32


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


函式原型:

Declare Function GetParent Lib "user32" Alias "GetParent" ( _
    ByVal hwnd As Long _
    ) As Long



參數型態及說明:
hwndLong 要指定視窗的代碼(Handle)

回傳值:
Long 呼叫成功的話,將會回傳父視窗代碼(Handle);若呼叫失敗的話,則回傳 NULL

.NET Framework API:
System.Windows.Forms.Form.FindForm
System.Windows.Forms.Form.Parent


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
9
'VB的宣告
Private Declare Function GetParent Lib "user32" ( _
	ByVal hwnd As Long _
	) As Long
 
Dim hwnd As Long
 
'取得目前執行程式的父視窗代碼(Handle)
hwnd = GetParent(Form1.hwnd)

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
9
'RB的宣告
Declare Function GetParent Lib "user32" ( _
	hwnd As Integer _
	) As Integer
 
Dim hwnd As Integer
 
'取得目前執行程式的父視窗代碼(Handle)
hwnd = GetParent(Window1.WinHWND)

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
11
'VB.NET的宣告
<DllImport("user32.dll")> _
Shared Function GetParent( _
	ByVal hwnd As IntPtr _
	) As IntPtr
End Function
 
Dim hwnd As IntPtr
 
'取得目前執行程式的父視窗代碼(Handle)
hwnd = GetParent(Me.Handle)

C#範例:

1
2
3
4
5
6
7
8
9
10
//C#的宣告
[DllImport("user32")]
public static extern IntPtr GetParent(
	IntPtr hwnd
	);
 
IntPtr hwnd;
 
//取得目前執行程式的父視窗代碼(Handle)
hwnd = GetParent(this.Handle);

發表迴響