enumchild.bas

来自「调用外部程序作为自已的子程序,其中调用了API函数」· BAS 代码 · 共 42 行

BAS
42
字号
Attribute VB_Name = "Module1"
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

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 Const WM_CLOSE = &H10


Public g_hChildWnd As Long
Public g_lrtnVal As Long
Public g_strTitle As String
Public g_titleLen As Long
Public g_strTmp As String
Public g_strAppPath As String
Public g_strAppName As String



Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    EnumChildProc = True
    '方法一
    'g_strTmp = Space(256)
    'GetWindowText hwnd, g_strTmp, 256
    'g_strTmp = Left(g_strTmp, InStr(1, g_strTmp, Chr(0)))
    '方法二
    g_titleLen = GetWindowTextLength(hwnd) + 1
    g_strTmp = Space(g_titleLen)
    GetWindowText hwnd, g_strTmp, g_titleLen
    'Debug.Print g_strTmp, g_strTitle, InStr(1, g_strTmp, g_strTitle)
    If Len(Trim(g_strTmp)) <> 0 And InStr(1, g_strTmp, g_strTitle) <> 0 Then
        g_hChildWnd = hwnd
        EnumChildProc = False
    End If
End Function

Public Function CloseChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    CloseChildProc = True
    Call SendMessage(hwnd, WM_CLOSE, ByVal &O0, ByVal &O0)
End Function

⌨️ 快捷键说明

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