Jump to content
AndyK70

Getting list of all "normal" windows

Recommended Posts

AndyK70

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

Share this post


Link to post
Share on other sites
AndyK70

 

Just now, jdelaney said:

WinGetState.  Is visible flag.

I did, please have a closer look into the example code I provided.

Share this post


Link to post
Share on other sites
BrewManNH
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

Share this post


Link to post
Share on other sites
Jos
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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
AndyK70
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

Share this post


Link to post
Share on other sites
Subz

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)

 

  • Like 1

Share this post


Link to post
Share on other sites
AndyK70
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.

 

Share this post


Link to post
Share on other sites
Subz

Have a look at the following 

 

WinApi function would probably be faster than WMI

  • Like 1

Share this post


Link to post
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

  • Similar Content

    • ur
      By ur
      When I compiled my script or any script to exe using 32 bit compiler and ran on 32 bit machine, I am getting below error.
       

       
      But it is 32 bit only.
       
      And, for testing, I disabled smart screen also, but same issue.
      Please suggest.
       
    • sadakathullah
      By sadakathullah
      Hi All, I am new to AutoIT and exploring options to use it in my organization. I tried couple of examples and it is fantastic. I am trying to run restrictions test in a pc to see if certain options are disabled like print screen, mstsc etc. I could not get a hang of it. Any help is much appreciated.
    • stayready40
      By stayready40
      Hello all. I created a script to uninstall Symantec from our environment and I placed the "BlockInput(1)" command in the beginning of the script so that end users would not be able to move the mouse or keyboard to disrupt the mouse clicks.
      During testing we found that this worked for our Windows 7 machines, but for our windows 10 machines the mouse disable did not work can anyone shed some light on why this is? 
      Here is my code:

       
    • faustf
      By faustf
      hi guys
      i have a script  like this,  in windows 7 work perfect , in windows 10 not  work  , some one can explain me  why ??'
      #include <Array.au3> #include <MsgBoxConstants.au3> Global $aGPathFoto= FileReadToArray (@ScriptDir & "\TEMP\PathFoto.txt") Local $ctrl = 0 While 1 Local $hWnd = WinWait("[CLASS:#32770]", "", 10) If WinExists("[CLASS:#32770]") Then If $ctrl < 2 Then ControlSend($hWnd, "Choose File to Upload", "[CLASS:Edit; INSTANCE:1]", $aGPathFoto[0]&"{Enter}") Exit $ctrl += 1 Else ExitLoop EndIf EndIf WEnd $aGpathfoto = C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
    • Skeletor
      By Skeletor
      Hi Virtual People, 
      I'm trying to lock my screen in Windows 10 but to no avail. 
      Has Windows 10 forbidden this feature? 
      Send("#l") Above code does not work. Even sending Ctrl Alt Del does not work nor as an Admin. 
      Note: I want to lock my screen, not log off. Thanks for been kind.
       
×