Page 1 of 1

Tip: Get handle/title of all open windows

Posted: Fri Jan 25, 2002 12:02 am
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

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

Posted: Wed Jul 23, 2014 7:43 am
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).