EnumChildWindows和WindowFromPoint的问题,熟悉枚举子窗体的老师们进来指导一下.
我是个VB新手,目前正自学到句柄这一块的知识,对这个问题,我研究了好多天了,也看了不少的网页.一点也没弄明白.
问题1:WindowFromPoint 是不是API函数?它的作用是什么.和EnumChildWindows有什么关系?
问题2:EnumChildWindows 它的原理是什么,怎么用它来枚举遍历.
以下是拜读本站一位老师 online(龙卷风) 的代码,太多都没看明白,希望能有师傅能(通俗点)的讲解一下,不胜感激:
使用EnumChildWindows
Private Declare Function FindWindow Lib "user32.dll " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim twnd As Long
twnd = FindWindow(vbNullString, "测试enabled ")
EnumChildWindows twnd, AddressOf EnumChildProc, ByVal 0& '--本人问:这一句是EnumChildWindows函数的用法吗 作用是什么呢,得到什么值出来?
End Sub
模块
Option Explicit
Declare Function GetClassName Lib "user32 " Alias "GetClassNameA " (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32 " (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long '----本人问: EnumChildProc 是不是AIP函数呢,他为什么要声明,他的作用是什么,原理是什么,和 EnumChildWindows 有什么关系.
Dim lpClassName As String
Dim retval As Long
Dim mname As String
Dim i As Integer
lpClassName = Space(256)
retval = GetClassName(hwnd, lpClassName, 256)
i = InStr(1, lpClassName, Chr(0)) '--本人问,这句的意思是什么,以
前只用过 instr ("12345","1") 返回1. 而这句里面怎么有三个参数在里面.
mname = Left(lpClassName, i - 1)
Form1.List1.AddItem hwnd & " " & mname
EnumChildProc = 1 '==这句又是什么意思啊 怎么 (EnumChildProc = 1)?
End Function
我是新手,分不多额.
[解决办法]
我专学的API那个值看了点,好像跟多文档多线程,额,挺后期的,你上百度上面搜索下那个函数名字,有百度文库,还有SOSO文库的,我都是不懂就上网问问的
[解决办法]
使用EnumChildWindows
Private Declare Function FindWindow Lib "user32.dll " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim twnd As Long
twnd = FindWindow(vbNullString, "测试enabled ")
EnumChildWindows twnd, AddressOf EnumChildProc, ByVal 0& '--本人问:这一句是EnumChildWindows函数的用法吗 作用是什么呢,得到什么值出来?
'含义是:EnumChildWindows说:我要去找twnd的子窗口,找到后[color=#99CC00]EnumChildProc你来瞧瞧
'--EnumChildProc叫回调函数,下面模块中定义的[/color]
End Sub
模块
Option Explicit
Declare Function GetClassName Lib "user32 " Alias "GetClassNameA " (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32 " (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long '----本人问: EnumChildProc 是不是AIP函数呢,他为什么要声明,他的作用是什么,原理是什么,和 EnumChildWindows 有什么关系.
'[color=#008000]EnumChildProc 处理EnumChildWindows找到的窗口 [/color]
Dim lpClassName As String
Dim retval As Long
Dim mname As String
Dim i As Integer
lpClassName = Space(256)
retval = GetClassName(hwnd, lpClassName, 256)
i = InStr(1, lpClassName, Chr(0)) '--本人问,这句的意思是什么,以
前只用过 instr ("12345","1") 返回1. 而这句里面怎么有三个参数在里面.
第一个参数表示从什么位置开始找,不指定就从第一个开始
mname = Left(lpClassName, i - 1)
Form1.List1.AddItem hwnd & " " & mname
EnumChildProc = 1 '==这句又是什么意思啊 怎么 (EnumChildProc = 1)?
[color=#008000]EnumChildProc处理完了一个窗口,他告诉喊它的EnumChildWindows继续找下一个---EnumChildProc = 0,不找了![/color]
End Function
[/code]