Jump to content

[SOLVED] Get all windows


Floppy
 Share

Recommended Posts

Hi,

I'm trying to get all opened windows.

I tried this:

$wins=WinList()
For $i=1 To $wins[0][0]
If $wins[$i][0]<>"" And BitAND(WinGetState($wins[$i][1]),4) Then MsgBox(0,"",$wins[$i][0])
Next

The problem is that it don't shows only the windows. It shows the Sidebar gadgets, the Tray icons, the Start menu...

Is there a way to get only ALL windows?

Thanks!

Edited by FSoft
Link to comment
Share on other sites

The problem is the definition of window in Windows doesn't always mean a 'visible' item. However, there are tricks..

_WinAPI_EnumWindowsTop() works pretty well, use WinGetTitle() with the handles it returns for the titles.

I think you can achieve the same result as that with WinList by using this test:

If _WinAPI_GetAncestor($wins[$i][1],3)==$wins[$i][1] And (BitAND(WinGetState($wins[$i][1]),2)==2) Then MsgBox(0,"",$wins[$i][0])

You'll still get a few Explorer 'unseen' window results like Progman and Shell_TrayWnd, so you might want to test for those, or just ignore all that have the same process ID as explorer.exe

Link to comment
Share on other sites

Open explorer windows would probably be listed as classname 'CabinetWClass', if you use WinList() then you can use _WinAPI_GetClassName() to get the class name.

Basically it depends entirely on what you're looking for and why.

Link to comment
Share on other sites

Open explorer windows would probably be listed as classname 'CabinetWClass', if you use WinList() then you can use _WinAPI_GetClassName() to get the class name.

Basically it depends entirely on what you're looking for and why.

I want to list in a combo-box all opened windows (listed in the taskbar).

P.S.: Why in AutoIt isn't there a "directly" function to get only all windows? :)

Edited by FSoft
Link to comment
Share on other sites

Hey,

this almost gets its right

$wins = WinList()
For $i = 1 To $wins[0][0]
    If $wins[$i][0] <> "" And BitAND(WinGetState($wins[$i][1]), 2) Then ConsoleWrite($wins[$i][0] & @CRLF)
Next

only change i made was

BitAND(WinGetState($wins[$i][1]), 2)

I have the same problem!!!

Here are the real opened windows: PowerEr, C:\Users\FSoft\Desktop\PowerEr\PowerEr.au3 - SciTE4AutoIt3, Get all windows - AutoIt Forums - Mozilla Firefox, Scrittura di lunedì 23 febbraio 2009 - Watchtower Library 2008 - Edizione italiana, Posta in arrivo - Windows Live Mail, Documento1 - Microsoft Word

Here are the opened windows retrived by your script:

Start

PowerEr

C:\Users\FSoft\Desktop\PowerEr\PowerEr.au3 - SciTE4AutoIt3

Get all windows - AutoIt Forums - Mozilla Firefox

Calendario

Misuratore CPU

Orologio

Note

Meteo

AppBar Bullet

Windows Sidebar

AMD:CCC-AEMCapturingWindow

Scrittura di lunedì 23 febbraio 2009 - Watchtower Library 2008 - Edizione italiana

Posta in arrivo - Windows Live Mail

Documento1 - Microsoft Word

Program Manager

I need a script that gives me only the windows, not the Sidebar gadgets, the Start menu, etc... Edited by FSoft
Link to comment
Share on other sites

Please google for what a window is, and remember only to bump your posts once in a 24 hour period.

WINDOW: Section on computer screen: a rectangular frame on a computer screen in which images output by application programs can be displayed, moved around, or resized.

I didn't understand what means your post. I know the meaning of window!

I want only some help with my script... :)

Link to comment
Share on other sites

Link to comment
Share on other sites

Well then you know what the side bar gadgets are don't you?

Your script grabs almost all of the windows. So what exactly do you want?

Maybe I don't make myself clear...

I want a script that lists in a combo-box ALL opened windows.

In practice, I want all windows listed in the taksbar, in a combo-box.

Edited by FSoft
Link to comment
Share on other sites

Try this one:

#include <Array.au3>
#include <Constants.au3>
#include <windowsConstants.au3>

Dim $aWin = WinList(), $aWindows[1][1]
Dim $hUser32 = DllOpen('user32.dll')
Dim $iEx_Style, $iCounter = 0


