根据子句柄取得主窗体句柄
0 Reply , Posted in 程序代码 on 2016 08, 2016
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
List1.Clear
1:
Text2 = GetParent(Text1) 'text1为子句柄,text2为上一层控件的句柄
If Text2 <> 0 Then '如果不是主窗体句柄
List1.AddItem Text2
Text1 = Text2
Text2 = ""
GoTo 1: '则跳转到标签1:处
End If
End Sub
'---------------------根据子句柄取得主窗体句柄---------------------
'原理:根据子句柄获得上一层控件的句柄,如果上一层句柄为0,则这一层句柄就是主窗体句柄
'Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
'Private Sub Command1_Click()
'List1.Clear
'List1.AddItem GetParent(Text1) 'text1为子句柄
'End Sub