枚举所有窗口句柄问题,求教
悬赏分:50 - 离问题结束还有 14 天 23 小时
我需要实现:枚举所有存在的窗口,发现窗口标题[含有]“123”,就把该窗口的句柄输出到Text1中,但是不知道代码某处出了错误,一直取不出,请高手帮我修改一下 O(∩_∩)O谢谢 小生有礼~ 新手求教,希望能给出修改后的源码 O(∩_∩)O谢谢
Private Sub Command2_Click() Dim l As Long l = EnumWindows(AddressOf EnumWindowsProc, 0) Text1.Text = xx End Sub
以下代码我存在独立的Module里的:
Module: Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim dd As String * 255
Dim a As String a = "123" RetVal = GetWindowText(hwnd, dd, 255)
If c = InStr(dd, a) Then
xx = dd
Else
End If
End Function
悬赏分:50 - 离问题结束还有 14 天 23 小时
我需要实现:枚举所有存在的窗口,发现窗口标题[含有]“123”,就把该窗口的句柄输出到Text1中,但是不知道代码某处出了错误,一直取不出,请高手帮我修改一下 O(∩_∩)O谢谢 小生有礼~ 新手求教,希望能给出修改后的源码 O(∩_∩)O谢谢
Private Sub Command2_Click() Dim l As Long l = EnumWindows(AddressOf EnumWindowsProc, 0) Text1.Text = xx End Sub
以下代码我存在独立的Module里的:
Module: Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim dd As String * 255
Dim a As String a = "123" RetVal = GetWindowText(hwnd, dd, 255)
If c = InStr(dd, a) Then
xx = dd
Else
End If
End Function
解决方案 »
- VB同时链接本地和远程服务器
- 求一个解决方法?100分★★★★★★
- 请各位大虾帮忙————急!
- 关于listbox控件
- 怎么样自动添加编号
- 控件的版权问题
- 如何在,ACCESS 中用VBA取得当前的路径
- vb 6.0 连接sql server express 2005
- 求 VB6 Enterprise edition Product ID to Download Visual Studio® Installer 1.0
- 关于时间比较的问题
- 用VB6给硬件做人机界面,要学习哪个方面?
- 请问VSFLEXGRID如何绑定显示“shape() append() relate... to....”结构的数据分层显示啊?
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim dd As String * 255
Dim a As String a = "123" RetVal = GetWindowText(hwnd, dd, 255)
If c = InStr(dd, a) Then
xx = dd
Else
End If
EnumWindowsProc=1
End Function
Command2之后 还是没办法把xx输出到TEXT1 再次求教
Dim RetVal As Long
Dim dd As String * 255
Dim a As String a = "123" RetVal = GetWindowText(hwnd, dd, 255)
If c = InStr(dd, a) Then
form1.text1.text = dd
Else
End If
EnumWindowsProc=1
End Function
Dim RetVal As Long
Dim dd As String * 255
Dim a As String a = "123" RetVal = GetWindowText(hwnd, dd, 255)
If 0<> InStr(dd, a) Then
form1.text1.text = form1.text1.text & vbcrlf & dd
Else
End If
EnumWindowsProc=1
End Function
Text1.Text = "" l = EnumWindows(AddressOf EnumWindowsProc, ByVal 0&) 'Text1.Text = xxEnd Sub
标准模块:Option ExplicitPublic Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As LongPublic Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim CaptionLength As Long
Dim WindowCaption As String
Dim a As String
a = "123"
CaptionLength = GetWindowTextLength(hwnd) '取得顶级窗口标题长度
WindowCaption = Space(CaptionLength) '设置窗口标题长度
RetVal = GetWindowText(hwnd, WindowCaption, CaptionLength + 1)
'WindowCaption = Left(WindowCaption, InStr(WindowCaption, Chr(0)) - 1) '去掉尾部空格
Debug.Print WindowCaption
If InStr(WindowCaption, a) > 0 Then
Form1.Text1.Text = Form1.Text1.Text & WindowCaption & vbCrLf
Else
'''''''''''''''''
End If
EnumWindowsProc = 1 'True
End Function