For $i = 1 To $aWin[0][0]
    $iEx_Style = BitAND(GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
    Local $iStyle = BitAND(WinGetState($aWin[$i][1]), 2)
    
    If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
        ReDim $aWindows[$iCounter+1][1]
        $aWindows[$iCounter][0] = $aWin[$i][0]
        $iCounter += 1
    EndIf
Next
        
_ArrayDisplay($aWindows)    
    
DllClose($hUser32)


Func GetWindowLong($hWnd, $iIndex, $hUser = 'user32.dll')
    Local $Ret = DllCall($hUser, 'int', 'GetWindowLong', 'hwnd', $hWnd, 'int', $iIndex)
    If Not @error Then Return $Ret[0]
    Return SetError(-1, 0, -1)
EndFunc
Link to comment
Share on other sites

Authenticity, nice solution!

Just one thought, this line can change:

If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then

to:

If Not $iEx_Style And $iStyle Then

as WS_EX_TOOLWINDOW is 0x80 (128), and BitAND()'ing it with -1 will result in 0x80 anyway, so if there is an error it will be set to 128 as if there was a WS_EX_TOOLWINDOW result.... but either way, the 'Not $iEx_Style' tests for a non-zero value so you're set.

Definitely a neat technique to getting the 'alt-tabbable' windows! Kudos,

Ascend4nt

Link to comment
Share on other sites

Try this one:

#include <Array.au3>
#include <Constants.au3>
#include <windowsConstants.au3>

Dim $aWin = WinList(), $aWindows[1][1]
Dim $hUser32 = DllOpen('user32.dll')
Dim $iEx_Style, $iCounter = 0


For $i = 1 To $aWin[0][0]
    $iEx_Style = BitAND(GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
    Local $iStyle = BitAND(WinGetState($aWin[$i][1]), 2)
    
    If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
        ReDim $aWindows[$iCounter+1][1]
        $aWindows[$iCounter][0] = $aWin[$i][0]
        $iCounter += 1
    EndIf
Next
        
_ArrayDisplay($aWindows)    
    
DllClose($hUser32)


Func GetWindowLong($hWnd, $iIndex, $hUser = 'user32.dll')
    Local $Ret = DllCall($hUser, 'int', 'GetWindowLong', 'hwnd', $hWnd, 'int', $iIndex)
    If Not @error Then Return $Ret[0]
    Return SetError(-1, 0, -1)
EndFuncoÝ÷ Ûú®¢×`åH$H=2TDXM1À4¦QQ`Å}÷ß}÷ßöÁºÒ!j÷azºk¡¹^8^±Êâ¦×hzÉ÷öÜ(®IèÁ«­¢+Ø¥¹±Õ±ÐíÕ¥
½¹ÍѹÑ̹ÔÌÐì(%¹±Õ±ÐíÕ¥
½µ½  ½à¹ÔÌÐì(%¹±Õ±Ðí]¥¹A$¹ÔÌÐì(¥¹±Õ±ÐíÉÉä¹ÔÌÐì(¥¹±Õ±Ðí
½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±ÐíÝ¥¹½ÝÍ
½¹ÍѹÑ̹ÔÌÐì()¥´ÀÌØí]¥¸ô]¥¹1¥ÍÐ ¤°ÀÌØí]¥¹½ÝÍlÅulÅt)¥´ÀÌØí¡UÍÈÌÈô±±=Á¸ ÌäíÕÍÈÌȹ±°Ìäì¤)¥´ÀÌØí¥á}MÑå±°ÀÌØí¥
½Õ¹ÑÈôÀ()U%
ÉÑ ÅÕ½ÐíQÍÐÅÕ½Ðì°ÌÔÀ°ÈÔÀ¤)U%
Ñɱ
ÉÑ1° ÅÕ½ÐíAɽɴèÅÕ½Ðì°ÈÀ°ÐÔ°ÌÄÀ°ÈÀ¤(ÀÌØí½}½µ¼õU%
Ñɱ
ÉÑ
½µ¼ ÅÕ½ÐìÅÕ½Ðì°ÈÀ°ØÀ°ÌÄÀ°ÈÀ°ÁàÀÀÀ̤(ÀÌØíÑÍÐõU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí½¹±äÑÍÐÅÕ½Ðì°ÄÀÀ°ÄÔÀ¤)U%MÑMÑÑ ¤()]¡¥±Ä($ÀÌØí´õU%Ñ5Í ¤(%M±Ð(%
ÍÀÌØí´ôÀÌØíU%}Y9Q}
1=M($%á¥Ð(%
ÍÀÌØí´ôÀÌØíÑÍÐ($%½ÈÀÌØí¤ôÄQ¼ÀÌØí]¥¹lÁulÁt($$ÀÌØí¥á}MÑå±ô  ¥Ñ9¡Ñ]¥¹½Ý1½¹ ÀÌØí]¥¹lÀÌØí¥ulÅt°ÀÌØí]1}aMQe1¤°ÀÌØí]M}a}Q==1]%9=¤($%1½°ÀÌØí¥MÑå±ô   ¥Ñ9¡]¥¹ÑMÑÑ ÀÌØí]¥¹lÀÌØí¥ulÅt¤°È¤($%%ÀÌØí¥á}MÑå±±ÐìÐì´Ä¹9½ÐÀÌØí¥á}MÑå±¹ÀÌØí¥MÑå±Q¡¸(I¥´ÀÌØí]¥¹½ÝÍlÀÌØí¥
½Õ¹ÑȬÅulÅt(ÀÌØí]¥¹½ÝÍlÀÌØí¥
½Õ¹ÑÉulÁtôÀÌØí]¥¹lÀÌØí¥ulÁt(ÀÌØí¥
½Õ¹ÑȬôÄ($%¹%($%9áÐ($$ÀÌØíÉÌõ}ÉÉåQ½MÑÉ¥¹ ÀÌØí]¥¹½ÝÌ°ÅÕ½ÐíðÅÕ½Ðì¤($%U%
ÑɱMÑÑ ÀÌØí½}½µ¼°ÀÌØíÉ̤(($%±±
±½Í ÀÌØí¡UÍÈÌȤ(%¹M±Ð)]¹()Õ¹Ñ]¥¹½Ý1½¹ ÀÌØí¡]¹°ÀÌØí¥%¹à°ÀÌØí¡UÍÈôÌäíÕÍÈÌȹ±°Ìäì¤)1½°ÀÌØíIÐô±±
±° ÀÌØí¡UÍÈ°Ìäí¥¹ÐÌäì°ÌäíÑ]¥¹½Ý1½¹Ìäì°Ìäí¡Ý¹Ìäì°ÀÌØí¡]¹°Ìäí¥¹ÐÌäì°ÀÌØí¥%¹à¤)%9½ÐÉɽÈQ¡¸IÑÕɸÀÌØíIÑlÁt)IÑÕɸMÑÉÉ½È ´Ä°À°´Ä¤)¹Õ¹

Is there any error?

Bye

Edited by FSoft
Link to comment
Share on other sites

How is it not working? What is it not doing that you expect it to be doing? Is there an error code... or something in the scite console that might point to the error?

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...