Get a list of all open windows using AutoIt

本秂侑毒 提交于 2019-12-10 13:38:06

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/18456091/get-a-list-of-all-open-windows-using-autoit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!