|
楼主 |
发表于 2014-4-17 23:44
|
显示全部楼层
本帖最后由 cbtaja 于 2014-4-18 15:27 编辑
- Public Declare Function getClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
- Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
- Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long '获得窗口的标题(对于控件,则是其Caption)
- Public Function getClasName(ByVal Hwnd As Long) '获得窗口的类名
- Dim lpClassName As String * 256, retval As Long
- retval = getClassName(Hwnd, lpClassName, 255)
- If retval <> 0 Then getClasName = Left$(lpClassName, retval)
- End Function
- Public Function GetWindwowCaption(ByVal Hwnd As Long) As String '获得窗口或控件的标题(如果它们存在)
- Dim cnt As Long, rttitle As String * 256
- cnt = GetWindowText(Hwnd, rttitle, 255)
- If cnt <> 0 Then GetWindwowCaption = Left$(rttitle, cnt)
- End Function
- Public Function EnumChildWind(ByVal hwndParent As Long) As Long '枚举子窗口并返回子窗口的总个数(为自定义函数)
- EnumChildWind = -1
- Do
- hwdChild = FindWindowEx(hwndParent, hwdChild, vbNullString, vbNullString) '水平滚动条的句柄
- TheClassName = getClasName(hwdChild)
- rttitle = GetWindwowCaption(hwdChild)
- Debug.Print hwdChild, TheClassName, rttitle '输出子窗口的句柄、类名以及窗口标题(后两项需调用其它API函数及相应自定义函数)
- EnumChildWind = EnumChildWind + 1
- Loop Until hwdChild = 0
- End Function
- Sub 枚举EXCEL活动窗口及子窗口()
- Dim hWndWin As Long
- Dim rttitle As String, TheClassName As String
-
- hWndWin = Application.Hwnd '得到EXCEL主程序的句柄。直接从Application属性中取得
- rttitle = GetWindwowCaption(hWndWin): Debug.Print rttitle
-
-
- hWndWin = FindWindowEx(hWndWin, 0&, "XLDESK", vbNullString) '找到EXCEL程序的工作区窗口的句柄
- rttitle = GetWindwowCaption(hWndWin): Debug.Print rttitle '
-
- hWndWin = FindWindowEx(hWndWin, 0&, vbNullString, vbNullString) '找到活动工作表窗口的句柄
- TheClassName = getClasName(hWndWin) '得到相应的类名
- rttitle = GetWindwowCaption(hWndWin) '
- Debug.Print hWndWin, TheClassName, rttitle '在立即窗口输出活动工作表窗口的句柄、类名、窗口标题
-
- Call EnumChildWind(hWndWin) ' 枚举活动工作表窗口的子窗口
- End Sub
复制代码 http://club.excelhome.net/forum.php?mod=attachment&aid=MTU3NzM3MXxjNzQ4ZDlhMHwxMzk3ODA1ODQ2fDkxODkxMnwxMTEzNjQz |
评分
-
3
查看全部评分
-
|