Jump to content

How to retrieve all open windows


Recommended Posts

okay, that works fine..

I tried to retrieve them, so i could write it in a label in a GUI. but that wouldn't work!

I dont want the For..Next. I want to be able to write all open windows in a lost, like:

$Label1 (window1)

$Label2 (window2)

$Label3 (window3)

so they can be shown i the GUI under each other..

Link to comment
Share on other sites

anyone?

<{POST_SNAPBACK}>

You'll have to get them into your label variable structure using an array and a for/next loop.

Then you can use the GUICtrlCreateLabel(x,y,$name[$array#])

$windows = WinList()
Dim $locationX = 0, $locationY = 0
Dim $label[$windows[0][0]]; <==edit forgot to add the dim for the label.
GUICreate("Test",500,500,50,50)
For $x = 1 to $windows[0][0]
   $label[$x] = $windows[$x][0]; get the window title into an array
   GUICtrlCreateLabel($label[$x],$locationX,$locationY+30,50,25)
Next
GUISetState()
While 1
   Sleep(10)
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE then Exit
WEnd

EDIT: Silly me. Corrected code posted.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

I feared that, i can't really see how this works... ive wred the help file many times, but i cant figure how to do it..

could someone write me an eksamle plz?

<{POST_SNAPBACK}>

See my edited post.

EDIT: Corrected errors in the syntax.

Meh, doesn't work yet.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

#include <GUIConstants.au3>
$windows = WinList()
Dim $locationX = 0, $locationY = 0, $y = 0
Dim $label[$windows[0][0]]
MsgBox(0, "test", $windows[5][0])
GUICreate("Test", 500, 500, 50, 50)
For $x = 1 to ($windows[0][0]) - 1
   If Not $windows[$x][0] = "" Then
      $y = $y + 1
      $label[$y] = $windows[$x][0]; get the window title into an array
      GUICtrlCreateLabel($label[$y], $locationX, $locationY + 30, 50, 25)
   EndIf
Next
GUISetState()
While 1
   Sleep(10)
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Partially works....got one window's title to display on my end.

Problem is, there's 277 windows on my desktop (most of them are hidden with null strings or spaces for titles). There's a bit in the help file about WinList, go back to there... My code is borken.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

WinGetState 
--------------------------------------------------------------------------------

Retrieves the state of a given window.


WinGetState ( "title" [, "text"] )


 

Parameters

title The title of the window to read. 
text [optional] The text of the window to read. 

 

Return Value

Success: Returns a value indicating the state of the window. Multiple values are added together so use BitAND() to examine the part you are interested in: 
 1 = Window exists 
 2 = Window is visible 
 4 = Windows is enabled 
 8 = Window is active 
 16 = Window is minimized 
 32 = Windows is maximized 
  
Failure: Returns 0 and sets @error to 1 if the window is not found.

hope this hint helps...

Link to comment
Share on other sites

I understand it about if its visible and so on. But i can't fugure how to get all visible windows, into a list... just to show witch windows are opened...

#include <GUIConstants.au3>

GUICreate("GUI",400, 225)

$label1 = GUIctrlCreatelabel("", 20, 55, 300, 20)
GUISetState(@SW_SHOW)

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

While 1
sleep(1000) 
$msg = GUIGetMsg()
$var = WinList()



For $i = 1 to $var[0][0]
  
  If $var[$i][0] <> "" AND IsVisible($var[$i][0]) Then
     GUICtrlsetdata($label1,$var[$i][0])
     MsgBox(0,"test",$var[$i][0])
  EndIf
Next


       If $msg = $GUI_EVENT_CLOSE Then
       Exitloop
       Endif


WEnd

it show them in the msgbox, one by one... but i want it to write all of them in the GUI, as a list...

Link to comment
Share on other sites

Why don't you write the data to a listbox?

If you insist on using labels...

Here it is.

#include <GUIConstants.au3>

GUICreate("GUI",400, 225)

$var = WinList()

Dim $x = -1
For $i = 1 to $var[0][0]
  If $var[$i][0] = "" Then ContinueLoop
  If IsVisible($var[$i][1]) Then
     $x = $x + 1
     GUIctrlCreatelabel($var[$i][0], 10, ($x * 15) + 25, 400, 20)
    ;MsgBox(0,"test",$var[$i][0])
  EndIf
Next
   
GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
   

 If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
 Endif


WEnd


Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc
Link to comment
Share on other sites

List box format...

#include <GUIConstants.au3>

GUICreate("GUI",400, 400)

$var = WinList()
$list = GUIctrlCreatelist("",10,10,350,350)
Dim $x = -1
For $i = 1 to $var[0][0]
  If $var[$i][0] = "" Then ContinueLoop
  If IsVisible($var[$i][1]) Then
     $x = $x + 1
     GUICtrlSetData($list,$var[$i][0] & "|")
    ;GUIctrlCreatelabel($var[$i][0], 10, ($x * 15) + 25, 400, 20)
   ;MsgBox(0,"test",$var[$i][0])
  EndIf
Next

   
GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
   

If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
Endif


WEnd


Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc
Link to comment
Share on other sites

okay, it works fine. When all windows has been listed, is it then possible to select one, and do something about that specific window. Like change to title...

I want to be able to select one in the list, and then do something...

something like "the windows title" has been selected

Link to comment
Share on other sites

hmm, sry for being noobish, but how can i intigrate that..

#include <GUIConstants.au3>

GUICreate("GUI",400, 400)

$var = WinList()
$list = GUIctrlCreatelist("",10,10,350,350)
Dim $x = -1
For $i = 1 to $var[0][0]
  If $var[$i][0] = "" Then ContinueLoop
  If IsVisible($var[$i][1]) Then
     $x = $x + 1
     GUICtrlSetData($list,$var[$i][0] & "|")
   ;GUIctrlCreatelabel($var[$i][0], 10, ($x * 15) + 25, 400, 20)
  ;MsgBox(0,"test",$var[$i][0])
  EndIf
Next

   
GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
   

If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
Endif


WEnd


Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

If $msg = $Listbox_1 Then

;Do whatever you want here

EndIf

nothing is really $listbox_1, in some way, i guess i have to call every single line in the listview something, so i can use the IF (butten selected)

i like to have it like when you have selected the window, then press a button, and it will tell me witch have been chosen :lmao:

Link to comment
Share on other sites

hmm, sry for being noobish, but how can i intigrate that..

#include <GUIConstants.au3>

GUICreate("GUI",400, 400)

$var = WinList()
$list = GUIctrlCreatelist("",10,10,350,350)
Dim $x = -1
For $i = 1 to $var[0][0]
  If $var[$i][0] = "" Then ContinueLoop
  If IsVisible($var[$i][1]) Then
     $x = $x + 1
     GUICtrlSetData($list,$var[$i][0] & "|")
 ;GUIctrlCreatelabel($var[$i][0], 10, ($x * 15) + 25, 400, 20)
;MsgBox(0,"test",$var[$i][0])
  EndIf
Next

   
GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
   

If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
Endif
WEnd
Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

nothing is really $listbox_1, in some way, i guess i have to call every single line in the listview something, so i can use the IF (butten selected)

i like to have it like when you have selected the window, then press a button, and it will tell me witch have been chosen :lmao:

<{POST_SNAPBACK}>

The key is this section of code right here:

GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
  

If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
Endif


WEnd

This is your primary data loop that just idles until something is pressed on the GUI. Be it a button, or whatever.

All events are stored in the $msg variable. This is why we set buttons to variables.

$button_1 = GUICtrlCreateButton()

That way, when button_1 is pressed, it sends the msg to the controller in your loop.

I wouldn't use If/ElseIf/Else/EndIf, I'd use Select/Case/CaseElse/EndSelect. Not that there's anything wrong, as both constructs are perfectly valid. it's just a personal preference and it makes better sense (to me).

$button_1 = GUICtrlCreateButton(); additional parameters required, see helpfile.
GUISetState(@SW_SHOW)

While 1; primary data loop
   sleep(25)
   $msg = GUIGetMsg() 
  
   Select
      Case $msg = $GUI_EVENT_CLOSE 
         ExitLoop
      Case $msg = $button_1 
       ;Do the functions needed after pressing this button.
   EndSelect

WEnd

Grab that tree and see what shakes out. o:)

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

uhm.. i know all about While.. WEnd sry, just don't get how to do this...

I want to know exacly how to to this..

I have the script witch find the open windows, and put them in the list..

Then i want to be able to click one of them in the list, then push a button, and rename that window..

Try to use this code, and build it into it... thx for any help!

#include <GUIConstants.au3>

GUICreate("GUI",400, 400)

$var = WinList()
$list = GUIctrlCreatelist("",10,10,350,350)
Dim $x = -1
For $i = 1 to $var[0][0]
  If $var[$i][0] = "" Then ContinueLoop
  If IsVisible($var[$i][1]) Then
     $x = $x + 1
     GUICtrlSetData($list,$var[$i][0] & "|")
  ;GUIctrlCreatelabel($var[$i][0], 10, ($x * 15) + 25, 400, 20)
  ;MsgBox(0,"test",$var[$i][0])
  EndIf
Next

   
GUISetState(@SW_SHOW)

While 1
   sleep(25)
   $msg = GUIGetMsg()
   

If $msg = $GUI_EVENT_CLOSE Then
    Exitloop
Endif


WEnd


Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc
Edited by Wb-FreeKill
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...