Seite 1 von 2

EnumAllWindows V3

Verfasst: 24.02.2005 00:08
von NicTheQuick
Das Programm listet alle sichtbaren und unsichtbaren Fenster auf und zeigt zu den einzelnen Fenstern Informationen an und liefert gleichzeitig die dafür notwendigen APIs mit und stellt deren Anwendung dar.
Nützlich für allerlei kleine Dinge oder einfach nur mal um zu staunen, was sich im Hintergrund von Windows noch alles verbirgt.

Das Programm hatte ich schon im alten Forum gepostet, aber Deeem2031 hate schon eine kleine Erweiterung eingebaut, die er sicherlich nach meinem Post vorführen wird. Ansonsten sind nur so kleine Funktionen wie [c]GadgetID()[/c] durch [c]IsGadget()[/c] ersetzt worden.

Code: Alles auswählen

Structure Window
  Childs.l
  Rekursion.l
  
  ;Window
  handle.l
  process.l
  Name.s
  Class.s
EndStructure

#PROCESS_ALL_ACCESS = $FFF

#BufferSize = 2048

Global LF.s
LF = Chr(13) + Chr(10)

Declare RefreshList(Modus.l)
Declare AddWindow(*Tmp.Window)
Declare EnumAllWindows()
Declare EnumAllSubChilds(handle.l, lParam.l)
Declare EnumProc(handle.l, lParam.l)
Declare.s GetTitle(handle) 
Declare.s GetClassName(handle.l)

NewList Window.Window()
  
;-

