Jump to content

Getting list of all "normal" windows


AndyK70
 Share

Recommended Posts

I'm trying to fill a ListView with all normal viewable windows to act with them.

First I tried with WinList:

Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]")
    Local $aTmp, $iID

;~  _ArrayDisplay($aWinList)
    For $i = $aWinList[0][0] To 1 Step -1 
    ; going backwards not disturbing the index while cycling through and deleting some
        If StringStripWS( $aWinList[$i][0], 3) == "" Or _
            Not BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_VISIBLE) Or _
            BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_MINIMIZED ) Then
            _ArrayDelete($aWinList, $i)
        Else 
            ; Window has a Title and is "visible"
            $aTmp = WinGetPos($aWinList[$i][1])
            If $aTmp[0] < -1000 Or $aTmp[1] < -1000 Then ; Window is minimized or tray icon
                _ArrayDelete($aWinList, $i)
            EndIf
        EndIf
    Next
    $aWinList[0][0] = UBound($aWinList)-1 ; getting actual # of windows
    ; Each row is now [ID]=> [Title], [hWnd]

But it keeps getting Windows which are definitely not there at least not visible:

YGbAlxu4Tlyr8Oy6u8rJOQ.png

Those windows "Rechner", "Einstellungen", "Netflix", "Microsoft Store", ... are not there!?! 
It should list only the first three windows, which are real.

I even tried it with _WinAPI_ UDF:

$hWnd = _WinAPI_GetForegroundWindow()

    ; Add items
    _GUICtrlListView_BeginUpdate($idListview)
    If $hWnd <> 0 Then
        $iI = 0
        Do
            If _WinAPI_IsWindow($hWnd) And _WinAPI_IsWindowVisible Then
                _GUICtrlListView_AddItem($idListview, WinGetTitle($hWnd))
                _GUICtrlListView_AddSubItem($idListview, $iI, $hWnd, 1)
                $iI += 1
                $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT)
            EndIf
        Until $hWnd = 0
    EndIf

But it is the same... :'(

 

How can i distinguish those invisible windows from normal ones?

PS: I'm using Windows 10, maybe it is important to know?

Edited by AndyK70
added tags
Link to comment
Share on other sites

1 hour ago, AndyK70 said:

I did,

No, you didn't. WinGetState is an AutoIt function, and you don't have that anywhere in your code, you're using the _WinAPI_GetWindow function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers
17 minutes ago, BrewManNH said:

No, you didn't.

It is used in the first piece of code in the line below the If. :) 

 

The second piece of code has en error  in this line:

If _WinAPI_IsWindow($hWnd) And _WinAPI_IsWindowVisible Then

_WinAPI_IsWindowVisible should have the handle as parameter.

Have you checked what the State is of these windows you don't want to see?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Oh, missed that first bit of code containing it.

Mea Culpa

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

16 hours ago, Jos said:

The second piece of code has en error  in this line:

If _WinAPI_IsWindow($hWnd) And _WinAPI_IsWindowVisible Then

_WinAPI_IsWindowVisible should have the handle as parameter.

Oh, yes :o right. Changed it, but doesn't help either.

Quote

Have you checked what the State is of these windows you don't want to see?

I did dig a littler deeper, got the PIDs and nearly all of them were the same which confused me a little bit. :blink:
Process Explorer then showed me, that this specific PID was for ApplicationFrameHost.exe, the others are for tasks which are suspended:

Ukgv5tSaTeeeFZFxIoxKDg.png

Notice the "Winstore.App.exe"(found as Microsoft Store), "SystemSettings.exe" (Einstellungen) and "Calculator.exe" (Rechner) are all those metro apps and so is the found Netflix app which is hiding behind the ApplicationFrameHost.exe.

I hope these are some useful information, even if I still don't know how I could filter them out.

 

@jdelaney I checked them and found the Class "ApplicationFrameWindow" for all of them, but this class is for all metro apps, it doesn't tell me if they are hidden or not.

 

Edit: If you want me anything to try, to search for or use some different tool to investigate further, please tell me.

Edited by AndyK70
Link to comment
Share on other sites

Maybe something like the following?  You could also check for any processes with a suspended state (WIn 10).

#include <Array.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hWindow, $vWinStyle, $aWinNormal[1][2]
Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]")
For $i = $aWinList[0][0] To 1 Step - 1
    If $aWinList[$i][0] = "" Then ContinueLoop
    $hWindow = WinGetHandle($aWinList[$i][1], "")
        If Not $hWindow Then ContinueLoop
    $vWinStyle = _WinAPI_GetWindowLong($hWindow, $GWL_STYLE)
    If BitAND(WinGetState($aWinList[$i][1]), 4) = 4 _
    And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _
    And BitAND($vWinStyle, $WS_MINIMIZE) <> $WS_MINIMIZE _
    And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _
    And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then _ArrayAdd($aWinNormal, $aWinList[$i][0] & "|" & $aWinList[$i][1])
Next
$aWinNormal[0][0] = UBound($aWinNormal) - 1
_ArrayDisplay($aWinNormal)

 

Link to comment
Share on other sites

5 hours ago, Subz said:

You could also check for any processes with a suspended state (WIn 10).

Yes, that would definitely help. Do you have a hint, where I should look for more information to check this?

I was looking in the helpfile, online help and even msdn but only found sth. how to suspend and resume a process, but not how to check if a process is suspended.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...