用过二楼介绍的代码了,但是好象不能加载程序,不知道出了什么问题?
1、建立一个标准工程
2、添加一个标准模块
3、再工程里添加一个listbox列表框
4、添加2个command 1个timer
将下面代码复制到,标准模块内
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'该函数是EnumWindows的回调函数,EnumWindows函数将遍历的窗口句柄传递到hwnd参数中
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim astr As String * 256
Dim L As Long
L = GetWindowText(hwnd, astr, Len(astr)) '得到窗口的标题
If InStr(astr, " ") > 1 Then
If InStr(LCase(astr), LCase("你要查找的标题-关键字")) > 0 And InStr(LCase(astr), LCase(" - ")) = 0 Then '将关键字换成你的就行了
Form1.Combo1.AddItem Left(astr, InStr(1, astr, Chr(0)) - 1) & vbCrLf & hwnd
End If
End If
EnumWindowsProc = True
End Function
5、将下面代码复制到form1模块内(窗体模块内)
Option Explicit
Private Sub Command1_Click()
Timer1.Enabled = True '启动开查找时钟
End Sub
Private Sub command2_click()
Timer1.Enabled = False '停止开始查找时钟
End Sub
Private Sub Timer1_Timer()
Call RefreshList
End Sub
Sub RefreshList()
On Error Resume Next
Dim L As Long
Dim k As Long
k = Combo1.ListIndex
Combo1.Clear
L = EnumWindows(AddressOf EnumWindowsProc, 0)
If Combo1.ListCount > 0 Then Combo1.ListIndex = k
End Sub
6、将查找关键字换成你要查找的关键字,运行即可,获得窗体名称与句柄。
这些代码仅仅只能在combo控件中显示找到了需要的程序而不是加载这个程序.谢谢望能给予帮助