Get a list of all open windows using AutoIt
You can get a list of all open windows using WinList:
$aWindows = WinList()
For $i=1 To $aWindows[0][0]
; skip windows without a title
If $aWindows[$i][0] = '' Then ContinueLoop
;use the HWND to get the state of the window
$iWndState = WinGetState($aWindows[$i][1])
; here you could filter out the windows you don't want to modify
ConsoleWrite($aWindows[$i][0] & ': ')
If BitAND($iWndState,1) = 1 Then ConsoleWrite(' exists')
If BitAND($iWndState,2) = 2 Then ConsoleWrite(' visible')
If BitAND($iWndState,4) = 4 Then ConsoleWrite(' enabled')
If BitAND($iWndState,8) = 8 Then ConsoleWrite(' active')
If BitAND($iWndState,16) = 16 Then ConsoleWrite(' minimised')
If BitAND($iWndState,32) = 32 Then ConsoleWrite(' maximised')
ConsoleWrite(@CRLF)
Next
Related videos on Youtube
Nicolás Straub
I am a computer nerd. I learned programming when I was 6, started working when I was 16, and haven't stopped since. My specialties are the user experience, domain architecture, tooling, and refactoring. I have served as architect and manager for multiple projects, leading teams of up to 5 people. I firmly believe in learning the underlying theory when it comes to software development, so instead of reading "teach yourself PHP in 2 weeks" or "Python in 24 hours" I prefer "Design Patterns", "Refactoring", "Analysis Patterns", "Domain-Driven Design" and other books which tell stories of the underlying patterns, paradigms and practices that compose software development. This gives me a perspective which allows me to pick up any language and start working with it in days. With that said, being a C# and JavaScript expert, I have read the most technical books on those subjects and have in-depth knowledge of how JS, C# and the .Net CLR work. I value TDD and SOLID practices, but take a pragmatic approach to them. So, you wont find me writing fifty-four unit tests for 3 lines of code or a hundred 3-line files, for the sake of not violating the Single Responsibility Principle. When Im not working Im either learning more about software development or playing with my 8-year old. Hes starting to take an interest in programming so maybe these two worlds will collide. for now, the joy of being a loving father to him is what keeps me going.
Updated on September 16, 2022Comments
-
Nicolás Straub over 1 year
I'm trying to get rid of my minimize, maximize and close buttons on all windows. Googling around I found this:
$h = WinGetHandle("[CLASS:Notepad]") $iOldStyle = _WinAPI_GetWindowLong($h, $GWL_STYLE) $iNewStyle = BitXOr($iOldStyle, $WS_SYSMENU) _WinAPI_SetWindowLong($h, $GWL_STYLE, $iNewStyle) _WinAPI_ShowWindow($h, @SW_SHOW)
This works fine, so now I only need to iterate over all windows with this code, and I'm done. How do I get a list of all HWNDs in the system?