Jump to content

How to get the list of windows opened in task bar.


Go to solution Solved by jguinch,

Recommended Posts

Hi all,
I need to get the list of windows which are resting in taskar. That means, windows which i can toggle through ALT TAB. I use "WinList" function. But it gives me all the windows. Then i tried to filter it like this;
Local $lst = WinList()
Local $Row = 0
For $i = 1 To $lst[0][0]

    If $lst[$i][0] = "" And Not BitAND(WinGetState($lst[$i][1]), 1) Then
        _ArrayDelete($lst,$Row)
    EndIf
    $Row +=1
Next
_ArrayDisplay($lst)

But this code doesn't delete the 2nd column. I have read the help file and saw an example which deletes an entire row from a 2 dimensional array. I have used the same method but please look this image. This is what i have got.

post-89644-0-71886200-1425280696_thumb.p

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

#include <Array.au3>
[code=autoit:0]Local $lst = WinList()
Local $i=1
Do
    If $lst[$i][0] = "" And Not BitAND(WinGetState($lst[$i][1]), 1) Then _ArrayDelete($lst,$i)
    $i+=1
Until $i>UBound($lst)-1
_ArrayDisplay($lst)
Exit

Maybe you can only use _arraydelete for 1D arrays

EDIT:Nope, is all fine, _arraydelete supports up to 2D arrays

EDIT2: Solved:

 

Local $lst = WinList('[REGEXPTITLE:(.+)]')
_ArrayDisplay($lst)
Exit
Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • Solution

A beginning, but not perfect:

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

$aList = WinList()

For $i = 1 To $aList[0][0]
    $iExStyle = _WinAPI_GetWindowLong($aList[$i][1], $GWL_EXSTYLE) ; get the extended style of each Window
    
    If NOT BitAND($iExStyle, $WS_EX_TOOLWINDOW) AND _  ; Search for windows without $WS_EX_TOOLWINDOW extended style
       BitAND(WinGetState($aList[$i][1]), 2 ) Then     ; And only visible windows 
        ConsoleWrite($aList[$i][0] & @CRLF)
    EndIf
Next
Link to comment
Share on other sites

 

EDIT2: Solved:

 

Local $lst = WinList('[REGEXPTITLE:(.+)]')
_ArrayDisplay($lst)
Exit

 

Hi 

Kyan, Solved.. Thanks a lot. And, How can i learn more about this "[REGEXPTITLE:(.+)]" Any tutorials ?
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Hi 

jguinch, Thanks for your reply. But your code gives an error. Please look this image.

post-89644-0-63224700-1425303690_thumb.p

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Hi 

jguinch, Yes.. it worked. And after the final comparison, i have decided to declare your answer is the best. Because, it gives the taskbar windows only, This is what i want. Thank you, Thanks a lot. And, after a few hours, i will get time to study your code. Then can i ask you about  these two constants ? $iExStyle, $WS_EX_TOOLWINDOW
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Hi 

jguinch, In your code, your are using console write. But i need to put this data into an array. But before the for loop, we can't say there are how many items in our array. So we can't declare an array. Then, how can i put this data into an array ? any idea ?
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

You can just declare an array at the begining and redim it each time a Window is found.

Look, I do it for you now, try to understand the Redim role :

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

Local $aWinInTaskBar[1][2]
$iCount = 0


$aList = WinList()

For $i = 1 To $aList[0][0]
    $iExStyle = _WinAPI_GetWindowLong($aList[$i][1], $GWL_EXSTYLE) ; get the extended style of each Window

    If NOT BitAND($iExStyle, $WS_EX_TOOLWINDOW) AND _  ; Search for windows without $WS_EX_TOOLWINDOW extended style
       BitAND(WinGetState($aList[$i][1]), 2 ) Then     ; And only visible windows
        $iCount += 1
        Redim $aWinInTaskBar[ $iCount + 1][2]
        $aWinInTaskBar[ $iCount][0] = $aList[$i][0]
        $aWinInTaskBar[ $iCount][1] = $aList[$i][1]
    EndIf
Next
$aWinInTaskBar[0][0] = UBound($aWinInTaskBar) - 1

_ArrayDisplay($aWinInTaskBar)
Link to comment
Share on other sites

Hi 

jguinch, Thank you. I have wrote for loop twice to solve this. 

Local $Count = 0

For $i = 1 to Winlist[0][0]

   if find a task bar window then

      $Count += 1

  End If

Next.

Local $NewArray[$Count] 

Then second for loop will come and populate this $NewArray. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

jguinch,

That is the worst possible way to deal with an array whose final size is unknown - ReDim is incredibly slow when the array gets large (although I admit it is unlikely to get too large in this particular case). Please see the final section of the Recursion tutorial in the Wiki to see the most efficient way to do it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

 

Hi 

Kyan, Solved.. Thanks a lot. And, How can i learn more about this "[REGEXPTITLE:(.+)]" Any tutorials ?

 

thats just a simple regular expression (the part in front of REGEXPTITLE:)

You can check the help file of Regular Expressions here:

stringRegExp()

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Hi 

Kyan, I searched in help file for "REGEXP" and didn't get any result. Anyway, thank you.
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@M23 : You're right. I know that, I usually minimize the Redim usage (Redim $array[ubound($array) * 2].

But in this case, unless the user has hundreds of opened windows in the same time, is it necessary ? o:)

For that matter, it could be interesting to add a comment in the Redim help page ?

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...