怎么样能得到任务管理器中(Ctrl+alt+del出来的那个)所有任务的窗体句柄
也就是任务栏上所有现在运行的程序,我想得到它们窗体的句柄,该怎么做?

解决方案 »

  1.   

    classname:#32770
    caption:Windows 任务管理器
    使用findwindow
      

  2.   

    Private Sub CWindow_Click()
      Dim l As Long
      
      List1.Clear
      '遍历所有的窗口
      l = EnumWindows(AddressOf EnumWindowsProc, 0)
    End SubDeclare 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
      Dim i As Long
      
      l = GetWindowText(hwnd, astr, Len(astr)) 
      If InStr(astr, " ") > 1 Then
        i = InStr(1, astr, Chr(0))
        astr = LCase(Left(astr, i - 1))
        Form1.List1.AddItem Trim(astr) & hwnd
      End If
      EnumWindowsProc = True
    End Function