VB.NET EnumChildWindows 问题
额 新手初学 API 遇到一些问题
EnumChildWindows 和 回调 函数EnumChildProc 不会用
我参考网上的一些例子 总是在 addressof 上面出错 说不是委托类型啥的
请高手写一个VB.NET 的例子 一个按钮 一个文本框就可以
遍历子窗口句柄 并显示出来
[最优解释]
<DllImport("User32.dll", EntryPoint := "FindWindow")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint := "FindWindowEx")> _
Private Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
End Function
<DllImport("User32.dll", EntryPoint := "SendMessage")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As Integer
End Function
Const WM_GETTEXT As Integer = &Hd
Const WM_SETTEXT As Integer = &Hc
Const WM_CLICK As Integer = &Hf5
Dim retval As Integer = 0
Dim lpszParentWindow As String = "Form1"
Dim lpszClass As String = ""
Dim text As String = ""
Dim ParenthWnd As New IntPtr(0)
Dim EdithWnd As New IntPtr(0)
ParenthWnd = FindWindow(Nothing, lpszParentWindow)
If Not ParenthWnd.Equals(IntPtr.Zero) Then
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "")
If Not EdithWnd.Equals(IntPtr.Zero) Then
text = ""
SendMessage(EdithWnd, WM_SETTEXT, DirectCast(0, IntPtr), text)
End If
End If
[其他解释]
把EnumChildProc放在模块里
[其他解释]
求详细代码
[其他解释]
自己UP
[其他解释]
帮顶
[其他解释]
自己UP
[其他解释]
UP
[其他解释]
VB.NET调用 EnumChildWindows 的时候,和VB确实有点区别,刚好我也遇到这个情况,需要用【委托类型】(Delegate)来解决:
Private Delegate Function EnumChildProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
Private Declare Unicode Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildProc, ByVal lParam As Integer) As Boolean
Private Function EnumFunc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
'hWnd:子窗口的窗口句柄。
'lParam:调用 EnumChildWindows 函数时传递的参数。
'Return True/False:要继续枚举返回 True;要停止枚举返回 False。
End Function
EnumChildWindows(Me.Handle, AddressOf EnumFunc, 0)