kcvinu

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

16 posts in this topic

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


My Contributions

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)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#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
1 person likes this

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

Share this post


Link to post
Share on other sites

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
1 person likes this

Share this post


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

My Contributions

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)

 

Share this post


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


My Contributions

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)

 

Share this post


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

My Contributions

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)

 

Share this post


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

My Contributions

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)

 

Share this post


Link to post
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)
1 person likes this

Share this post


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


My Contributions

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)

 

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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()
1 person likes this

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

Share this post


Link to post
Share on other sites

Hi 

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

My Contributions

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)

 

Share this post


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

Share this post


Link to post
Share on other sites

@kcvinu you can click in the function name that I posted :) (I searched in the help file index for "stringRegExp" and was found)

1 person likes this

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

Share this post


Link to post
Share on other sites

I have same problem, I try to do but it not run correct :(

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

    • cappy2112
      By cappy2112
      I've used WinList() to give me a list of all the windows it finds on the system.
      I then search through that list to find a few windows which match a title string.
      Now I want to present that smaller list of Title/strings to the user, so that they can select ONE of them.
      Which widget would be best for this operation? Ideally, the widget should return the index of the item selected, and if possible only allow the user to select 1 item.
      I don't expect there will be more than 10 Windows running on the systems I'm working with. In all practicality, I've only seen 4 at the max.
       
      Thanks
    • Danyfirex
      By Danyfirex
      HI. I was needing to add a program to Tarkbar(an easy way without using objectcreateinterface )   so I found this. So then I deduced how to add to the StartMenu while I see the shell32 in hex editor search for taskbarunpin|taskbarpin string. I found another two interesting string (startpin|startunpin) So I try out and they work too but to add to StartMenu.
      This is not an official way to do this, however it works.
      $sFileLnk parameter must be Link(.lnk) to our program.
      ;~ Success: True. ;~ Failure: False. Func DeleteFromTaskBar($sFileLnk) Return _WinAPI_ShellExecute($sFileLnk,"","", "taskbarunpin") EndFunc Func AddToTaskBar($sFileLnk) Return _WinAPI_ShellExecute($sFileLnk,"","", "taskbarpin") EndFunc Func AddToStartMenu($sFileLnk) Return _WinAPI_ShellExecute($sFileLnk,"","", "startpin") EndFunc Func DeleteFromStartMenu($sFileLnk) Return _WinAPI_ShellExecute($sFileLnk,"","", "startunpin") EndFunc  
      Saludos
    • timmalos
      By timmalos
      Hello guys.
      I have a little issue and I can't find any answer sadly so I'm opening this post.
      I created a tool with AutoIt, but sadly on Windows 8.1 I can't pin it to my taskbar, I have no idea why. If I take any other program for example Firefox, when it's started and I do a right click on the icon in the taskbar I can have a nice menu and just below "Exit window" I have an option "Pin this program to the TaskBar" (or Unpin if already clicked), but with my AutoIt script (compiled) I have only the Exit button.
      Do you know if there is a Windows option to add to GuiCtrlCreateGui() or anything I can do to be able to pin my program to the  windows 8.1 taskbar?
      Thank you very much,
      Tim
    • RichE
      By RichE
      Hi All,
      I wrote an app a few years ago and have revisited it to improve it, one thing I can't sort it to not show it on the taskbar, but show it in the system tray, the point of the app is to allow users easy access to info that tech support may ask, like username, pc name & IP address.
      I've searched the forums but not found a answer, can anyone point me in the right direction.
      Thanks in advance#
      RichE
    • AmbientMike
      By AmbientMike
      Hi,
      I am trying to find a way to detect if two applications are running (and visible in the GUI).  One sits in the system tray (which I've got sorted) but another launches (so is easily visible as a running process) but seems to delay until showing in the GUI but the "WinExists" command seems to pick it up a few seconds before it's actually visible!
      The bit of script that detects the system tray app is modified from somewhere on these forums that finds the text labels from all of the tray icons...
      Func Get_Systray_IconText($sToolTipTitle) Local $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) Local $iSystray_ButtonNumber For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText EndIf Next Return SetError(1, 0, "") EndFunc So I was hoping that there was something nearly identical that detects icons in the Taskbar in a near-identical way as ProcessExists and WinExists commands seem to detect it too early and I really need to detect the time that the window is visible to the user which seems to be when it spawns it's taskbar icon.
      Any ideas?