Procedure.s GetClassName(handle.l)
  Class.s = Space(#BufferSize)
  GetClassName_(handle, @Class, Len(Class))
  ProcedureReturn Left(Class, Len(Class))
EndProcedure

Procedure.s GetTitle(handle)
  Name.s = Space(#BufferSize)
  GetWindowText_(handle, @Name, Len(Name))
  ProcedureReturn Left(Name, Len(Name))
EndProcedure

Procedure EnumProc(handle.l, lParam.l)
  AddElement(Window())
  
  Window()\handle = handle
  Window()\process = 0
  GetWindowThreadProcessId_(handle, @Window()\process) 
  Window()\Name = GetTitle(handle)
  Window()\Class = GetClassName(handle)
  
  If lParam
    *Tmp.Window = lParam
    *Tmp\Childs + 1
    Window()\Rekursion = *Tmp\Rekursion + 1
  Else
    Window()\Rekursion = 0
  EndIf
  
  EnumChildWindows_(handle, @EnumProc(), @Window())
  
  ProcedureReturn #True
EndProcedure

Procedure EnumAllWindows()
  Protected TmpL.l
  ClearList(Window())
  TmpL = EnumWindows_(@EnumProc(), 0)
EndProcedure

;-

Procedure AddWindow(*Tmp.Window)
  handle.l = *Tmp\handle
  ClassName.s = *Tmp\Class
  processid.l = *Tmp\process
  Name.s = *Tmp\Name
  Childs.l = *Tmp\Childs
  ;AddGadgetItem(0, -1, "Handle: " + Str(Handle) + ", Process ID: " + Str(ProcessID) + ", Name: " + Chr(34) + Name + Chr(34) + ", Class Name: " + Chr(34) + ClassName + Chr(34))
  AddGadgetItem(0, -1, Name + " (" + ClassName + ") [" + Right("0000000" + Hex(handle), 8) + ", " + Right("0000000" + Hex(processid), 8) + "] + <" + Str(Childs) + ">")
EndProcedure

Procedure AddNodeToList()
  AddWindow(@Window())
  If Window()\Childs
    OpenTreeGadgetNode(0)
    Childs = Window()\Childs
    For a.l = 1 To Childs
      NextElement(Window())
      AddNodeToList()
    Next
    CloseTreeGadgetNode(0)
  EndIf
EndProcedure

Procedure RefreshList(Modus.l)
  If Modus & 1
    SetWindowCallback(0)
    ClearGadgetItemList(0)
    ResetList(Window())
    While NextElement(Window())
      AddNodeToList()
    Wend
    While WindowEvent() : Wend
  EndIf
  
  If Modus & 2
    State.l = GetGadgetState(0)
    ResetList(Window())
    c.l = 0
    While NextElement(Window())
      If Window()\Childs > 0
        SetGadgetItemState(0, c, #PB_Tree_Expanded)
      EndIf
      c + 1
    Wend
    SetGadgetState(0, State)
  EndIf
  
  If Modus & 8
    State.l = GetGadgetState(0)
    If State >= 0
      SelectElement(Window(), State)
      Rek.l = Window()\Rekursion
      c.l = State
      Repeat
        If Window()\Childs > 0
          SetGadgetItemState(0, c, #PB_Tree_Expanded)
        EndIf
        c + 1
      Until NextElement(Window()) = 0 Or (Window()\Rekursion = Rek And c > State)
      SetGadgetState(0, State)
    EndIf
  EndIf

EndProcedure

Procedure DelProcInList(process.l)
  ResetList(Window())
  While NextElement(Window())
    If Window()\process = process
      DeleteElement(Window())
    EndIf
  Wend
EndProcedure

Procedure.s rgState(DWord.l)
  #STATE_SYSTEM_FOCUSABLE = $00100000
  #STATE_SYSTEM_INVISIBLE = $8000
  #STATE_SYSTEM_OFFSCREEN = $10000
  #STATE_SYSTEM_UNAVAILABLE = $1
  #STATE_SYSTEM_PRESSED = $08
  
  Text.s = ""
  If DWord & #STATE_SYSTEM_FOCUSABLE
    Text = Text + "can accept the focus, "
  EndIf
  If DWord & #STATE_SYSTEM_INVISIBLE
    Text = Text + "invisible, "
  EndIf
  If DWord & #STATE_SYSTEM_OFFSCREEN
    Text = Text + "no visible representation, "
  EndIf
  If DWord & #STATE_SYSTEM_UNAVAILABLE
    Text = Text + "unavailable, "
  EndIf
  If DWord & #STATE_SYSTEM_PRESSED
    Text = Text + "pressed, "
  EndIf
  
  If Text
    Text = Left(Text, Len(Text) - 2)
  Else
    Text = "n/a"
  EndIf
  ProcedureReturn Text
EndProcedure

Procedure.s dwStyle(DWord.l)
  Text.s = ""
  If DWord & #WS_BORDER
    Text = Text + "thin-line border, "
  EndIf
  If DWord & #WS_CAPTION
    Text = Text + "title bar, "
  EndIf
  If DWord & #WS_CHILD
    Text = Text + "child, "
  EndIf
  If DWord & #WS_CHILDWINDOW
    Text = Text + "child, "
  EndIf
  If DWord & #WS_CLIPCHILDREN
    Text = Text + "#WS_CLIPCHILDREN, "
  EndIf
  If DWord & #WS_CLIPSIBLINGS
    Text = Text + "#WS_CLIPSIBLINGS, "
  EndIf
  If DWord & #WS_DISABLED
    Text = Text + "disabled, "
  EndIf
  If DWord & #WS_DLGFRAME
    Text = Text + "#WS_DLGFRAME, "
  EndIf
  If DWord & #WS_GROUP
    Text = Text + "first group control, "
  EndIf
  If DWord & #WS_HSCROLL
    Text = Text + "horizontal scroll bar, "
  EndIf
  If DWord & #WS_ICONIC
    Text = Text + "minimized, "
  EndIf
  If DWord & #WS_MAXIMIZE
    Text = Text + "maximized, "
  EndIf
  If DWord & #WS_MAXIMIZEBOX
    Text = Text + "maximize button, "
  EndIf
  If DWord & #WS_OVERLAPPED
    Text = Text + "overlapped, "
  EndIf
  If DWord & #WS_OVERLAPPEDWINDOW
    Text = Text + "overlapped, "
  EndIf
  If DWord & #WS_POPUP
    Text = Text + "pop-up, "
  EndIf
  If DWord & #WS_POPUPWINDOW
    Text = Text + "pop-up, "
  EndIf
  If DWord & #WS_SIZEBOX
    Text = Text + "sizing border, "
  EndIf
  If DWord & #WS_SYSMENU
    Text = Text + "system menu, "
  EndIf
  If DWord & #WS_TABSTOP
    Text = Text + "TAB navigation, "
  EndIf
  If DWord & #WS_THICKFRAME
    Text = Text + "sizing border, "
  EndIf
  If DWord & #WS_TILED
    Text = Text + "overlapped, "
  EndIf
  If DWord & #WS_TILEDWINDOW
    Text = Text + "overlapped, "
  EndIf
  If DWord & #WS_VISIBLE
    Text = Text + "visible, "
  EndIf
  If DWord & #WS_VSCROLL
    Text = Text + "vertical scroll bar, "
  EndIf
  
  If Text
    Text = Left(Text, Len(Text) - 2)
  Else
    Text = "n/a"
  EndIf
  ProcedureReturn Text
EndProcedure

Procedure.s dwExStyle(DWord.l)
  #WS_EX_COMPOSITED = $02000000
  #WS_EX_LAYERED = $80000
  #WS_EX_LAYOUTRTL = $400000
  #WS_EX_NOACTIVATE = $8000000
  #WS_EX_NOINHERITLAYOUT = $100000
  
  Text.s = ""
  If DWord & #WS_EX_ACCEPTFILES
    Text = Text + "accept drag-drop files, "
  EndIf
  If DWord & #WS_EX_APPWINDOW
    Text = Text + "taskbar window, "
  EndIf
  If DWord & #WS_EX_CLIENTEDGE
    Text = Text + "sunken edge border, "
  EndIf
  If DWord & #WS_EX_COMPOSITED
    Text = Text + "#WS_EX_COMPOSITED, "
  EndIf
  If DWord & #WS_EX_CONTEXTHELP
    Text = Text + "question mark button, "
  EndIf
  If DWord & #WS_EX_CONTROLPARENT
    Text = Text + "#WS_EX_CONTROLPARENT, "
  EndIf
  If DWord & #WS_EX_DLGMODALFRAME
    Text = Text + "double border, "
  EndIf
  If DWord & #WS_EX_LAYERED
    Text = Text + "layred, "
  EndIf
  If DWord & #WS_EX_LAYOUTRTL
    Text = Text + "Arabic/Hebrew, "
  EndIf
  If DWord & #WS_EX_LEFT
    Text = Text + "left-aligned, "
  EndIf
  If DWord & #WS_EX_LEFTSCROLLBAR
    Text = Text + "left scroll bar, "
  EndIf
  If DWord & #WS_EX_LTRREADING
    Text = Text + "left-to-right reading, "
  EndIf
  If DWord & #WS_EX_MDICHILD
    Text = Text + "MDI child, "
  EndIf
  If DWord & #WS_EX_NOACTIVATE
    Text = Text + "#WS_EX_NOACTIVATE, "
  EndIf
  If DWord & #WS_EX_NOINHERITLAYOUT
    Text = Text + "#WS_EX_NOINHERITLAYOUT, "
  EndIf
  If DWord & #WS_EX_NOPARENTNOTIFY
    Text = Text + "no #WS_PARENTNOTIFY message, "
  EndIf
  If DWord & #WS_EX_OVERLAPPEDWINDOW
    Text = Text + ""
  EndIf
  If DWord & #WS_EX_PALETTEWINDOW
    Text = Text + ""
  EndIf
  If DWord & #WS_EX_RIGHT
    Text = Text + "right-aligned, "
  EndIf
  If DWord & #WS_EX_RIGHTSCROLLBAR
    Text = Text + "right scroll bar, "
  EndIf
  If DWord & #WS_EX_RTLREADING
    Text = Text + "right-to-left reading, "
  EndIf
  If DWord & #WS_EX_STATICEDGE
    Text = Text + "3D border, "
  EndIf
  If DWord & #WS_EX_TOOLWINDOW
    Text = Text + "tool window, "
  EndIf
  If DWord & #WS_EX_TOPMOST
    Text = Text + "topmost, "
  EndIf
  If DWord & #WS_EX_TRANSPARENT
    Text = Text + "transparent, "
  EndIf
  If DWord & #WS_EX_WINDOWEDGE
    Text = Text + "raised edge, "
  EndIf
  
  If Text
    Text = Left(Text, Len(Text) - 2)
  Else
    Text = "n/a"
  EndIf
  ProcedureReturn Text
EndProcedure

Procedure.s Placement_flags(DWord.l)
  #WPF_ASYNCWINDOWPLACEMENT = $4
  #WPF_RESTORETOMAXIMIZED = $2
  #WPF_SETMINPOSITION = $1
  
  Text.s = ""
  If DWord & #WPF_ASYNCWINDOWPLACEMENT
    Text = Text + "#WPF_ASYNCWINDOWPLACEMENT, "
  EndIf
  If DWord & #WPF_RESTORETOMAXIMIZED
    Text = Text + "#WPF_RESTORETOMAXIMIZED, "
  EndIf
  If DWord & #WPF_SETMINPOSITION
    Text = Text + "#WPF_SETMINPOSITION, "
  EndIf
  
  If Text
    Text = Left(Text, Len(Text) - 2)
  Else
    Text = "n/a"
  EndIf
  ProcedureReturn Text
EndProcedure

Procedure.s Placement_showCmd(DWord.l)
  Text.s = ""
  If DWord & #SW_HIDE
    Text = Text + "hide, "
  EndIf
  If DWord & #SW_MAXIMIZE
    Text = Text + "maximize, "
  EndIf
  If DWord & #SW_MINIMIZE
    Text = Text + "minimize, "
  EndIf
  If DWord & #SW_RESTORE
    Text = Text + "restore, "
  EndIf
  If DWord & #SW_SHOW
    Text = Text + "show, "
  EndIf
  If DWord & #SW_SHOWMAXIMIZED
    Text = Text + "show maxmized, "
  EndIf
  If DWord & #SW_SHOWMINIMIZED
    Text = Text + "show minimized, "
  EndIf
  If DWord & #SW_SHOWMINNOACTIVE
    Text = Text + "show no active, "
  EndIf
  If DWord & #SW_SHOWNA
    Text = Text + "show (na), "
  EndIf
  If DWord & #SW_SHOWNOACTIVATE
    Text = Text + "show no activate, "
  EndIf
  If DWord & #SW_SHOWNORMAL
    Text = Text + "show normal, "
  EndIf

  If Text
    Text = Left(Text, Len(Text) - 2)
  Else
    Text = "n/a"
  EndIf
  ProcedureReturn Text
EndProcedure



Procedure.s GetWindowInfo(handle.l)
  Text.s = "Info about " + Hex(handle) + ":" + LF + LF
  If handle
    ;Width and height
     If GetClientRect_(handle, @Size.RECT)
       Text = Text + "GetClientRect_:" + LF
       Text = Text + "W" + Str(Size\Right) + "x" + Str(Size\Bottom) + LF + LF
     EndIf
    
    ;GetTitleBarInfo_()
     Structure TITLEBARINFO
       cbsize.l
       rcTitleBar.RECT
       rgState.l[6]
     EndStructure
     
     TitleBar.TITLEBARINFO
     TitleBar\cbsize = SizeOf(TITLEBARINFO)
     If GetTitleBarInfo_(handle, @TitleBar)
       Text = Text + "GetTitleBarInfo_:" + LF
       Text = Text + "Rect: L" + Str(TitleBar\rcTitleBar\left) + ", T" + Str(TitleBar\rcTitleBar\top)
       Text = Text + ", R" + Str(TitleBar\rcTitleBar\Right) + ", B" + Str(TitleBar\rcTitleBar\Bottom) + LF
       Text = Text + "Elements:" + LF
       Text = Text + "Title bar itself: " + rgState(TitleBar\rgState[0]) + LF
       Text = Text + "Minimize Button: " + rgState(TitleBar\rgState[2]) + LF
       Text = Text + "Maximize Button: " + rgState(TitleBar\rgState[3]) + LF
       Text = Text + "Help Button: " + rgState(TitleBar\rgState[4]) + LF
       Text = Text + "Close Button: " + rgState(TitleBar\rgState[5]) + LF + LF
     EndIf
     
    ;GetWindowInfo_
     #WS_ACTIVECAPTION = $1
     Structure WINDOWINFO
       cbsize.l
       rcWindow.RECT
       rcClient.RECT
       dwStyle.l
       dwExStyle.l
       dwWindowStatus.l
       cxWindowBorders.l
       cyWindowBorders.l
       AtomWindowType.l
       wCreatorVersion.w
     EndStructure
     
     WindowInfo.WINDOWINFO
     WindowInfo\cbsize = SizeOf(WINDOWINFO)
     If GetWindowInfo_(handle, @WindowInfo)
       Text = Text + "GetWindowInfo_:" + LF
       Text = Text + "Window Rect: L" + Str(WindowInfo\rcWindow\left) + ", T" + Str(WindowInfo\rcWindow\top)
       Text = Text + ", R" + Str(WindowInfo\rcWindow\Right) + ", B" + Str(WindowInfo\rcWindow\Bottom) + LF
       Text = Text + "Client Rect: L" + Str(WindowInfo\rcClient\left) + ", T" + Str(WindowInfo\rcClient\top)
       Text = Text + ", R" + Str(WindowInfo\rcClient\Right) + ", B" + Str(WindowInfo\rcClient\Bottom) + LF
       Text = Text + "Style: " + dwStyle(WindowInfo\dwStyle) + LF
       Text = Text + "Ex Style: " + dwExStyle(WindowInfo\dwExStyle) + LF
       Text = Text + "Status: "
       If WindowInfo\dwWindowStatus & #WS_ACTIVECAPTION
         Text = Text + "activated" + LF
       Else
         Text = Text + "deactivated" + LF
       EndIf
       Text = Text + "Border width: " + Str(WindowInfo\cxWindowBorders) + LF
       Text = Text + "Border height: " + Str(WindowInfo\cyWindowBorders) + LF
       Text = Text + "Windows version: " + Str(WindowInfo\wCreatorVersion) + LF + LF
     EndIf
     
    ;GetModuleFileName_
     ModuleName.s = Space(1024)
     If GetModuleFileName_(handle, ModuleName, 1024)
       Text = Text + "GetModuleFileName_:" + LF
       Text = Text + ModuleName + LF + LF
     EndIf
     
    ;GetWindowPlacement_
     Placement.WINDOWPLACEMENT
     Placement\Length = SizeOf(WINDOWPLACEMENT)
     If GetWindowPlacement_(handle, @Placement)
       Text = Text + "GetWindowPlacement_:" + LF
       Text = Text + "Flags: " + Placement_flags(Placement\flags) + LF
       Text = Text + "Show state: " + Placement_showCmd(Placement\showCmd) + LF
       Text = Text + "Min Position: " + Str(Placement\ptMinPosition\x) + "x" + Str(Placement\ptMinPosition\y) + LF
       Text = Text + "Max Position: " + Str(Placement\ptMaxPosition\x) + "x" + Str(Placement\ptMaxPosition\y) + LF
       Text = Text + "Normal Position: L" + Str(Placement\rcNormalPosition\left) + ", T" + Str(Placement\rcNormalPosition\top)
       Text = Text + ", R" + Str(Placement\rcNormalPosition\Right) + ", B" + Str(Placement\rcNormalPosition\Bottom) + LF + LF
     EndIf
     
    ;IsWindowUnicode_
     Text = Text + "IsWindowUnicode_: "
     If IsWindowUnicode_(handle)
       Text = Text + "yes"
     Else
       Text = Text + "no"
     EndIf
     ;Text = Text + LF + LF
  Else
    Text.s = "No info available"
  EndIf
  ProcedureReturn Text
EndProcedure

;-

Procedure SetGadgetStateLI(Gadget.l, State.l)
  Protected a.l
  For a = 0 To CountGadgetItems(Gadget) - 1
    If a = State
      SetGadgetItemState(Gadget, a, #PB_ListIcon_Selected)
    Else
      SetGadgetItemState(Gadget, a, 0)
    EndIf
  Next
  SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, State, 1)
EndProcedure

Procedure SetCursorOnHandle(handle.l)
  ResetList(Window())
  While NextElement(Window())
    If Window()\Handle = Handle
      
      If Window()\Rekursion
        Rek.l = Window()\Rekursion
        While PreviousElement(Window()) And Window()\Rekursion
          If Window()\Rekursion < Rek
            SetGadgetItemState(0, ListIndex(Window()) - 1, #PB_Tree_Expanded)
            Rek = Window()\Rekursion
          EndIf
        Wend
        SetGadgetItemState(0, ListIndex(Window()) - 1, #PB_Tree_Expanded)
      EndIf
      SetGadgetState(0, ListIndex(Window()) - 1)
      ProcedureReturn #True
    EndIf
  Wend
  ProcedureReturn #False
EndProcedure

Procedure AddLog(Text.s)
  State.l = CountGadgetItems(2)
  Zeit.s = FormatDate("%hh:%ii:%ss", Date())
  AddGadgetItem(2, State, Zeit)
  SetGadgetItemText(2, State, Text, 1)
  SetGadgetStateLI(2, State)
EndProcedure

Width.l = 800
Height.l = 600

If OpenWindow(0, 0, 0, Width, Height, #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget, "AllWindows and Childs")
  If CreateGadgetList(WindowID())
    #T1Width = 140
    #TextHeight = 16
    #ButtonHeight = 18
    #StrHeight = 200
    #Abs = 5
    #PanelHeight = 200

    TreeGadget(0, 0, 0, Width - #T1Width - 5, Height - #PanelHeight - 5, #PB_Tree_AlwaysShowSelection | #PB_Tree_NoLines)    
    
    PanelGadget(5, 0, Height - #PanelHeight, Width - #T1Width - 5, #PanelHeight)
    AddGadgetItem(5, 0, "Log")
      ListIconGadget(2, 0, 0, Width - #T1Width - 52, #PanelHeight - 25, "Zeit", 100, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_FullRowSelect)
      AddGadgetColumn(2, 1, "Log", 1000)
      ButtonGadget(3, Width - #T1Width - 50, 0, 40, #PanelHeight - 25, "Clear")
    AddGadgetItem(5, 1, "Window Info")
      StringGadget(4, 0, 0, Width - #T1Width - 10, #PanelHeight - 25, "", #PB_String_MultiLine | #WS_VSCROLL | #WS_HSCROLL)
    CloseGadgetList()
    
    ButtonGadget(10, Width - #T1Width, 0 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh Memory")
    ButtonGadget(11, Width - #T1Width, 1 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh List")
    
    ButtonGadget(12, Width - #T1Width, 2 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open All Nodes")
    ButtonGadget(14, Width - #T1Width, 3 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open Whole Node")
    
    
    ButtonGadget(16, Width - #T1Width, 4 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Quit")
    ButtonGadget(17, Width - #T1Width, 5 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Close")
    
    ButtonGadget(18, Width - #T1Width, 6 * #ButtonHeight + 4 * #Abs, #T1Width, #ButtonHeight, "Terminate Process")
    
    ButtonGadget(20, Width - #T1Width, 7 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "CloseWindow_")
    ButtonGadget(21, Width - #T1Width, 8 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "DestroyWindow_")
    ButtonGadget(22, Width - #T1Width, 9 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "Window Info")
    ButtonGadget(23, Width - #T1Width, 10 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetDesktopWindow_")
    ButtonGadget(24, Width - #T1Width, 11 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetForegroundWindow_")
    ButtonGadget(25, Width - #T1Width, 12 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetNextWindow_")
    ButtonGadget(26, Width - #T1Width, 13 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetPrevWindow_")
;     ButtonGadget(27, Width - #T1Width, 14 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "HideWindow_")
    
    Width - 1
    Repeat
      If Width <> WindowWidth() Or Height <> WindowHeight()
        Width = WindowWidth()
        Height = WindowHeight()
        ResizeGadget(0, -1, -1, Width - #T1Width - 5, Height - #PanelHeight - 5)
        ResizeGadget(2, -1, -1, Width - #T1Width - 52, -1)
        ResizeGadget(3, Width - #T1Width - 50, -1, -1, -1)
        ResizeGadget(4, -1, -1, Width - #T1Width - 10, -1)
        ResizeGadget(5, -1, Height - #PanelHeight, Width - #T1Width - 5, -1)
        For a.l = 10 To 26
          If IsGadget(a)
            ResizeGadget(a, Width - #T1Width, -1, -1, -1)
          EndIf
        Next
      EndIf
      
      If CountList(Window())
        DisableGadget(11, 0)
      Else
        DisableGadget(11, 1)
      EndIf
      
      If CountGadgetItems(0)
        DisableGadget(12, 0)
        DisableGadget(23, 0)
        DisableGadget(24, 0)
      Else
        DisableGadget(12, 1)
        DisableGadget(23, 1)
        DisableGadget(24, 1)
      EndIf
      
      State.l = GetGadgetState(0)
      
      If State >= 0
        SelectElement(Window(), State)
        If Window()\Childs
          DisableGadget(14, 0)
        Else
          DisableGadget(14, 1)
        EndIf
        DisableGadget(16, 0)
        DisableGadget(17, 0)
        
        Result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\process) 
        If Result
          DisableGadget(18, 0)
          closehandle_(Result)
        Else
          DisableGadget(18, 0)        
        EndIf
        
        For a.l = 19 To 21
          If GadgetID(a) : DisableGadget(a, 0) : EndIf
        Next
        
        If IsWindow_(Window()\handle)
          DisableGadget(22, 0)
        Else
          DisableGadget(22, 1)
        EndIf
        
        DisableGadget(25, 0)
        DisableGadget(26, 0)
      Else
        For a.l = 14 To 22
          If IsGadget(a) : DisableGadget(a, 1) : EndIf
        Next
        For a.l = 25 To 26
          If IsGadget(a) : DisableGadget(a, 1) : EndIf
        Next
      EndIf
      
      If CountGadgetItems(2)
        DisableGadget(3, 0)
        DisableGadget(2, 0)
      Else
        DisableGadget(3, 1)
        DisableGadget(2, 1)
      EndIf
      
      If Trim(GetGadgetText(4)) = ""
        DisableGadget(4, 1)
      Else
        DisableGadget(4, 0)
      EndIf

      EventID.l = WaitWindowEvent()
      Select EventID
        Case #PB_EventCloseWindow
          End
        
        Case #PB_EventGadget
          Select EventGadgetID()
            Case 3  ;Clear Log
              ClearGadgetItemList(2)
              
            Case 10 ;Refresh Memory
              time.l = GetTickCount_()
              EnumAllWindows()
              time.l = GetTickCount_() - time
              AddLog("Enum windows in " + Str(time) + " ms.")
              AddLog(Str(CountList(Window())) + " windows found")
            
            Case 11 ;Refresh List
              time.l = GetTickCount_()
              RefreshList(1)
              time.l = GetTickCount_() - time
              AddLog("Refresh list in " + Str(time) + " ms.")
            
            Case 12 ;Open All Nodes
              time.l = GetTickCount_()
              RefreshList(2)
              time.l = GetTickCount_() - time
              AddLog("Opened all nodes in " + Str(time) + " ms.")
            
            Case 14 ;Open Whole Node
              time.l = GetTickCount_()
              RefreshList(8)
              time.l = GetTickCount_() - time
              AddLog("Opened whole node in " + Str(time) + " ms.")
            
            Case 16 ;Post Quit
              PostMessage_(Window()\handle, #WM_QUIT, 0, 0)
            Case 17 ;Post Close
              PostMessage_(Window()\handle, #WM_CLOSE, 0, 0)
            
            Case 18 ;Terminate Process
              Result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\process) 
              If Result
                If terminateprocess_(Result, 0)
                  AddLog("The process with the ID " + Str(Window()\process) + " was successfully terminated.")
                  DelProcInList(Window()\process)
                  AddLog("List refresh needed")
                EndIf
                closehandle_(Result)
              EndIf
            
            Case 20 ;CloseWindow_
              CloseWindow_(Window()\handle)
            
            Case 21 ;DestroyWindow_
              DestroyWindow_(Window()\handle)
            
            Case 22 ;Window Info
              Text.s = GetWindowInfo(Window()\handle)
              SetGadgetText(4, Text)
              SetGadgetState(5, 1)
              ActivateGadget(0)
              
            Case 23 ;GetDesktopWindow_
              Result.l = GetDesktopWindow_()
              If Result
                SetCursorOnHandle(Result)
              EndIf
              
            Case 24 ;GetForegroundWindow_
              Result.l = GetForegroundWindow_()
              If Result
                SetCursorOnHandle(Result)
              EndIf
            
            Case 25 ;GetNextWindow_
              Result.l = GetWindow_(Window()\handle, #GW_HWNDNEXT)
              If Result
                SetCursorOnHandle(Result)
                AddLog("Handle: " + Str(Result))
              Else
                AddLog("No next Window")
              EndIf
            
            Case 26 ;GetPrevWindow_
              Result.l = GetWindow_(Window()\handle, #GW_HWNDPREV)
              If Result
                SetCursorOnHandle(Result)
                AddLog("Handle: " + Str(Result))
              Else
                AddLog("No previous Window")
              EndIf
            
;             Case 27 ;HideWindow_
;               If Result
;                 DestroyWindow_(Result)
;               EndIf
          EndSelect
      EndSelect
    ForEver
  EndIf
EndIf
End

Verfasst: 24.02.2005 00:28
von Ynnus
Bei mir zeigt er immer an, dass es 234.626 Fenster sind. (in ~4000 ms geladen) :o
Ist das jetzt ein Bug oder laufen tatsächlich so viele Fenster / Button / Childs und Co. umher? Demnach schafft er es auch nicht, die Liste der Fenster zu laden und stürzt immer dabei ab. Scheinbar sind das dann doch zu viele Rechenoperationen bevor er diese ~ 230.000 Fenster alle gefunden hat...

Verfasst: 24.02.2005 00:34
von NicTheQuick
Bei mir findet er innerhalb 100 ms 3180 Fenster und die Liste wird dann in 6128 ms aktualisiert.

Also irgendwas stimmt da bei dir nicht. /:->

Welches Windows hast du?

Verfasst: 24.02.2005 00:48
von Ynnus
Windows XP Pro (Build 2600), ohne jegliches SP. Und ich glaube, sooo viele Fenster hab ich nun auch wieder nicht am Laufen.
//EDIT: Habe gerade herausgefunden, dass sich dein Programm scheinbar nicht mit eDonkey2000 (v1.0) verträgt. Jetzt wo ich es aus habe, findet er in 31 ms ca. 800 Fenster. Trotzdem komisch, dass es da Probleme gibt. Glaube kaum, dass eDonkey 2000 mehr als 200.000 Fenster erstellt.

Verfasst: 24.02.2005 01:16
von NicTheQuick
Im Grunde macht mein Programm nichts ungewöhnliches. Das heißt, es findet die Fenster so, wie es vorgesehen ist. Ich benutze keine Hacks oder sonstiges, sondern die normalen API-Funktionen um "Childs" zu "enumerieren" und werte die Rückmeldungen korrekt aus.

Was das ganze mit eDonkey zu tun, weiß ich jetzt aber nicht. Ich kenne bisher noch keinen, der das selbe Problem hätte. Aber auf WinXP kann ich das ganze nicht testen, da wir zu Hause nur Rechner mit Win2k haben.

Verantwortlich für das Auffinden der Fenster und Eintragen in die interne Liste sind nur die folgenden zwei Fonktionen:

Code: Alles auswählen

Procedure EnumProc(handle.l, lParam.l) 
  AddElement(Window()) 
  
  Window()\handle = handle 
  Window()\process = 0 
  GetWindowThreadProcessId_(handle, @Window()\process) 
  Window()\Name = GetTitle(handle) 
  Window()\Class = GetClassName(handle) 
  
  If lParam 
    *Tmp.Window = lParam 
    *Tmp\Childs + 1 
    Window()\Rekursion = *Tmp\Rekursion + 1 
  Else 
    Window()\Rekursion = 0 
  EndIf 
  
  EnumChildWindows_(handle, @EnumProc(), @Window()) 
  
  ProcedureReturn #True 
EndProcedure 

Procedure EnumAllWindows() 
  Protected TmpL.l 
  ClearList(Window()) 
  TmpL = EnumWindows_(@EnumProc(), 0) 
EndProcedure 
Kannst du mal schauen, ob du irgendwas herausfindest, warum das ganze so ist? Irgendeine Abhängigkeit?

Verfasst: 24.02.2005 01:28
von Deeem2031
Er zeigt bei mir zwar auch 14.000 Fenster an und braucht fast 2 Min. um die Liste zu aktuallisieren aber 200.000? :freak:

Naja, jedenfalls ist hier meine verbesserte Version:

Code: Alles auswählen

Enumeration ;Gadgets
  #G_MainTree
  #G_MainPanel
  #G_Log
  #G_LogClear
  #G_WindowInfo
  
  #G_B_RefreshMemory
  #G_B_RefreshList
  #G_B_OpenAllNodes
  #G_B_OpenWholeNode
  #G_B_PostQuit
  #G_B_PostClose
  #G_B_TerminateProcess
  #G_B_CloseWindow
  #G_B_DestroyWindow
  #G_B_WindowInfo
  #G_B_GetDesktopWindow
  #G_B_GetForegroundWindow
  #G_B_GetNextWindow
  #G_B_GetPrevWindow
  #G_B_HideWindow
  #G_B_MouseOverWindow
EndEnumeration

Structure Window 
  Childs.l 
  Rekursion.l 
  
  ;Window 
  Handle.l 
  Process.l 
  name.s 
  Class.s 
EndStructure 

#PROCESS_ALL_ACCESS = $FFF 

#BufferSize = 2048 

Global LF.s 
LF = Chr(13) + Chr(10) 

Declare RefreshList(Modus.l) 
Declare AddWindow(*tmp.Window) 
Declare EnumAllWindows() 
Declare EnumProc(Handle.l, lParam.l) 
Declare.s GetTitle(Handle) 
Declare.s GetClassName(Handle.l) 

NewList Window.Window() 
  
;- 

Procedure.s GetClassName(Handle.l) 
  Class.s = Space(#BufferSize) 
  GetClassName_(Handle, @Class, Len(Class)) 
  ProcedureReturn Left(Class, Len(Class)) 
EndProcedure 

Procedure.s GetTitle(Handle) 
  name.s = Space(#BufferSize) 
  GetWindowText_(Handle, @name, Len(name)) 
  ProcedureReturn Left(name, Len(name)) 
EndProcedure 

Procedure EnumProc(Handle.l, lParam.l) 
  AddElement(Window()) 
  
  Window()\Handle = Handle 
  Window()\Process = 0 
  GetWindowThreadProcessId_(Handle, @Window()\Process) 
  Window()\name = GetTitle(Handle) 
  Window()\Class = GetClassName(Handle) 
  
  If lParam 
    *tmp.Window = lParam 
    *tmp\Childs + 1 
    Window()\Rekursion = *tmp\Rekursion + 1 
  Else 
    Window()\Rekursion = 0 
  EndIf 
  
  EnumChildWindows_(Handle, @EnumProc(), @Window()) 
  
  ProcedureReturn #True 
EndProcedure 

Procedure EnumAllWindows() 
  Protected TmpL.l 
  ClearList(Window()) 
  TmpL = EnumWindows_(@EnumProc(), 0) 
EndProcedure 

;- 

Procedure AddWindow(*tmp.Window) 
  Handle.l = *tmp\Handle 
  ClassName.s = *tmp\Class 
  ProcessID.l = *tmp\Process 
  name.s = *tmp\name 
  Childs.l = *tmp\Childs 
  ;AddGadgetItem(#G_MainTree, -1, "Handle: " + Str(Handle) + ", Process ID: " + Str(ProcessID) + ", Name: " + Chr(34) + Name + Chr(34) + ", Class Name: " + Chr(34) + ClassName + Chr(34)) 
  AddGadgetItem(#G_MainTree, -1, name + " (" + ClassName + ") [" + Right("0000000" + Hex(Handle), 8) + ", " + Right("0000000" + Hex(ProcessID), 8) + "] + <" + Str(Childs) + ">") 
EndProcedure 

Procedure AddNodeToList() 
  AddWindow(@Window()) 
  If Window()\Childs 
    OpenTreeGadgetNode(#G_MainTree) 
    Childs = Window()\Childs 
    For a.l = 1 To Childs 
      NextElement(Window()) 
      AddNodeToList() 
    Next 
    CloseTreeGadgetNode(#G_MainTree)
  EndIf 
EndProcedure 

Procedure RefreshList(Modus.l) 
  If Modus & 1 
    SetWindowCallback(0) 
    ClearGadgetItemList(#G_MainTree) 
    ResetList(Window()) 
    While NextElement(Window()) 
      AddNodeToList() 
    Wend 
    While WindowEvent() : Wend 
  EndIf 
  
  If Modus & 2 
    State.l = GetGadgetState(#G_MainTree) 
    ResetList(Window()) 
    c.l = 0 
    While NextElement(Window()) 
      If Window()\Childs > 0 
        SetGadgetItemState(#G_MainTree, c, #PB_Tree_Expanded) 
      EndIf 
      c + 1 
    Wend 
    SetGadgetState(#G_MainTree, State) 
  EndIf 
  
  If Modus & 8 
    State.l = GetGadgetState(#G_MainTree) 
    If State >= 0 
      SelectElement(Window(), State) 
      Rek.l = Window()\Rekursion 
      c.l = State 
      Repeat 
        If Window()\Childs > 0 
          SetGadgetItemState(#G_MainTree, c, #PB_Tree_Expanded) 
        EndIf 
        c + 1 
      Until NextElement(Window()) = 0 Or (Window()\Rekursion = Rek And c > State) 
      SetGadgetState(#G_MainTree, State) 
    EndIf 
  EndIf 
  
EndProcedure 

Procedure DelProcInList(Process.l) 
  ResetList(Window()) 
  While NextElement(Window()) 
    If Window()\Process = Process 
      DeleteElement(Window()) 
    EndIf 
  Wend 
EndProcedure 

Procedure SearchWindow(hwnd.l)
  Static Pos.l
  
  Pos = 0
  
  ResetList(Window())
  While NextElement(Window())
    If Window()\Handle = hwnd
      found = #True
      Break 1
    EndIf
    Pos + 1
    If Window()\Childs 
      For a.l = 1 To Window()\Childs
        NextElement(Window())
        If Window()\Handle = hwnd
          found = #True
          Break 2
        EndIf
        Pos + 1
      Next 
    EndIf 
  Wend
  
  If found
    SetGadgetState(#G_MainTree,Pos)
  EndIf
  
  ProcedureReturn found
EndProcedure

Procedure.s rgState(dword.l) 
  #STATE_SYSTEM_FOCUSABLE = $00100000 
  #STATE_SYSTEM_INVISIBLE = $8000 
  #STATE_SYSTEM_OFFSCREEN = $10000 
  #STATE_SYSTEM_UNAVAILABLE = $1 
  #STATE_SYSTEM_PRESSED = $08 
  
  Text.s = "" 
  If dword & #STATE_SYSTEM_FOCUSABLE 
    Text = Text + "can accept the focus, " 
  EndIf 
  If dword & #STATE_SYSTEM_INVISIBLE 
    Text = Text + "invisible, " 
  EndIf 
  If dword & #STATE_SYSTEM_OFFSCREEN 
    Text = Text + "no visible representation, " 
  EndIf 
  If dword & #STATE_SYSTEM_UNAVAILABLE 
    Text = Text + "unavailable, " 
  EndIf 
  If dword & #STATE_SYSTEM_PRESSED 
    Text = Text + "pressed, " 
  EndIf 
  
  If Text 
    Text = Left(Text, Len(Text) - 2) 
  Else 
    Text = "n/a" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 

Procedure.s dwStyle(dword.l) 
  Text.s = "" 
  If dword & #WS_BORDER 
    Text = Text + "thin-line border, " 
  EndIf 
  If dword & #WS_CAPTION 
    Text = Text + "title bar, " 
  EndIf 
  If dword & #WS_CHILD 
    Text = Text + "child, " 
  EndIf 
  If dword & #WS_CHILDWINDOW 
    Text = Text + "child, " 
  EndIf 
  If dword & #WS_CLIPCHILDREN 
    Text = Text + "#WS_CLIPCHILDREN, " 
  EndIf 
  If dword & #WS_CLIPSIBLINGS 
    Text = Text + "#WS_CLIPSIBLINGS, " 
  EndIf 
  If dword & #WS_DISABLED 
    Text = Text + "disabled, " 
  EndIf 
  If dword & #WS_DLGFRAME 
    Text = Text + "#WS_DLGFRAME, " 
  EndIf 
  If dword & #WS_GROUP 
    Text = Text + "first group control, " 
  EndIf 
  If dword & #WS_HSCROLL 
    Text = Text + "horizontal scroll bar, " 
  EndIf 
  If dword & #WS_ICONIC 
    Text = Text + "minimized, " 
  EndIf 
  If dword & #WS_MAXIMIZE 
    Text = Text + "maximized, " 
  EndIf 
  If dword & #WS_MAXIMIZEBOX 
    Text = Text + "maximize button, " 
  EndIf 
  If dword & #WS_OVERLAPPED 
    Text = Text + "overlapped, " 
  EndIf 
  If dword & #WS_OVERLAPPEDWINDOW 
    Text = Text + "overlapped, " 
  EndIf 
  If dword & #WS_POPUP 
    Text = Text + "pop-up, " 
  EndIf 
  If dword & #WS_POPUPWINDOW 
    Text = Text + "pop-up, " 
  EndIf 
  If dword & #WS_SIZEBOX 
    Text = Text + "sizing border, " 
  EndIf 
  If dword & #WS_SYSMENU 
    Text = Text + "system menu, " 
  EndIf 
  If dword & #WS_TABSTOP 
    Text = Text + "TAB navigation, " 
  EndIf 
  If dword & #WS_THICKFRAME 
    Text = Text + "sizing border, " 
  EndIf 
  If dword & #WS_TILED 
    Text = Text + "overlapped, " 
  EndIf 
  If dword & #WS_TILEDWINDOW 
    Text = Text + "overlapped, " 
  EndIf 
  If dword & #WS_VISIBLE 
    Text = Text + "visible, " 
  EndIf 
  If dword & #WS_VSCROLL 
    Text = Text + "vertical scroll bar, " 
  EndIf 
  
  If Text 
    Text = Left(Text, Len(Text) - 2) 
  Else 
    Text = "n/a" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 

Procedure.s dwExStyle(dword.l) 
  #WS_EX_COMPOSITED = $02000000 
  #WS_EX_LAYERED = $80000 
  #WS_EX_LAYOUTRTL = $400000 
  #WS_EX_NOACTIVATE = $8000000 
  #WS_EX_NOINHERITLAYOUT = $100000 
  
  Text.s = "" 
  If dword & #WS_EX_ACCEPTFILES 
    Text = Text + "accept drag-drop files, " 
  EndIf 
  If dword & #WS_EX_APPWINDOW 
    Text = Text + "taskbar window, " 
  EndIf 
  If dword & #WS_EX_CLIENTEDGE 
    Text = Text + "sunken edge border, " 
  EndIf 
  If dword & #WS_EX_COMPOSITED 
    Text = Text + "#WS_EX_COMPOSITED, " 
  EndIf 
  If dword & #WS_EX_CONTEXTHELP 
    Text = Text + "question mark button, " 
  EndIf 
  If dword & #WS_EX_CONTROLPARENT 
    Text = Text + "#WS_EX_CONTROLPARENT, " 
  EndIf 
  If dword & #WS_EX_DLGMODALFRAME 
    Text = Text + "double border, " 
  EndIf 
  If dword & #WS_EX_LAYERED 
    Text = Text + "layred, " 
  EndIf 
  If dword & #WS_EX_LAYOUTRTL 
    Text = Text + "Arabic/Hebrew, " 
  EndIf 
  If dword & #WS_EX_LEFT 
    Text = Text + "left-aligned, " 
  EndIf 
  If dword & #WS_EX_LEFTSCROLLBAR 
    Text = Text + "left scroll bar, " 
  EndIf 
  If dword & #WS_EX_LTRREADING 
    Text = Text + "left-to-right reading, " 
  EndIf 
  If dword & #WS_EX_MDICHILD 
    Text = Text + "MDI child, " 
  EndIf 
  If dword & #WS_EX_NOACTIVATE 
    Text = Text + "#WS_EX_NOACTIVATE, " 
  EndIf 
  If dword & #WS_EX_NOINHERITLAYOUT 
    Text = Text + "#WS_EX_NOINHERITLAYOUT, " 
  EndIf 
  If dword & #WS_EX_NOPARENTNOTIFY 
    Text = Text + "no #WS_PARENTNOTIFY message, " 
  EndIf 
  If dword & #WS_EX_OVERLAPPEDWINDOW 
    Text = Text + "" 
  EndIf 
  If dword & #WS_EX_PALETTEWINDOW 
    Text = Text + "" 
  EndIf 
  If dword & #WS_EX_RIGHT 
    Text = Text + "right-aligned, " 
  EndIf 
  If dword & #WS_EX_RIGHTSCROLLBAR 
    Text = Text + "right scroll bar, " 
  EndIf 
  If dword & #WS_EX_RTLREADING 
    Text = Text + "right-to-left reading, " 
  EndIf 
  If dword & #WS_EX_STATICEDGE 
    Text = Text + "3D border, " 
  EndIf 
  If dword & #WS_EX_TOOLWINDOW 
    Text = Text + "tool window, " 
  EndIf 
  If dword & #WS_EX_TOPMOST 
    Text = Text + "topmost, " 
  EndIf 
  If dword & #WS_EX_TRANSPARENT 
    Text = Text + "transparent, " 
  EndIf 
  If dword & #WS_EX_WINDOWEDGE 
    Text = Text + "raised edge, " 
  EndIf 
  
  If Text 
    Text = Left(Text, Len(Text) - 2) 
  Else 
    Text = "n/a" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 

Procedure.s Placement_flags(dword.l) 
  #WPF_ASYNCWINDOWPLACEMENT = $4 
  #WPF_RESTORETOMAXIMIZED = $2 
  #WPF_SETMINPOSITION = $1 
  
  Text.s = "" 
  If dword & #WPF_ASYNCWINDOWPLACEMENT 
    Text = Text + "#WPF_ASYNCWINDOWPLACEMENT, " 
  EndIf 
  If dword & #WPF_RESTORETOMAXIMIZED 
    Text = Text + "#WPF_RESTORETOMAXIMIZED, " 
  EndIf 
  If dword & #WPF_SETMINPOSITION 
    Text = Text + "#WPF_SETMINPOSITION, " 
  EndIf 
  
  If Text 
    Text = Left(Text, Len(Text) - 2) 
  Else 
    Text = "n/a" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 

Procedure.s Placement_showCmd(dword.l) 
  Text.s = "" 
  If dword & #SW_HIDE 
    Text = Text + "hide, " 
  EndIf 
  If dword & #SW_MAXIMIZE 
    Text = Text + "maximize, " 
  EndIf 
  If dword & #SW_MINIMIZE 
    Text = Text + "minimize, " 
  EndIf 
  If dword & #SW_RESTORE 
    Text = Text + "restore, " 
  EndIf 
  If dword & #SW_SHOW 
    Text = Text + "show, " 
  EndIf 
  If dword & #SW_SHOWMAXIMIZED 
    Text = Text + "show maxmized, " 
  EndIf 
  If dword & #SW_SHOWMINIMIZED 
    Text = Text + "show minimized, " 
  EndIf 
  If dword & #SW_SHOWMINNOACTIVE 
    Text = Text + "show no active, " 
  EndIf 
  If dword & #SW_SHOWNA 
    Text = Text + "show (na), " 
  EndIf 
  If dword & #SW_SHOWNOACTIVATE 
    Text = Text + "show no activate, " 
  EndIf 
  If dword & #SW_SHOWNORMAL 
    Text = Text + "show normal, " 
  EndIf 
  
  If Text 
    Text = Left(Text, Len(Text) - 2) 
  Else 
    Text = "n/a" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 



Procedure.s GetWindowInfo(Handle.l) 
  Text.s = "Info about " + Hex(Handle) + ":" + LF + LF 
  If Handle 
    ;Width and height 
    If GetClientRect_(Handle, @size.RECT) 
      Text = Text + "GetClientRect_:" + LF 
      Text = Text + "W" + Str(size\right) + "x" + Str(size\bottom) + LF + LF 
    EndIf 
    
    ;GetTitleBarInfo_() 
    Structure TITLEBARINFO 
      cbSize.l 
      rcTitleBar.RECT 
      rgState.l[6] 
    EndStructure 
    
    TitleBar.TITLEBARINFO 
    TitleBar\cbSize = SizeOf(TITLEBARINFO) 
    If GetTitleBarInfo_(Handle, @TitleBar) 
      Text = Text + "GetTitleBarInfo_:" + LF 
      Text = Text + "Rect: L" + Str(TitleBar\rcTitleBar\left) + ", T" + Str(TitleBar\rcTitleBar\top) 
      Text = Text + ", R" + Str(TitleBar\rcTitleBar\right) + ", B" + Str(TitleBar\rcTitleBar\bottom) + LF 
      Text = Text + "Elements:" + LF 
      Text = Text + "Title bar itself: " + rgState(TitleBar\rgState[0]) + LF 
      Text = Text + "Minimize Button: " + rgState(TitleBar\rgState[2]) + LF 
      Text = Text + "Maximize Button: " + rgState(TitleBar\rgState[3]) + LF 
      Text = Text + "Help Button: " + rgState(TitleBar\rgState[4]) + LF 
      Text = Text + "Close Button: " + rgState(TitleBar\rgState[5]) + LF + LF 
    EndIf 
    
    ;GetWindowInfo_ 
    #WS_ACTIVECAPTION = $1 
    Structure WINDOWINFO 
      cbSize.l 
      rcWindow.RECT 
      rcClient.RECT 
      dwStyle.l 
      dwExStyle.l 
      dwWindowStatus.l 
      cxWindowBorders.l 
      cyWindowBorders.l 
      AtomWindowType.l 
      wCreatorVersion.w 
    EndStructure 
    
    WindowInfo.WINDOWINFO 
    WindowInfo\cbSize = SizeOf(WINDOWINFO) 
    If GetWindowInfo_(Handle, @WindowInfo) 
      Text = Text + "GetWindowInfo_:" + LF 
      Text = Text + "Window Rect: L" + Str(WindowInfo\rcWindow\left) + ", T" + Str(WindowInfo\rcWindow\top) 
      Text = Text + ", R" + Str(WindowInfo\rcWindow\right) + ", B" + Str(WindowInfo\rcWindow\bottom) + LF 
      Text = Text + "Client Rect: L" + Str(WindowInfo\rcClient\left) + ", T" + Str(WindowInfo\rcClient\top) 
      Text = Text + ", R" + Str(WindowInfo\rcClient\right) + ", B" + Str(WindowInfo\rcClient\bottom) + LF 
      Text = Text + "Style: " + dwStyle(WindowInfo\dwStyle) + LF 
      Text = Text + "Ex Style: " + dwExStyle(WindowInfo\dwExStyle) + LF 
      Text = Text + "Status: " 
      If WindowInfo\dwWindowStatus & #WS_ACTIVECAPTION 
        Text = Text + "activated" + LF 
      Else 
        Text = Text + "deactivated" + LF 
      EndIf 
      Text = Text + "Border width: " + Str(WindowInfo\cxWindowBorders) + LF 
      Text = Text + "Border height: " + Str(WindowInfo\cyWindowBorders) + LF 
      Text = Text + "Windows version: " + Str(WindowInfo\wCreatorVersion) + LF + LF 
    EndIf 
    
    ;GetModuleFileName_ 
    ModuleName.s = Space(1024) 
    If GetModuleFileName_(Handle, ModuleName, 1024) 
      Text = Text + "GetModuleFileName_:" + LF 
      Text = Text + ModuleName + LF + LF 
    EndIf 
    
    ;GetWindowPlacement_ 
    Placement.WINDOWPLACEMENT 
    Placement\Length = SizeOf(WINDOWPLACEMENT) 
    If GetWindowPlacement_(Handle, @Placement) 
      Text = Text + "GetWindowPlacement_:" + LF 
      Text = Text + "Flags: " + Placement_flags(Placement\flags) + LF 
      Text = Text + "Show state: " + Placement_showCmd(Placement\showCmd) + LF 
      Text = Text + "Min Position: " + Str(Placement\ptMinPosition\x) + "x" + Str(Placement\ptMinPosition\y) + LF 
      Text = Text + "Max Position: " + Str(Placement\ptMaxPosition\x) + "x" + Str(Placement\ptMaxPosition\y) + LF 
      Text = Text + "Normal Position: L" + Str(Placement\rcNormalPosition\left) + ", T" + Str(Placement\rcNormalPosition\top) 
      Text = Text + ", R" + Str(Placement\rcNormalPosition\right) + ", B" + Str(Placement\rcNormalPosition\bottom) + LF + LF 
    EndIf 
    
    ;IsWindowUnicode_ 
    Text = Text + "IsWindowUnicode_: " 
    If IsWindowUnicode_(Handle) 
      Text = Text + "yes" 
    Else 
      Text = Text + "no" 
    EndIf 
    ;Text = Text + LF + LF 
  Else 
    Text.s = "No info available" 
  EndIf 
  ProcedureReturn Text 
EndProcedure 

;- 

Procedure SetGadgetStateLI(Gadget.l, State.l) 
  Protected a.l 
  For a = 0 To CountGadgetItems(Gadget) - 1 
    If a = State 
      SetGadgetItemState(Gadget, a, #PB_ListIcon_Selected) 
    Else 
      SetGadgetItemState(Gadget, a, 0) 
    EndIf 
  Next 
  SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, State, 1) 
EndProcedure 

Procedure SetCursorOnHandle(Handle.l) 
  ResetList(Window()) 
  While NextElement(Window()) 
    If Window()\Handle = Handle 
      
      If Window()\Rekursion 
        Rek.l = Window()\Rekursion 
        While PreviousElement(Window()) And Window()\Rekursion 
          If Window()\Rekursion < Rek 
            SetGadgetItemState(#G_MainTree, ListIndex(Window()) - 1, #PB_Tree_Expanded) 
            Rek = Window()\Rekursion 
          EndIf 
        Wend 
        SetGadgetItemState(#G_MainTree, ListIndex(Window()) - 1, #PB_Tree_Expanded) 
      EndIf 
      SetGadgetState(#G_MainTree, ListIndex(Window()) - 1) 
      ProcedureReturn #True 
    EndIf 
  Wend 
  ProcedureReturn #False 
EndProcedure 

Procedure AddLog(Text.s) 
  State.l = CountGadgetItems(#G_Log) 
  Zeit.s = FormatDate("%hh:%ii:%ss", Date()) 
  AddGadgetItem(#G_Log, State, Zeit) 
  SetGadgetItemText(#G_Log, State, Text, 1) 
  SetGadgetStateLI(#G_Log, State) 
EndProcedure 

Width.l = 800 
Height.l = 600 

If OpenWindow(0, 0, 0, Width, Height, #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget, "AllWindows and Childs") 
  If CreateGadgetList(WindowID()) 
    #T1Width = 140 
    #TextHeight = 16 
    #ButtonHeight = 18 
    #StrHeight = 200 
    #Abs = 5 
    #PanelHeight = 200 
    
    TreeGadget(#G_MainTree, 0, 0, Width - #T1Width - 5, Height - #PanelHeight - 5, #PB_Tree_AlwaysShowSelection | #PB_Tree_NoLines)    
    
    PanelGadget(#G_MainPanel, 0, Height - #PanelHeight, Width - #T1Width - 5, #PanelHeight) 
    AddGadgetItem(#G_MainPanel, 0, "Log") 
    ListIconGadget(#G_Log, 0, 0, Width - #T1Width - 52, #PanelHeight - 25, "Zeit", 100, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_FullRowSelect) 
    AddGadgetColumn(#G_Log, 1, "Log", 1000) 
    ButtonGadget(#G_LogClear, Width - #T1Width - 50, 0, 40, #PanelHeight - 25, "Clear") 
    AddGadgetItem(#G_MainPanel, 1, "Window Info") 
    StringGadget(#G_WindowInfo, 0, 0, Width - #T1Width - 10, #PanelHeight - 25, "", #PB_String_MultiLine | #WS_VSCROLL | #WS_HSCROLL) 
    CloseGadgetList() 
    
    ButtonGadget(#G_B_RefreshMemory, Width - #T1Width, 0 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh Memory") 
    ButtonGadget(#G_B_RefreshList, Width - #T1Width, 1 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh List") 
    
    ButtonGadget(#G_B_OpenAllNodes, Width - #T1Width, 2 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open All Nodes") 
    ButtonGadget(#G_B_OpenWholeNode, Width - #T1Width, 3 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open Whole Node") 
    
    
    ButtonGadget(#G_B_PostQuit, Width - #T1Width, 4 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Quit") 
    ButtonGadget(#G_B_PostClose, Width - #T1Width, 5 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Close") 
    
    ButtonGadget(#G_B_TerminateProcess, Width - #T1Width, 6 * #ButtonHeight + 4 * #Abs, #T1Width, #ButtonHeight, "Terminate Process") 
    
    ButtonGadget(#G_B_CloseWindow, Width - #T1Width, 7 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "CloseWindow_") 
    ButtonGadget(#G_B_DestroyWindow, Width - #T1Width, 8 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "DestroyWindow_") 
    ButtonGadget(#G_B_WindowInfo, Width - #T1Width, 9 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "Window Info") 
    ButtonGadget(#G_B_GetDesktopWindow, Width - #T1Width, 10 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetDesktopWindow_") 
    ButtonGadget(#G_B_GetForegroundWindow, Width - #T1Width, 11 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetForegroundWindow_") 
    ButtonGadget(#G_B_GetNextWindow, Width - #T1Width, 12 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetNextWindow_") 
    ButtonGadget(#G_B_GetPrevWindow, Width - #T1Width, 13 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetPrevWindow_") 
    ButtonGadget(#G_B_MouseOverWindow, Width - #T1Width, 14 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "")
    ;ButtonGadget(#G_B_HideWindow, Width - #T1Width, 15 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "HideWindow_")
    
    AddKeyboardShortcut(0,#PB_Shortcut_Space,32)
    
    Width - 1 
    Repeat 
      If Width <> WindowWidth() Or Height <> WindowHeight() 
        Width = WindowWidth() 
        Height = WindowHeight() 
        ResizeGadget(#G_MainTree, -1, -1, Width - #T1Width - 5, Height - #PanelHeight - 5) 
        ResizeGadget(#G_MainPanel, -1, Height - #PanelHeight, Width - #T1Width - 5, -1) 
        ResizeGadget(#G_Log, -1, -1, Width - #T1Width - 52, -1) 
        ResizeGadget(#G_LogClear, Width - #T1Width - 50, -1, -1, -1) 
        ResizeGadget(#G_WindowInfo, -1, -1, Width - #T1Width - 10, -1) 
        For a.l = #G_B_RefreshMemory To #G_B_DestroyWindow
          If IsGadget(a) 
            ResizeGadget(a, Width - #T1Width, -1, -1, -1) 
          EndIf 
        Next 
      EndIf 
      
      If CountList(Window()) 
        DisableGadget(#G_B_RefreshList, 0) 
      Else 
        DisableGadget(#G_B_RefreshList, 1) 
      EndIf 
      
      If CountGadgetItems(#G_MainTree) 
        DisableGadget(#G_B_OpenAllNodes, 0) 
        DisableGadget(#G_B_GetDesktopWindow, 0) 
        DisableGadget(#G_B_GetForegroundWindow, 0) 
        DisableGadget(#G_B_MouseOverWindow, #False)
      Else 
        DisableGadget(#G_B_OpenAllNodes, 1) 
        DisableGadget(#G_B_GetDesktopWindow, 1) 
        DisableGadget(#G_B_GetForegroundWindow, 1) 
        DisableGadget(#G_B_MouseOverWindow, #True)
      EndIf 
      
      State.l = GetGadgetState(#G_MainTree) 
      
      If State >= 0 
        SelectElement(Window(), State) 
        If Window()\Childs 
          DisableGadget(#G_B_OpenWholeNode, 0) 
        Else 
          DisableGadget(#G_B_OpenWholeNode, 1) 
        EndIf 
        DisableGadget(#G_B_PostQuit, 0) 
        DisableGadget(#G_B_PostClose, 0) 
        
        result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\Process) 
        If result 
          DisableGadget(#G_B_TerminateProcess, 0) 
          CloseHandle_(result) 
        Else 
          DisableGadget(#G_B_TerminateProcess, 0)        
        EndIf 
        
        For a.l = #G_B_CloseWindow To #G_B_DestroyWindow
          If GadgetID(a) : DisableGadget(a, 0) : EndIf 
        Next 
        
        If IsWindow_(Window()\Handle) 
          DisableGadget(#G_B_WindowInfo, 0) 
        Else 
          DisableGadget(#G_B_WindowInfo, 1) 
        EndIf 
        
        DisableGadget(#G_B_GetNextWindow, 0) 
        DisableGadget(#G_B_GetPrevWindow, 0) 
      Else 
        For a.l = #G_B_OpenWholeNode To #G_B_WindowInfo
          If IsGadget(a) : DisableGadget(a, 1) : EndIf 
        Next 
        For a.l = #G_B_GetNextWindow To #G_B_GetPrevWindow
          If IsGadget(a) : DisableGadget(a, 1) : EndIf 
        Next 
      EndIf 
      
      If CountGadgetItems(#G_Log) 
        DisableGadget(#G_LogClear, 0) 
        DisableGadget(#G_Log, 0) 
      Else 
        DisableGadget(#G_LogClear, 1) 
        DisableGadget(#G_Log, 1) 
      EndIf 
      
      If Trim(GetGadgetText(#G_WindowInfo)) = "" 
        DisableGadget(#G_WindowInfo, 1) 
      Else 
        DisableGadget(#G_WindowInfo, 0) 
      EndIf 
      
      GetCursorPos_(@CursorPos.POINT)
      SetGadgetText(#G_B_MouseOverWindow,"MouseOver: $"+Hex( WindowFromPoint_(CursorPos\x,CursorPos\y) ))
      
      EventID.l = WindowEvent() 
      Select EventID 
        Case #PB_EventCloseWindow 
          End 
          
        Case #PB_EventGadget 
          Select EventGadgetID() 
            Case #G_LogClear  ;Clear Log 
              ClearGadgetItemList(#G_Log) 
              
            Case #G_B_RefreshMemory ;Refresh Memory 
              time.l = GetTickCount_() 
              EnumAllWindows() 
              time.l = GetTickCount_() - time 
              AddLog("Enum windows in " + Str(time) + " ms.") 
              AddLog(Str(CountList(Window())) + " windows found") 
              
            Case #G_B_RefreshList ;Refresh List 
              time.l = GetTickCount_() 
              RefreshList(1) 
              time.l = GetTickCount_() - time 
              AddLog("Refresh list in " + Str(time) + " ms.") 
              
            Case #G_B_OpenAllNodes ;Open All Nodes 
              time.l = GetTickCount_() 
              RefreshList(2) 
              time.l = GetTickCount_() - time 
              AddLog("Opened all nodes in " + Str(time) + " ms.") 
              
            Case #G_B_OpenWholeNode ;Open Whole Node 
              time.l = GetTickCount_() 
              RefreshList(8) 
              time.l = GetTickCount_() - time 
              AddLog("Opened whole node in " + Str(time) + " ms.") 
              
            Case #G_B_PostQuit ;Post Quit 
              PostMessage_(Window()\Handle, #WM_QUIT, 0, 0) 
            Case #G_B_PostClose ;Post Close 
              PostMessage_(Window()\Handle, #WM_CLOSE, 0, 0) 
              
            Case #G_B_TerminateProcess ;Terminate Process 
              result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\Process) 
              If result 
                If TerminateProcess_(result, 0) 
                  AddLog("The process with the ID " + Str(Window()\Process) + " was successfully terminated.") 
                  DelProcInList(Window()\Process) 
                  AddLog("List refresh needed") 
                EndIf 
                CloseHandle_(result) 
              EndIf 
              
            Case #G_B_CloseWindow ;CloseWindow_ 
              CloseWindow_(Window()\Handle) 
              
            Case #G_B_DestroyWindow ;DestroyWindow_ 
              DestroyWindow_(Window()\Handle) 
              
            Case #G_B_WindowInfo ;Window Info 
              Text.s = GetWindowInfo(Window()\Handle) 
              SetGadgetText(#G_WindowInfo, Text) 
              SetGadgetState(#G_MainPanel, 1) 
              ActivateGadget(#G_MainTree) 
              
            Case #G_B_GetDesktopWindow ;GetDesktopWindow_ 
              result.l = GetDesktopWindow_() 
              If result 
                SetCursorOnHandle(result) 
              EndIf 
              
            Case #G_B_GetForegroundWindow ;GetForegroundWindow_ 
              result.l = GetForegroundWindow_() 
              If result 
                SetCursorOnHandle(result) 
              EndIf 
              
            Case #G_B_GetNextWindow ;GetNextWindow_ 
              result.l = GetWindow_(Window()\Handle, #GW_HWNDNEXT) 
              If result 
                SetCursorOnHandle(result) 
                AddLog("Handle: " + Str(result)) 
              Else 
                AddLog("No next Window") 
              EndIf 
              
            Case #G_B_GetPrevWindow ;GetPrevWindow_ 
              result.l = GetWindow_(Window()\Handle, #GW_HWNDPREV) 
              If result 
                SetCursorOnHandle(result) 
                AddLog("Handle: " + Str(result)) 
              Else 
                AddLog("No previous Window") 
              EndIf 
              
            Case #G_B_MouseOverWindow
              GetCursorPos_(@CursorPos.POINT)
              SearchWindow( WindowFromPoint_(CursorPos\x,CursorPos\y) )
              
            ;Case #G_B_HideWindow ;HideWindow_ 
            ;  If result 
            ;    DestroyWindow_(result) 
            ;  EndIf 
          EndSelect 
          
        Case #PB_Event_Menu
          Select EventMenuID()
            Case 32
              GetCursorPos_(@CursorPos.POINT)
              SearchWindow( WindowFromPoint_(CursorPos\x,CursorPos\y) )
          EndSelect
        
        Case 0
          Delay(50)
      EndSelect 
    ForEver 
  EndIf 
EndIf 
End
Neues:
- Konstanten anstatt Nummern bei den GadgetIDs (sieht einfach besser aus ;) )
- MouseOverWindow-Button: zeigt das handle des Windows an über dem die Maus ist
- Suche nach dem Window über dem die Maus ist
-- kann man per Buttonklick (bisl Schwachsinn weil die Maus ja dann über dem Button ist) oder Space (Focus muss aber auf dem EnumAllWindows-Proggy liegen) durchführen

Verfasst: 24.02.2005 09:54
von dige
Ich bekomme hier ( WinXPSP2, PB3.93B3 ) die Fehlermeldung
das die Konstante #PROCESS_ALL_ACCESS schon mit einem
anderen Wert vorbelegt ist! Und zwar mit $1F0FFF

Verfasst: 24.02.2005 10:09
von Rings
$1F0FFF ist definitiv richtig !

Verfasst: 23.03.2006 21:19
von Deeem2031
Hab das ganze (da ich es öfters brauche) ma für PB4.00 umgeschrieben und noch ein Feature hinzugefügt, und zwar wird jetzt, wenn man WindowInfo auf ein SysListView32 (ListViewGadget) anwendet, der Inhalt der einzelnen Felder angezeigt (Der Header nich, war auch so kompliziert genug ;) )
Außerdem funzt das mit dem Space -> MouseOver jetzt auch ohne dass das Fenster aktiv ist.

Code: Alles auswählen

Enumeration ;Gadgets
  #G_MainTree
  #G_MainPanel
  #G_Log
  #G_LogClear
  #G_WindowInfo
  
  #G_B_RefreshMemory
  #G_B_RefreshList
  #G_B_OpenAllNodes
  #G_B_OpenWholeNode
  #G_B_PostQuit
  #G_B_PostClose
  #G_B_TerminateProcess
  #G_B_CloseWindow
  #G_B_DestroyWindow
  #G_B_WindowInfo
  #G_B_GetDesktopWindow
  #G_B_GetForegroundWindow
  #G_B_GetNextWindow
  #G_B_GetPrevWindow
  #G_B_SetForegroundWindow
  #G_B_MouseOverWindow
EndEnumeration

Structure Window 
  Childs.l 
  Rekursion.l 
  
  ;Window 
  Handle.l 
  Process.l 
  Name.s 
  Class.s 
EndStructure 

;#PROCESS_ALL_ACCESS = $FFF 
#LVM_GETHEADER = #LVM_FIRST+31

#BufferSize = 2048 

Global LF.s 
LF = Chr(13) + Chr(10) 

Declare RefreshList(Modus.l) 
Declare AddWindow(*tmp.Window) 
Declare EnumAllWindows() 
Declare EnumProc(Handle.l, lParam.l) 
Declare.s GetTitle(Handle) 
Declare.s GetClassName(Handle.l) 

Global NewList Window.Window() 
Global G_MainTree_Node

;- 

Procedure.s GetClassName(Handle.l) 
Class.s = Space(#BufferSize) 
GetClassName_(Handle, @Class, Len(Class)) 
ProcedureReturn Left(Class, Len(Class)) 
EndProcedure 

Procedure.s GetTitle(Handle) 
Name.s = Space(#BufferSize) 
GetWindowText_(Handle, @Name, Len(Name)) 
ProcedureReturn Left(Name, Len(Name)) 
EndProcedure 

Procedure EnumProc(Handle.l, lParam.l) 
  AddElement(Window()) 
  
  Window()\Handle = Handle 
  Window()\Process = 0 
  GetWindowThreadProcessId_(Handle, @Window()\Process) 
  Window()\Name = GetTitle(Handle) 
  Window()\Class = GetClassName(Handle) 
  
  If lParam 
    *tmp.Window = lParam 
    *tmp\Childs + 1 
    Window()\Rekursion = *tmp\Rekursion + 1 
  Else 
    Window()\Rekursion = 0 
  EndIf 
  
  EnumChildWindows_(Handle, @EnumProc(), @Window()) 
  
  ProcedureReturn #True 
EndProcedure 

Procedure EnumAllWindows() 
  Protected TmpL.l 
  ClearList(Window()) 
  TmpL = EnumWindows_(@EnumProc(), 0) 
EndProcedure 

;- 

Procedure AddWindow(*tmp.Window)
  Handle.l = *tmp\Handle 
  ClassName.s = *tmp\Class 
  ProcessID.l = *tmp\Process 
  name.s = *tmp\name 
  Childs.l = *tmp\Childs 
  ;AddGadgetItem(#G_MainTree, -1, "Handle: " + Str(Handle) + ", Process ID: " + Str(ProcessID) + ", Name: " + Chr(34) + Name + Chr(34) + ", Class Name: " + Chr(34) + ClassName + Chr(34)) 
  AddGadgetItem(#G_MainTree, -1, name + " (" + ClassName + ") [" + Right("0000000" + Hex(Handle), 8) + ", " + Right("0000000" + Hex(ProcessID), 8) + "] + <" + Str(Childs) + ">",0,G_MainTree_Node) 
EndProcedure 

Procedure AddNodeToList() 
  AddWindow(@Window()) 
  If Window()\Childs 
    G_MainTree_Node + 1
    Childs = Window()\Childs 
    For a.l = 1 To Childs 
      NextElement(Window()) 
      AddNodeToList() 
    Next 
    G_MainTree_Node - 1
  EndIf 
EndProcedure 

Procedure RefreshList(Modus.l) 
  If Modus & 1 
    SetWindowCallback(0) 
    HideGadget(#G_MainTree,#True)
    While WindowEvent() : Wend 
    ClearGadgetItemList(#G_MainTree) 
    ResetList(Window()) 
    While NextElement(Window()) 
      AddNodeToList() 
    Wend 
    HideGadget(#G_MainTree,#False)    
    While WindowEvent() : Wend 
  EndIf 
  
  If Modus & 2 
    State.l = GetGadgetState(#G_MainTree) 
    ResetList(Window()) 
    c.l = 0 
    While NextElement(Window()) 
      If Window()\Childs > 0 
        SetGadgetItemState(#G_MainTree, c, #PB_Tree_Expanded) 
      EndIf 
      c + 1 
    Wend 
    SetGadgetState(#G_MainTree, State) 
  EndIf 
  
  If Modus & 8 
    State.l = GetGadgetState(#G_MainTree) 
    If State >= 0 
      SelectElement(Window(), State) 
      Rek.l = Window()\Rekursion 
      c.l = State 
      Repeat 
        If Window()\Childs > 0 
          SetGadgetItemState(#G_MainTree, c, #PB_Tree_Expanded) 
        EndIf 
        c + 1 
      Until NextElement(Window()) = 0 Or (Window()\Rekursion = Rek And c > State) 
      SetGadgetState(#G_MainTree, State) 
    EndIf 
  EndIf 
  
EndProcedure 

Procedure DelProcInList(Process.l) 
  ResetList(Window()) 
  While NextElement(Window()) 
    If Window()\Process = Process 
      DeleteElement(Window()) 
    EndIf 
  Wend 
EndProcedure 

Procedure SearchWindow(hwnd.l)
  Protected Pos.l,found.l
  
  ResetList(Window())
  While NextElement(Window())
    If Window()\Handle = hwnd
      found = #True
      Break 1
    EndIf
    Pos + 1
    If Window()\Childs 
      For a.l = 1 To Window()\Childs
        NextElement(Window())
        If Window()\Handle = hwnd
          found = #True
          Break 2
        EndIf
        Pos + 1
      Next 
    EndIf 
  Wend
  
  If found
    SetGadgetState(#G_MainTree,Pos)
  EndIf
  
  ProcedureReturn found
EndProcedure

Procedure.s rgState(dword.l) 
#STATE_SYSTEM_FOCUSABLE = $00100000 
#STATE_SYSTEM_INVISIBLE = $8000 
#STATE_SYSTEM_OFFSCREEN = $10000 
#STATE_SYSTEM_UNAVAILABLE = $1 
#STATE_SYSTEM_PRESSED = $08 

Text.s = "" 
If dword & #STATE_SYSTEM_FOCUSABLE 
  Text = Text + "can accept the focus, " 
EndIf 
If dword & #STATE_SYSTEM_INVISIBLE 
  Text = Text + "invisible, " 
EndIf 
If dword & #STATE_SYSTEM_OFFSCREEN 
  Text = Text + "no visible representation, " 
EndIf 
If dword & #STATE_SYSTEM_UNAVAILABLE 
  Text = Text + "unavailable, " 
EndIf 
If dword & #STATE_SYSTEM_PRESSED 
  Text = Text + "pressed, " 
EndIf 

If Text 
  Text = Left(Text, Len(Text) - 2) 
Else 
  Text = "n/a" 
EndIf 
ProcedureReturn Text 
EndProcedure 

Procedure.s dwStyle(dword.l) 
Text.s = "" 
If dword & #WS_BORDER 
  Text = Text + "thin-line border, " 
EndIf 
If dword & #WS_CAPTION 
  Text = Text + "title bar, " 
EndIf 
If dword & #WS_CHILD 
  Text = Text + "child, " 
EndIf 
If dword & #WS_CHILDWINDOW 
  Text = Text + "child, " 
EndIf 
If dword & #WS_CLIPCHILDREN 
  Text = Text + "#WS_CLIPCHILDREN, " 
EndIf 
If dword & #WS_CLIPSIBLINGS 
  Text = Text + "#WS_CLIPSIBLINGS, " 
EndIf 
If dword & #WS_DISABLED 
  Text = Text + "disabled, " 
EndIf 
If dword & #WS_DLGFRAME 
  Text = Text + "#WS_DLGFRAME, " 
EndIf 
If dword & #WS_GROUP 
  Text = Text + "first group control, " 
EndIf 
If dword & #WS_HSCROLL 
  Text = Text + "horizontal scroll bar, " 
EndIf 
If dword & #WS_ICONIC 
  Text = Text + "minimized, " 
EndIf 
If dword & #WS_MAXIMIZE 
  Text = Text + "maximized, " 
EndIf 
If dword & #WS_MAXIMIZEBOX 
  Text = Text + "maximize button, " 
EndIf 
If dword & #WS_OVERLAPPED 
  Text = Text + "overlapped, " 
EndIf 
If dword & #WS_OVERLAPPEDWINDOW 
  Text = Text + "overlapped, " 
EndIf 
If dword & #WS_POPUP 
  Text = Text + "pop-up, " 
EndIf 
If dword & #WS_POPUPWINDOW 
  Text = Text + "pop-up, " 
EndIf 
If dword & #WS_SIZEBOX 
  Text = Text + "sizing border, " 
EndIf 
If dword & #WS_SYSMENU 
  Text = Text + "system menu, " 
EndIf 
If dword & #WS_TABSTOP 
  Text = Text + "TAB navigation, " 
EndIf 
If dword & #WS_THICKFRAME 
  Text = Text + "sizing border, " 
EndIf 
If dword & #WS_TILED 
  Text = Text + "overlapped, " 
EndIf 
If dword & #WS_TILEDWINDOW 
  Text = Text + "overlapped, " 
EndIf 
If dword & #WS_VISIBLE 
  Text = Text + "visible, " 
EndIf 
If dword & #WS_VSCROLL 
  Text = Text + "vertical scroll bar, " 
EndIf 

If Text 
  Text = Left(Text, Len(Text) - 2) 
Else 
  Text = "n/a" 
EndIf 
ProcedureReturn Text 
EndProcedure 

Procedure.s dwExStyle(dword.l) 
#WS_EX_COMPOSITED = $02000000 
#WS_EX_LAYERED = $80000 
#WS_EX_LAYOUTRTL = $400000 
#WS_EX_NOACTIVATE = $8000000 
#WS_EX_NOINHERITLAYOUT = $100000 

Text.s = "" 
If dword & #WS_EX_ACCEPTFILES 
  Text = Text + "accept drag-drop files, " 
EndIf 
If dword & #WS_EX_APPWINDOW 
  Text = Text + "taskbar window, " 
EndIf 
If dword & #WS_EX_CLIENTEDGE 
  Text = Text + "sunken edge border, " 
EndIf 
If dword & #WS_EX_COMPOSITED 
  Text = Text + "#WS_EX_COMPOSITED, " 
EndIf 
If dword & #WS_EX_CONTEXTHELP 
  Text = Text + "question mark button, " 
EndIf 
If dword & #WS_EX_CONTROLPARENT 
  Text = Text + "#WS_EX_CONTROLPARENT, " 
EndIf 
If dword & #WS_EX_DLGMODALFRAME 
  Text = Text + "double border, " 
EndIf 
If dword & #WS_EX_LAYERED 
  Text = Text + "layred, " 
EndIf 
If dword & #WS_EX_LAYOUTRTL 
  Text = Text + "Arabic/Hebrew, " 
EndIf 
If dword & #WS_EX_LEFT 
  Text = Text + "left-aligned, " 
EndIf 
If dword & #WS_EX_LEFTSCROLLBAR 
  Text = Text + "left scroll bar, " 
EndIf 
If dword & #WS_EX_LTRREADING 
  Text = Text + "left-to-right reading, " 
EndIf 
If dword & #WS_EX_MDICHILD 
  Text = Text + "MDI child, " 
EndIf 
If dword & #WS_EX_NOACTIVATE 
  Text = Text + "#WS_EX_NOACTIVATE, " 
EndIf 
If dword & #WS_EX_NOINHERITLAYOUT 
  Text = Text + "#WS_EX_NOINHERITLAYOUT, " 
EndIf 
If dword & #WS_EX_NOPARENTNOTIFY 
  Text = Text + "no #WS_PARENTNOTIFY message, " 
EndIf 
If dword & #WS_EX_OVERLAPPEDWINDOW 
  Text = Text + "" 
EndIf 
If dword & #WS_EX_PALETTEWINDOW 
  Text = Text + "" 
EndIf 
If dword & #WS_EX_RIGHT 
  Text = Text + "right-aligned, " 
EndIf 
If dword & #WS_EX_RIGHTSCROLLBAR 
  Text = Text + "right scroll bar, " 
EndIf 
If dword & #WS_EX_RTLREADING 
  Text = Text + "right-to-left reading, " 
EndIf 
If dword & #WS_EX_STATICEDGE 
  Text = Text + "3D border, " 
EndIf 
If dword & #WS_EX_TOOLWINDOW 
  Text = Text + "tool window, " 
EndIf 
If dword & #WS_EX_TOPMOST 
  Text = Text + "topmost, " 
EndIf 
If dword & #WS_EX_TRANSPARENT 
  Text = Text + "transparent, " 
EndIf 
If dword & #WS_EX_WINDOWEDGE 
  Text = Text + "raised edge, " 
EndIf 

If Text 
  Text = Left(Text, Len(Text) - 2) 
Else 
  Text = "n/a" 
EndIf 
ProcedureReturn Text 
EndProcedure 

Procedure.s Placement_flags(dword.l) 
#WPF_ASYNCWINDOWPLACEMENT = $4 
#WPF_RESTORETOMAXIMIZED = $2 
#WPF_SETMINPOSITION = $1 

Text.s = "" 
If dword & #WPF_ASYNCWINDOWPLACEMENT 
  Text = Text + "#WPF_ASYNCWINDOWPLACEMENT, " 
EndIf 
If dword & #WPF_RESTORETOMAXIMIZED 
  Text = Text + "#WPF_RESTORETOMAXIMIZED, " 
EndIf 
If dword & #WPF_SETMINPOSITION 
  Text = Text + "#WPF_SETMINPOSITION, " 
EndIf 

If Text 
  Text = Left(Text, Len(Text) - 2) 
Else 
  Text = "n/a" 
EndIf 
ProcedureReturn Text 
EndProcedure 

Procedure.s Placement_showCmd(dword.l) 
Text.s = "" 
If dword & #SW_HIDE 
  Text = Text + "hide, " 
EndIf 
If dword & #SW_MAXIMIZE 
  Text = Text + "maximize, " 
EndIf 
If dword & #SW_MINIMIZE 
  Text = Text + "minimize, " 
EndIf 
If dword & #SW_RESTORE 
  Text = Text + "restore, " 
EndIf 
If dword & #SW_SHOW 
  Text = Text + "show, " 
EndIf 
If dword & #SW_SHOWMAXIMIZED 
  Text = Text + "show maxmized, " 
EndIf 
If dword & #SW_SHOWMINIMIZED 
  Text = Text + "show minimized, " 
EndIf 
If dword & #SW_SHOWMINNOACTIVE 
  Text = Text + "show no active, " 
EndIf 
If dword & #SW_SHOWNA 
  Text = Text + "show (na), " 
EndIf 
If dword & #SW_SHOWNOACTIVATE 
  Text = Text + "show no activate, " 
EndIf 
If dword & #SW_SHOWNORMAL 
  Text = Text + "show normal, " 
EndIf 

If Text 
  Text = Left(Text, Len(Text) - 2) 
Else 
  Text = "n/a" 
EndIf 
ProcedureReturn Text 
EndProcedure 



Procedure.s GetWindowInfo(Handle.l) 
Text.s = "Info about " + Hex(Handle) + ":" + LF + LF 
If Handle 
  ;Width and height 
  If GetClientRect_(Handle, @size.RECT) 
    Text = Text + "GetClientRect_:" + LF 
    Text = Text + "W" + Str(size\right) + "x" + Str(size\bottom) + LF + LF 
  EndIf 
  
  ;GetTitleBarInfo_() 
  Structure TITLEBARINFO 
    cbSize.l 
    rcTitleBar.RECT 
    rgState.l[6] 
  EndStructure 
  
  TitleBar.TITLEBARINFO 
  TitleBar\cbSize = SizeOf(TITLEBARINFO) 
  If GetTitleBarInfo_(Handle, @TitleBar) 
    Text = Text + "GetTitleBarInfo_:" + LF 
    Text = Text + "Rect: L" + Str(TitleBar\rcTitleBar\left) + ", T" + Str(TitleBar\rcTitleBar\top) 
    Text = Text + ", R" + Str(TitleBar\rcTitleBar\right) + ", B" + Str(TitleBar\rcTitleBar\bottom) + LF 
    Text = Text + "Elements:" + LF 
    Text = Text + "Title bar itself: " + rgState(TitleBar\rgState[0]) + LF 
    Text = Text + "Minimize Button: " + rgState(TitleBar\rgState[2]) + LF 
    Text = Text + "Maximize Button: " + rgState(TitleBar\rgState[3]) + LF 
    Text = Text + "Help Button: " + rgState(TitleBar\rgState[4]) + LF 
    Text = Text + "Close Button: " + rgState(TitleBar\rgState[5]) + LF + LF 
  EndIf 
  
  ;GetWindowInfo_ 
  #WS_ACTIVECAPTION = $1 
  Structure WINDOWINFO 
    cbSize.l 
    rcWindow.RECT 
    rcClient.RECT 
    dwStyle.l 
    dwExStyle.l 
    dwWindowStatus.l 
    cxWindowBorders.l 
    cyWindowBorders.l 
    AtomWindowType.l 
    wCreatorVersion.w 
  EndStructure 
  
  WindowInfo.WINDOWINFO 
  WindowInfo\cbSize = SizeOf(WINDOWINFO) 
  If GetWindowInfo_(Handle, @WindowInfo) 
    Text = Text + "GetWindowInfo_:" + LF 
    Text = Text + "Window Rect: L" + Str(WindowInfo\rcWindow\left) + ", T" + Str(WindowInfo\rcWindow\top) 
    Text = Text + ", R" + Str(WindowInfo\rcWindow\right) + ", B" + Str(WindowInfo\rcWindow\bottom) + LF 
    Text = Text + "Client Rect: L" + Str(WindowInfo\rcClient\left) + ", T" + Str(WindowInfo\rcClient\top) 
    Text = Text + ", R" + Str(WindowInfo\rcClient\right) + ", B" + Str(WindowInfo\rcClient\bottom) + LF 
    Text = Text + "Style: " + dwStyle(WindowInfo\dwStyle) + LF 
    Text = Text + "Ex Style: " + dwExStyle(WindowInfo\dwExStyle) + LF 
    Text = Text + "Status: " 
    If WindowInfo\dwWindowStatus & #WS_ACTIVECAPTION 
      Text = Text + "activated" + LF 
    Else 
      Text = Text + "deactivated" + LF 
    EndIf 
    Text = Text + "Border width: " + Str(WindowInfo\cxWindowBorders) + LF 
    Text = Text + "Border height: " + Str(WindowInfo\cyWindowBorders) + LF 
    Text = Text + "Windows version: " + Str(WindowInfo\wCreatorVersion) + LF + LF 
  EndIf 
  
  ;GetModuleFileName_ 
  ModuleName.s = Space(1024) 
  If GetModuleFileName_(Handle, ModuleName, 1024) 
    Text = Text + "GetModuleFileName_:" + LF 
    Text = Text + ModuleName + LF + LF 
  EndIf 
  
  ;GetWindowPlacement_ 
  Placement.WINDOWPLACEMENT 
  Placement\Length = SizeOf(WINDOWPLACEMENT) 
  If GetWindowPlacement_(Handle, @Placement) 
    Text = Text + "GetWindowPlacement_:" + LF 
    Text = Text + "Flags: " + Placement_flags(Placement\flags) + LF 
    Text = Text + "Show state: " + Placement_showCmd(Placement\showCmd) + LF 
    Text = Text + "Min Position: " + Str(Placement\ptMinPosition\x) + "x" + Str(Placement\ptMinPosition\y) + LF 
    Text = Text + "Max Position: " + Str(Placement\ptMaxPosition\x) + "x" + Str(Placement\ptMaxPosition\y) + LF 
    Text = Text + "Normal Position: L" + Str(Placement\rcNormalPosition\left) + ", T" + Str(Placement\rcNormalPosition\top) 
    Text = Text + ", R" + Str(Placement\rcNormalPosition\right) + ", B" + Str(Placement\rcNormalPosition\bottom) + LF + LF 
  EndIf 
  
  ;IsWindowUnicode_ 
  Text = Text + "IsWindowUnicode_: " 
  If IsWindowUnicode_(Handle) 
    Text = Text + "yes" 
  Else 
    Text = Text + "no" 
  EndIf 
  Text = Text + LF + LF 
  
  Text + "ClassName: "+GetClassName(handle) + LF + LF 
  If LCase(GetClassName(handle)) = LCase("SysListView32")
    Text + "WindowContent: " + LF + LF 
    
    ;hProcess = OpenProcess_(#PROCESS_VM_OPERATION, #True, Window()\Process) 
    hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\Process) 
    If hProcess
              
      tmpItemCount = SendMessage_(handle,#LVM_GETITEMCOUNT,0,0)
      hHeader = SendMessage_(handle,#LVM_GETHEADER,0,0)
   	  tmpSubItemCount = SendMessage_(hHeader,#HDM_GETITEMCOUNT,0,0)
  	   
      tmpItem.LVITEM
      *tmpItem.LVITEM = VirtualAllocEx_(hProcess,#Null,SizeOf(LVITEM),#MEM_COMMIT, #PAGE_READWRITE)
      If *tmpItem
      
        tmpItem\pszText = VirtualAllocEx_(hProcess,#Null,256,#MEM_COMMIT, #PAGE_READWRITE)
        local_pszText = AllocateMemory(256)
        If tmpItem\pszText And local_pszText
          tmpItem\cchTextMax = 255
          tmpItem\mask = #LVIF_TEXT
          Content.s = ""
          For i = 0 To tmpItemCount-1
            ;RtlZeroMemory_(tmpItem\pszText,tmpItem\cchTextMax)
            tmpItem\iItem = i
            For i2 = 0 To tmpSubItemCount-1
              tmpItem\iSubItem = i2
              WriteProcessMemory_(hProcess,*tmpItem,tmpitem,SizeOf(LVITEM),#Null)
              tmpStringLen = SendMessage_(handle,#LVM_GETITEMTEXT,i,*tmpItem)
              ReadProcessMemory_(hProcess,*tmpItem,tmpitem,SizeOf(LVITEM),#Null)
          
              ReadProcessMemory_(hProcess,tmpitem\pszText,local_pszText,256,#Null)
              Content + PeekS(local_pszText,tmpStringLen) + " | "
            Next
            Content = Left(Content,Len(Content)-3)
            Content + LF
          Next
          Text + Content
          VirtualFreeEx_(hProcess,tmpItem\pszText,256,#MEM_DECOMMIT)
          FreeMemory(local_pszText)
        Else
          Text + "Can't allocate memory" + LF + LF
        EndIf
        VirtualFreeEx_(hProcess,*tmpItem,SizeOf(LVITEM),#MEM_DECOMMIT)
      Else
        Text + "Can't allocate memory" + LF + LF
      EndIf
      CloseHandle_(hProcess) 
    Else
      Text + "Access denied" + LF + LF
    EndIf 
  Else
    Text + "WindowTitle: "+GetTitle(handle) + LF + LF 
  EndIf
  
Else 
  Text.s = "No info available" 
EndIf 
ProcedureReturn Text 
EndProcedure 

;- 

Procedure SetGadgetStateLI(Gadget.l, State.l) 
  Protected a.l 
  For a = 0 To CountGadgetItems(Gadget) - 1 
    If a = State 
      SetGadgetItemState(Gadget, a, #PB_ListIcon_Selected) 
    Else 
      SetGadgetItemState(Gadget, a, 0) 
    EndIf 
  Next 
  SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, State, 1) 
EndProcedure 

Procedure SetCursorOnHandle(Handle.l) 
  ResetList(Window()) 
  While NextElement(Window()) 
    If Window()\Handle = Handle 
      
      If Window()\Rekursion 
        Rek.l = Window()\Rekursion 
        While PreviousElement(Window()) And Window()\Rekursion 
          If Window()\Rekursion < Rek 
            SetGadgetItemState(#G_MainTree, ListIndex(Window()) - 1, #PB_Tree_Expanded) 
            Rek = Window()\Rekursion 
          EndIf 
        Wend 
        SetGadgetItemState(#G_MainTree, ListIndex(Window()) - 1, #PB_Tree_Expanded) 
      EndIf 
      SetGadgetState(#G_MainTree, ListIndex(Window()) - 1) 
      ProcedureReturn #True 
    EndIf 
  Wend 
  ProcedureReturn #False 
EndProcedure 

Procedure AddLog(Text.s) 
  State.l = CountGadgetItems(#G_Log) 
  Zeit.s = FormatDate("%hh:%ii:%ss", Date()) 
  AddGadgetItem(#G_Log, State, Zeit) 
  SetGadgetItemText(#G_Log, State, Text, 1) 
  SetGadgetStateLI(#G_Log, State) 
EndProcedure 

Width.l = 800 
Height.l = 600 

If OpenWindow(0, 0, 0, Width, Height, "AllWindows and Childs", #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget) 
  If CreateGadgetList(WindowID(0)) 
    #T1Width = 140 
    #TextHeight = 16 
    #ButtonHeight = 18 
    #StrHeight = 200 
    #Abs = 5 
    #PanelHeight = 200 
    
    TreeGadget(#G_MainTree, 0, 0, Width - #T1Width - 5, Height - #PanelHeight - 5, #PB_Tree_AlwaysShowSelection | #PB_Tree_NoLines)    
    
    PanelGadget(#G_MainPanel, 0, Height - #PanelHeight, Width - #T1Width - 5, #PanelHeight) 
    AddGadgetItem(#G_MainPanel, 0, "Log") 
    ListIconGadget(#G_Log, 0, 0, Width - #T1Width - 52, #PanelHeight - 25, "Zeit", 100, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_FullRowSelect) 
    AddGadgetColumn(#G_Log, 1, "Log", 1000) 
    ButtonGadget(#G_LogClear, Width - #T1Width - 50, 0, 40, #PanelHeight - 25, "Clear") 
    AddGadgetItem(#G_MainPanel, 1, "Window Info") 
    StringGadget(#G_WindowInfo, 0, 0, Width - #T1Width - 10, #PanelHeight - 25, "", #ES_MULTILINE | #WS_VSCROLL | #WS_HSCROLL) 
    CloseGadgetList() 
    
    ButtonGadget(#G_B_RefreshMemory, Width - #T1Width, 0 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh Memory") 
    ButtonGadget(#G_B_RefreshList, Width - #T1Width, 1 * #ButtonHeight + 0 * #Abs, #T1Width, #ButtonHeight, "Refresh List") 
    
    ButtonGadget(#G_B_OpenAllNodes, Width - #T1Width, 2 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open All Nodes") 
    ButtonGadget(#G_B_OpenWholeNode, Width - #T1Width, 3 * #ButtonHeight + 1 * #Abs, #T1Width, #ButtonHeight, "Open Whole Node") 
    
    
    ButtonGadget(#G_B_PostQuit, Width - #T1Width, 4 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Quit") 
    ButtonGadget(#G_B_PostClose, Width - #T1Width, 5 * #ButtonHeight + 3 * #Abs, #T1Width, #ButtonHeight, "Post Close") 
    
    ButtonGadget(#G_B_TerminateProcess, Width - #T1Width, 6 * #ButtonHeight + 4 * #Abs, #T1Width, #ButtonHeight, "Terminate Process") 
    
    ButtonGadget(#G_B_CloseWindow, Width - #T1Width, 7 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "CloseWindow_") 
    ButtonGadget(#G_B_DestroyWindow, Width - #T1Width, 8 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "DestroyWindow_") 
    ButtonGadget(#G_B_WindowInfo, Width - #T1Width, 9 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "Window Info") 
    ButtonGadget(#G_B_GetDesktopWindow, Width - #T1Width, 10 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetDesktopWindow_") 
    ButtonGadget(#G_B_GetForegroundWindow, Width - #T1Width, 11 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetForegroundWindow_") 
    ButtonGadget(#G_B_GetNextWindow, Width - #T1Width, 12 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetNextWindow_") 
    ButtonGadget(#G_B_GetPrevWindow, Width - #T1Width, 13 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "GetPrevWindow_") 
    ButtonGadget(#G_B_SetForegroundWindow, Width - #T1Width, 14 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "SetForegroundWindow_") 
    ButtonGadget(#G_B_MouseOverWindow, Width - #T1Width, 15 * #ButtonHeight + 6 * #Abs, #T1Width, #ButtonHeight, "")
    
    Repeat 
      If Width <> WindowWidth(0) Or Height <> WindowHeight(0) 
        Width = WindowWidth(0) 
        Height = WindowHeight(0) 
        ResizeGadget(#G_MainTree, #PB_Ignore, #PB_Ignore, Width - #T1Width - 5, Height - #PanelHeight - 5) 
        ResizeGadget(#G_MainPanel, #PB_Ignore, Height - #PanelHeight, Width - #T1Width - 5, #PB_Ignore) 
        ResizeGadget(#G_Log, #PB_Ignore, #PB_Ignore, Width - #T1Width - 52, #PB_Ignore) 
        ResizeGadget(#G_LogClear, Width - #T1Width - 50, #PB_Ignore, #PB_Ignore, #PB_Ignore) 
        ResizeGadget(#G_WindowInfo, #PB_Ignore, #PB_Ignore, Width - #T1Width - 10, #PB_Ignore) 
        For a.l = #G_B_RefreshMemory To #G_B_MouseOverWindow
          If IsGadget(a) 
            ResizeGadget(a, Width - #T1Width, #PB_Ignore, #PB_Ignore, #PB_Ignore) 
          EndIf 
        Next 
      EndIf 
      
      If CountList(Window()) 
        DisableGadget(#G_B_RefreshList, #False) 
      Else 
        DisableGadget(#G_B_RefreshList, #True) 
      EndIf 
      
      If CountGadgetItems(#G_MainTree) 
        DisableGadget(#G_B_OpenAllNodes       , #False) 
        DisableGadget(#G_B_GetDesktopWindow   , #False) 
        DisableGadget(#G_B_GetForegroundWindow, #False) 
        DisableGadget(#G_B_MouseOverWindow    , #False)
      Else 
        DisableGadget(#G_B_OpenAllNodes       , #True) 
        DisableGadget(#G_B_GetDesktopWindow   , #True) 
        DisableGadget(#G_B_GetForegroundWindow, #True) 
        DisableGadget(#G_B_MouseOverWindow    , #True)
      EndIf 
      
      State.l = GetGadgetState(#G_MainTree) 
      
      If State >= 0 
        SelectElement(Window(), State) 
        If Window()\Childs 
          DisableGadget(#G_B_OpenWholeNode, #False) 
        Else 
          DisableGadget(#G_B_OpenWholeNode, #True) 
        EndIf 
        DisableGadget(#G_B_PostQuit , #False) 
        DisableGadget(#G_B_PostClose, #False) 
        
        result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\Process) 
        If result 
          DisableGadget(#G_B_TerminateProcess, #False) 
          CloseHandle_(result) 
        Else 
          DisableGadget(#G_B_TerminateProcess, #False)
        EndIf 
        
        For a.l = #G_B_CloseWindow To #G_B_DestroyWindow
          If GadgetID(a) : DisableGadget(a, #False) : EndIf 
        Next 
        
        If IsWindow_(Window()\Handle) 
          DisableGadget(#G_B_WindowInfo, #False) 
        Else 
          DisableGadget(#G_B_WindowInfo, #True) 
        EndIf 
        
        DisableGadget(#G_B_GetNextWindow, #False) 
        DisableGadget(#G_B_GetPrevWindow, #False) 
        DisableGadget(#G_B_SetForegroundWindow, #False)
      Else 
        For a.l = #G_B_OpenWholeNode To #G_B_WindowInfo
          If IsGadget(a) : DisableGadget(a, #True) : EndIf 
        Next 
        For a.l = #G_B_GetNextWindow To #G_B_GetPrevWindow
          If IsGadget(a) : DisableGadget(a, #True) : EndIf 
        Next 
        DisableGadget(#G_B_SetForegroundWindow, #True) 
      EndIf 
      
      If CountGadgetItems(#G_Log) 
        DisableGadget(#G_LogClear, #False) 
        DisableGadget(#G_Log, #False) 
      Else 
        DisableGadget(#G_LogClear, #True) 
        DisableGadget(#G_Log, #True) 
      EndIf 
      
      If Trim(GetGadgetText(#G_WindowInfo)) = "" 
        DisableGadget(#G_WindowInfo, #True) 
      Else 
        DisableGadget(#G_WindowInfo, #False) 
      EndIf 
      
      GetCursorPos_(@CursorPos.POINT)
      SetGadgetText(#G_B_MouseOverWindow,"MouseOver: $"+Hex( WindowFromPoint_(CursorPos\x,CursorPos\y) ))
      
      EventID.l = WindowEvent() 
      Select EventID 
        Case #PB_Event_CloseWindow 
          End 
          
        Case #PB_Event_Gadget 
          Select EventGadget() 
            Case #G_LogClear  ;Clear Log 
              ClearGadgetItemList(#G_Log) 
              
            Case #G_B_RefreshMemory ;Refresh Memory 
              time.l = GetTickCount_() 
              EnumAllWindows() 
              time.l = GetTickCount_() - time 
              AddLog("Enum windows in " + Str(time) + " ms.") 
              AddLog(Str(CountList(Window())) + " windows found") 
              
            Case #G_B_RefreshList ;Refresh List 
              time.l = GetTickCount_() 
              RefreshList(1) 
              time.l = GetTickCount_() - time 
              AddLog("Refresh list in " + Str(time) + " ms.") 
              
            Case #G_B_OpenAllNodes ;Open All Nodes 
              time.l = GetTickCount_() 
              RefreshList(2) 
              time.l = GetTickCount_() - time 
              AddLog("Opened all nodes in " + Str(time) + " ms.") 
              
            Case #G_B_OpenWholeNode ;Open Whole Node 
              time.l = GetTickCount_() 
              RefreshList(8) 
              time.l = GetTickCount_() - time 
              AddLog("Opened whole node in " + Str(time) + " ms.") 
              
            Case #G_B_PostQuit ;Post Quit 
              PostMessage_(Window()\Handle, #WM_QUIT, 0, 0) 
            Case #G_B_PostClose ;Post Close 
              PostMessage_(Window()\Handle, #WM_CLOSE, 0, 0) 
              
            Case #G_B_TerminateProcess ;Terminate Process 
              result.l = OpenProcess_(#PROCESS_ALL_ACCESS, #True, Window()\Process) 
              If result 
                If TerminateProcess_(result, 0) 
                  AddLog("The process with the ID " + Str(Window()\Process) + " was successfully terminated.") 
                  DelProcInList(Window()\Process) 
                  AddLog("List refresh needed") 
                EndIf 
                CloseHandle_(result) 
              EndIf 
              
            Case #G_B_CloseWindow ;CloseWindow_ 
              CloseWindow_(Window()\Handle) 
              
            Case #G_B_DestroyWindow ;DestroyWindow_ 
              DestroyWindow_(Window()\Handle) 
              
            Case #G_B_WindowInfo ;Window Info 
              text.s = GetWindowInfo(Window()\Handle) 
              SetGadgetText(#G_WindowInfo, text) 
              SetGadgetState(#G_MainPanel, 1) 
              SetActiveGadget(#G_MainTree) 
              
            Case #G_B_GetDesktopWindow ;GetDesktopWindow_ 
              result.l = GetDesktopWindow_() 
              If result 
                ;SetCursorOnHandle(result) 
                SearchWindow(result)
              EndIf 
              
            Case #G_B_GetForegroundWindow ;GetForegroundWindow_ 
              result.l = GetForegroundWindow_() 
              If result 
                ;SetCursorOnHandle(result) 
                SearchWindow(result)
              EndIf 
              
            Case #G_B_GetNextWindow ;GetNextWindow_ 
              result.l = GetWindow_(Window()\Handle, #GW_HWNDNEXT) 
              If result 
                SetCursorOnHandle(result) 
                AddLog("Handle: " + Str(result)) 
              Else 
              AddLog("No next Window") 
            EndIf 
            
          Case #G_B_GetPrevWindow ;GetPrevWindow_ 
            result.l = GetWindow_(Window()\Handle, #GW_HWNDPREV) 
            If result 
              SetCursorOnHandle(result) 
              AddLog("Handle: " + Str(result)) 
            Else 
              AddLog("No previous Window") 
            EndIf 
            
          Case #G_B_MouseOverWindow
            GetCursorPos_(@CursorPos.POINT)
            SearchWindow( WindowFromPoint_(CursorPos\x,CursorPos\y) )
            
          Case #G_B_SetForegroundWindow
            SetForegroundWindow_(Window()\Handle) 
            
            ;Case #G_B_HideWindow ;HideWindow_ 
            ;  If result 
            ;    DestroyWindow_(result) 
            ;  EndIf 
        EndSelect 
        
      Case 0
        If GetKeyState_(' ') & $F0000000
          GetCursorPos_(@CursorPos.POINT)
          SearchWindow( WindowFromPoint_(CursorPos\x,CursorPos\y) )          
        Else
          Delay(50)
        EndIf
    EndSelect 
  ForEver 
EndIf 
EndIf
Als Exe gibts das ganze auch hier: http://www.deeem2031.de/PB/Nic-Windows-V4.exe

Verfasst: 27.03.2006 21:59
von NicTheQuick
Schön! :D

Ich brauche das Programm eigentlich sehr selten. Das war damals eher
so ein Spaßprojekt, weil ich unbedingt Window-Enumerations
ausprobieren wollte. <)

Aber gut, das es wo anders mehr genutzt wird und sogar weiterentwickelt
wird. :allright: