module1.bas

来自「灰色按钮激活」· BAS 代码 · 共 45 行

BAS
45
字号
Attribute VB_Name = "Module1"

Public Declare Function ChildWindowFromPoint Lib "user32" (ByVal hwnd As Long, ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long
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 IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long

Public Const HWND_TOPMOST = -1
Public icount As Integer

'
Function GetText(Ihwnd As Long) As String
    Dim Textlen As Long
    Dim Text As String

    Textlen = SendMessage(Ihwnd, WM_GETTEXTLENGTH, 0, 0)
    If Textlen = 0 Then
        GetText = "(No text)"
        Exit Function
    End If
    Textlen = Textlen + 1
    Text = Space$(Textlen)
    Textlen = SendMessage(Ihwnd, WM_GETTEXT, Textlen, ByVal Text)
    GetText = Left$(Text, Textlen)

End Function

Public Function WndEnumChildProc(ByVal hwnd As Long, ByVal lParam As ListBox) As Long
    Dim bRet As Long
    Dim myStr As String * 50
    
    bRet = GetClassName(hwnd, myStr, 50)
    If IsWindowEnabled(hwnd) = 0 Then EnableWindow hwnd, 1
    
    lParam.AddItem Str(hwnd) & "--" & Left(myStr, 20) & "--" & GetText(hwnd)
    icount = icount + 1
    WndEnumChildProc = 1
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?