vb枚举窗口模块
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
S = Left(S, InStr(S, Chr(0)) - 1)
If InStr(1, S, sA) <= 0 Then
Found = False
EnumWindowsProc = True '返回真继续枚举。
Else
Found = True
FoundWindowHwnd = hwnd
Public Property Let Found(ByRef vData As Boolean)
mVarFound = vData
End Property
Public Property Get Found() As Boolean
Found = mVarFound
End Property
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private mVarWindowCaptionString As String '需要比较的值
Private mVarFound As Boolean '是否找到指定的窗口
Private mVarFoundWindowHwnd As Long '找到窗口的句柄
Public Property Let FoundWindowHwnd(ByRef vData As Long)
mVarFoundWindowHwnd = vData
End Property
Public Property Get FoundWindowHwnd() As Long
FoundWindowHwnd = mVarFoundWindowHwnd
End Property
'EnumWindows枚举所有屏幕上的顶层窗口,并将窗口句柄传送给应用程序定义的回调函数。回调函数返回FALSE将停止枚举,否则EnumWindows函数继续到所有顶层窗口枚举完为止。
Declare Function enumwindows Lib "user32" Alias "EnumWindows" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
If Found Then
FindWindows = FoundWindowHwnd '这里是找到的窗口句柄
Else
Exit Function
End If
End Function
Public Property Let WindowCaptionString(ByRef vData As String)
mVarWindowCaptionString = vData
End Property
Public rty Get WindowCaptionString() As String
'2 调用说明,直接在程序中使用FindWindows函数来找到窗口句柄;如果需要连续处理多个
’窗口,请自己修改EnumWindowsProc函数,在里面添加处理代码。
'*******************************************************************************************
'*******************************************************************************************
'模块名称 EnumWindows
'AUTHOR Morn Woo 20120112
’1. 把下面的模块存储为EnumWindows.bas,并加入到你的工程中
Dim sA
Dim S As String
EnumWindowsProc = False
sA = Trim(WindowCaptionString)
If Trim(sA) = "" Then Exit Function
S = String(80, Chr(0))
Call GetWindowText(hwnd, S, 80)
WindowCaptionString = mVarWindowCaptionString
End Property
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
End If
End Function
Public Function FindWindows(ByVal sCaption As String) As Long '返回找到的窗口句柄
enumwindows AddressOf EnumWindowsProc, 0&
WindowCaptionString = sCaption
If InStr(1, S, sA) <= 0 Then
Found = False
EnumWindowsProc = True '返回真继续枚举。
Else
Found = True
FoundWindowHwnd = hwnd
Public Property Let Found(ByRef vData As Boolean)
mVarFound = vData
End Property
Public Property Get Found() As Boolean
Found = mVarFound
End Property
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private mVarWindowCaptionString As String '需要比较的值
Private mVarFound As Boolean '是否找到指定的窗口
Private mVarFoundWindowHwnd As Long '找到窗口的句柄
Public Property Let FoundWindowHwnd(ByRef vData As Long)
mVarFoundWindowHwnd = vData
End Property
Public Property Get FoundWindowHwnd() As Long
FoundWindowHwnd = mVarFoundWindowHwnd
End Property
'EnumWindows枚举所有屏幕上的顶层窗口,并将窗口句柄传送给应用程序定义的回调函数。回调函数返回FALSE将停止枚举,否则EnumWindows函数继续到所有顶层窗口枚举完为止。
Declare Function enumwindows Lib "user32" Alias "EnumWindows" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
If Found Then
FindWindows = FoundWindowHwnd '这里是找到的窗口句柄
Else
Exit Function
End If
End Function
Public Property Let WindowCaptionString(ByRef vData As String)
mVarWindowCaptionString = vData
End Property
Public rty Get WindowCaptionString() As String
'2 调用说明,直接在程序中使用FindWindows函数来找到窗口句柄;如果需要连续处理多个
’窗口,请自己修改EnumWindowsProc函数,在里面添加处理代码。
'*******************************************************************************************
'*******************************************************************************************
'模块名称 EnumWindows
'AUTHOR Morn Woo 20120112
’1. 把下面的模块存储为EnumWindows.bas,并加入到你的工程中
Dim sA
Dim S As String
EnumWindowsProc = False
sA = Trim(WindowCaptionString)
If Trim(sA) = "" Then Exit Function
S = String(80, Chr(0))
Call GetWindowText(hwnd, S, 80)
WindowCaptionString = mVarWindowCaptionString
End Property
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
End If
End Function
Public Function FindWindows(ByVal sCaption As String) As Long '返回找到的窗口句柄
enumwindows AddressOf EnumWindowsProc, 0&
WindowCaptionString = sCaption