M
mazunini
Unregistered / Unconfirmed
GUEST, unregistred user!
有原代码是关于“VB获取正在系统中运行的窗口标题”问题的,代码如下:
模块中:
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
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
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Sub FindTitle()
'查找桌面上的所有窗口标题
Dim currwnd As Integer
Combo1.Clear
currwnd = GetWindow(hwnd, GW - HWNDFIRST)
While currwnd <> 0
length = GetWindowTextLength(currwnd)
listitem = Space(length + 1)
length = GetWindowText(currwnd, listitem, length + 1)
If length > 0 then
Combo1.Addltem listitem
End If
currwnd = GetWindow(currwnd, GW_HWNDNEXT)
If Combl1.ListCount > 0 then
Combo1.Text = Combol.List(0)
Combo1.ListIndex = 0
else
MsgBox "没有发现可活动的窗口", 16, "活动"
End If
Wend
End Sub
Sub Sift()
'测试窗口能否活动
i = 0
Combo2.Clear
Do
On Local Error Resume Next
AppActivate Combo1.List(i)
If Err = 0 then
Combo2.AddItem Combo1.List(i)
End If
i = i + 1
Loop
i = Combo1.ListCount - 1
AppActivate Form1.Caption
If Combo2.ListCount > 0 then
Combo2.Text = Combo2.List(0)
Combo2.ListIndex = 0
else
MsgBox "没有发现可活动窗口", 16, "活动"
End If
End Sub
form1中代码:
Private Sub Command1_Click()
F = Combo2.Text
On Local Error Resume Next
AppActivate F
End Sub
Private Sub Command2_Click()
Call FindTitle
Call Sift
End Sub
Private Sub Form_Load()
Form1.Show '首先将本窗体显示出来,否则查找出的窗体标题没有本身
MsgBox "开始查找窗口标题"
Call FindTitle
Call Sift
End Sub
在form1中添加两个combo和command控件!该段程序我始终调不出来!在
combo1.clear和combo2.clear这两句话上报错,注销不用后运行死机,请问
该段程序哪里有问题??不做大的修改,如何调试??
模块中:
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
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
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Sub FindTitle()
'查找桌面上的所有窗口标题
Dim currwnd As Integer
Combo1.Clear
currwnd = GetWindow(hwnd, GW - HWNDFIRST)
While currwnd <> 0
length = GetWindowTextLength(currwnd)
listitem = Space(length + 1)
length = GetWindowText(currwnd, listitem, length + 1)
If length > 0 then
Combo1.Addltem listitem
End If
currwnd = GetWindow(currwnd, GW_HWNDNEXT)
If Combl1.ListCount > 0 then
Combo1.Text = Combol.List(0)
Combo1.ListIndex = 0
else
MsgBox "没有发现可活动的窗口", 16, "活动"
End If
Wend
End Sub
Sub Sift()
'测试窗口能否活动
i = 0
Combo2.Clear
Do
On Local Error Resume Next
AppActivate Combo1.List(i)
If Err = 0 then
Combo2.AddItem Combo1.List(i)
End If
i = i + 1
Loop
i = Combo1.ListCount - 1
AppActivate Form1.Caption
If Combo2.ListCount > 0 then
Combo2.Text = Combo2.List(0)
Combo2.ListIndex = 0
else
MsgBox "没有发现可活动窗口", 16, "活动"
End If
End Sub
form1中代码:
Private Sub Command1_Click()
F = Combo2.Text
On Local Error Resume Next
AppActivate F
End Sub
Private Sub Command2_Click()
Call FindTitle
Call Sift
End Sub
Private Sub Form_Load()
Form1.Show '首先将本窗体显示出来,否则查找出的窗体标题没有本身
MsgBox "开始查找窗口标题"
Call FindTitle
Call Sift
End Sub
在form1中添加两个combo和command控件!该段程序我始终调不出来!在
combo1.clear和combo2.clear这两句话上报错,注销不用后运行死机,请问
该段程序哪里有问题??不做大的修改,如何调试??