以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于ShowAppWindow  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=75619)

--  作者:lswwsl
--  发布时间:2015/10/11 17:25:00
--  关于ShowAppWindow
如题,请问如何获取QQ对话窗口的标题以方便使用ShowAppWindow最小化?是QQ好友聊天窗口而非QQ主程序。
--  作者:大红袍
--  发布时间:2015/10/11 19:48:00
--  

汗,测试了一下,没有完善的方法,只能大致获取,参考代码

 

全局代码

 

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Integer) As Integer

Public Delegate Function   EnumWindowsProc(ByVal   hwnd   As   Integer,   ByVal   lParam   As   Integer)   As   Boolean

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer

<DllImport("user32.dll")> _
Public Function GetWindowTextLength(hWnd As Integer) As Integer
End Function

Public Function EnumWindowsProcCallBack(ByVal   hwnd   As   Integer,   ByVal   lParam   As   Integer)   As   Boolean
      Return Functions.Execute("EnumWindowsProcCallBack", hwnd, lparam)
End   Function

<DllImport("user32.dll")> _
Public Function GetWindowThreadProcessId(hWnd As Integer, ByRef pid As Integer) As Integer
End Function

 

内部函数 EnumWindowsProcCallBack

 

Dim hwnd As Integer = args(0)

Dim len As Integer = GetWindowTextLength(hWnd) + 1
Dim s As new StringBuilder(len)
If GetWindowText(hwnd, s, len ) > 0 Then
    Dim pid As Integer
    GetWindowThreadProcessId(hwnd, pid)
    If vars("ls").contains(pid) Then
        output.show(s.Tostring)
    End If
End If
Return True

 

调用代码

 

vars("ls") = new List(Of String)
Dim ps As  System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("QQ")
For Each p As System.Diagnostics.Process In ps
    vars("ls").add(p.id)
Next

Dim CallBack As New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
EnumWindows(CallBack, 0)