Visible Windows List [Windows]

Share your advanced PureBasic knowledge/code with the community.
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Visible Windows List [Windows]

Post by oryaaaaa »

Code: Select all

Structure FindWindowData
  hFW.l ; variable to store a handle
  sFW.s ; variable to store a Window name
  cFW.s ; variable to store a window class name
  px.l
  py.l
  height.l
  width.l
EndStructure

Global NewList FindWindow.FindWindowData()

Procedure.l EnumWindowsProc(hFind, lParam)
  Protected WindowName.s = Space(255)
  Protected WindowClass.s = Space(255)
  Protected WP.WINDOWPLACEMENT
  ClearStructure(@WP, WINDOWPLACEMENT)
  WP\length = SizeOf(WINDOWPLACEMENT)
  If GetWindowText_(hFind, WindowName, 255)
    Result = GetClassName_(hFind, WindowClass, 255)
    ;    If FindString(WindowClass, "WindowClass_", 0)
    If GetWindowPlacement_(hFind, @WP)
      If WP\showCmd=1 And IsWindowVisible_(hFind) And WindowClass<>"Button" And WindowClass<>"Progman"
        AddElement(FindWindow())
        FindWindow()\hFW = hFind
        FindWindow()\sFW = WindowName
        FindWindow()\cFW = WindowClass
        FindWindow()\px    = WP\rcNormalPosition\left
        FindWindow()\py    = WP\rcNormalPosition\top
        FindWindow()\height =  WP\rcNormalPosition\bottom-WP\rcNormalPosition\top-2*GetSystemMetrics_(#SM_CYFRAME)-GetSystemMetrics_(#SM_CYCAPTION)
        FindWindow()\width = WP\rcNormalPosition\right-WP\rcNormalPosition\left-2*GetSystemMetrics_(#SM_CXFRAME)
      EndIf
    EndIf
    ;  EndIf
  EndIf
  ProcedureReturn 1
EndProcedure

If EnumWindows_(@EnumWindowsProc(), 0)
  CallDebugger
EndIf
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Visible Windows List [Windows]

Post by IdeasVacuum »

A very nice code example oryaaaaa, thank you for sharing.

Code: Select all

If EnumWindows_(@EnumWindowsProc(), 0)
  
   FirstElement(FindWindow.FindWindowData())
  
         For i = 1 To ListSize(FindWindow.FindWindowData())
    
                 Debug FindWindow.FindWindowData()\sFW
                 Debug FindWindow.FindWindowData()\cFW
                 Debug " "
           
                 NextElement(FindWindow.FindWindowData())

         Next i
EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply