因为在找一个窗体时,标题太长了,而且后半部会有变化,能不能只取前多少字符这样来找呢?或者有其他什么方法没有呢?先谢谢了...
解决方案 »
- 关于“类型不匹配”的错误
- 【新手】关于两个listbox
- 怎样做出带有水平滚动条的ListBox?
- unload me 前的等待问题,简单,立马给分!!!
- 初学的问题,各位大哥请帮帮忙
- vb6做的安装包,xp系统中运行到setup1.exe时提示“无法找到组件”
- 100分 很容易拿到吗?
- 对不起....我悔过.我公开道歉.回复:"To:jessezappy(晶晶) 求你不要乱往人家的帖子上粘东西,好吗老兄"!!!!!再次请求大家不要跟贴,以便我自己删除这贴!!!!!!******
- 我想让form1改变尺寸到一定大小时不改变!怎写代码?!急
- TreeView1_DblClick()如何获取点击节点所属的第三级节点
- 离线问题
- 请教大虾datagrid里面的数据怎样才能导入到excel中去
Option ExplicitPrivate Sub Command1_Click()
EnumWindows AddressOf EnumProc, 0 '枚举窗口列表中的所有父窗口
End Sub=======================模块======================Option ExplicitDeclare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDim buf As String
Dim title As StringPublic Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean '遍查主窗口
Dim buf As String * 1024
Dim length As Long length = GetWindowText(app_hwnd, buf, Len(buf))
title = Left$(buf, length) If Left(title, 2) = "QQ" Then '判断是否为 OICQ 窗口
MsgBox "QQ"
End If
EnumProc = 1
End Function
提供一种方法:
Option Explicit
Private 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
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim CptWnd() As String'获取含指定字符指定窗口句柄
Public Sub mGetWindow(ByVal cName As String, ByRef fText As String)
Dim myStr As String * 255
Dim strLen As String
Dim bWnd As Long
Dim bWndback As Long
Dim i As Long
ReDim CptWnd(1, 0)
strLen = Len(myStr)
bWndback = 0: i = 0
Do
'获取子窗口标志
bWnd = FindWindowEx(0, bWndback, cName, vbNullString)
If bWnd <> 0 Then
'获取子窗口标题
GetWindowText bWnd, myStr, strLen
myStr = Trim(myStr)
If InStr(myStr, fText) Then
ReDim Preserve CptWnd(1, i)
CptWnd(0, i) = myStr
CptWnd(1, i) = bWnd
Me.Print bWnd
i = i + 1
'Exit Do
End If
Else
Exit Do
End If
bWndback = bWnd
Loop
End SubPrivate Sub Form_Load()
Dim i As Long
mGetWindow vbNullString, "Visual"
For i = 0 To UBound(CptWnd, 2) ' - 1
Debug.Print CptWnd(1, i) & " " & CptWnd(0, i)
Next
End Sub结束语,这种方法可以列出标题中喊有指定字符(这里是"Visual")的窗体(包括子窗,“控件”),也可以列出具有指定类名的。如果不想要子窗,可以把FINDWINDOWSEX换成FINDWINDOW。