【开源项目】花密(Flower Password)VB版之窗体控件枚举模块

'*****************************************************************
' Copyright (c) 2011-2012 FlowerPassword.com All rights reserved.
'      Author : xLsDg @ Xiao Lu Software Development Group
'        Blog : http://hi.baidu.com/xlsdg
'          QQ : 4 4 7 4 0 5 7 4 0
'     Version : 1 . 0 . 0 . 0
'        Date : 2 0 1 2 / 0 4 / 0 7
' Description :
'     History :
'*****************************************************************
Option Explicit

Private Declare Function SendMessage _
                Lib "user32" _
                Alias "SendMessageA" (ByVal hwnd As Long, _
                                      ByVal wMsg As Long, _
                                      ByVal wParam As Long, _
                                      lParam As Any) As Long

Private Declare Function GetWindow _
                Lib "user32" (ByVal hwnd As Long, _
                              ByVal wCmd As Long) As Long

Private Declare Function GetClassName _
                Lib "user32" _
                Alias "GetClassNameA" (ByVal hwnd As Long, _
                                       ByVal lpClassName As String, _
                                       ByVal nMaxCount As Long) As Long

Private Const GW_CHILD = 5

Private Const GW_HWNDNEXT = 2

Private Const WM_GETTEXT = &HD

Private Const WM_GETTEXTLENGTH = &HE

' Return information about this window.
Public Function WindowInfo(ByVal window_hwnd As Long, _
                           ByVal class_name As String) As String

    Static txt As String

    Dim buf    As String

    Dim buflen As Long

    ' Get the class name.
    buflen = 256
    buf = Space$(buflen - 1)
    buflen = GetClassName(window_hwnd, buf, buflen)
    buf = Left$(buf, buflen)

    If LCase$(buf) = class_name Then
        ' Associated text.
        txt = WindowText(window_hwnd)
        Exit Function

    End If

    Dim child_hwnd As Long

    Dim children   As Collection

    ' Make a list of the child windows.
    Set children = New Collection
    child_hwnd = GetWindow(window_hwnd, GW_CHILD)

    Do While child_hwnd <> 0
        children.Add child_hwnd
        child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
    Loop

    Dim i As Integer

    ' Get information on the child windows.
    For i = 1 To children.count
        WindowInfo children(i), class_name
    Next i

    WindowInfo = txt

End Function

' Return the text associated with the window.
Public Function WindowText(ByVal window_hwnd As Long) As String

    Dim txtlen As Long

    Dim txt    As String

    WindowText = vbNullString

    If window_hwnd = 0 Then Exit Function
    txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)

    If txtlen = 0 Then Exit Function
    txtlen = txtlen + 1
    txt = Space$(txtlen)
    txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
    WindowText = Left$(txt, txtlen)

End Function



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值