Tip: Get handle/title of all open windows

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Tip: Get handle/title of all open windows

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by PB.

This is handy to get a list of which apps are running (as long as they have a
window open; it won't show "background" apps without an IDE). For Windows OS.

Code: Select all

; Get handles and titles of all open windows.
; Handles are stored in wh() array, and titles in wt$() array.
; By PB; feel free to use in any way you wish!  :)
;
nw=0 ; Number of found windows.
Dim wh(999) ; Each window's handle.
Dim wt$(999) ; Each window's title.
; Prepare to show all found windows.
OpenConsole()
PrintN("[Handle] Title")
PrintN("")
; Now find them all!
r=GetWindow_(GetDesktopWindow_(),#GW_CHILD) ; Start at the Desktop level.
Repeat
  a$=Space(255) : GetWindowText_(r,a$,255) ; Prepare title buffer and get title.
  If a$<>"" And a$<>"Program Manager" ; Ignore "fake" windows and the Desktop.
    If IsWindowVisible_(r)=#TRUE ; We found an open window!
      nw=nw+1 : wh(nw)=r : wt$(nw)=a$ ; Store its handle/title in variables.
      PrintN("["+Str(r)+"] "+a$) ; Show the handle/title in the console.
    EndIf
  EndIf
  r=GetWindow_(r,#GW_HWNDNEXT) ; Find next window until no more are found.
Until r=0
Delay(9999)

PB - Registered PureBasic Coder
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: Tip: Get handle/title of all open windows

Post by grabiller »

Does someone also published the equivalent of this for Mac OSX ?

I would be interested to also know how to move/resize Windows ones found (on Mac OSX that is).
guy rabiller | radfac founder / ceo | raafal.org
Post Reply