AutoHotkey Community

It is currently May 26th, 2012, 12:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: June 28th, 2008, 1:21 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Here's my another lil function, written in pure ahk! :)
it'll offer an easier way to get things from all existing windows


Prototype
    WinGetAll(Which="Title", DetectHidden="Off")

Usage
    WinGetAll() - Return Window Titles from all windows
    WinGetAll("Title") - Same as above
    WinGetAll("Class") - Return Window Classes from all windows
    WinGetAll("Hwnd") - Return Window Handles (Unique ID) from all windows
    WinGetAll("Process") - Return Process Names from all windows
    WinGetAll("PID") - Return Process Identifier from all windows
    WinGetAll("ANY parameter of above", "On"/0/Whatever than blank) - Include hidden windows

Note
    "Process" & "PID" are supposed to return only interactable windows with AHK. it'll not include system processes such as svchost.exe / csrss.exe / services.exe etc, if you want to get REAL process list, use other function on forum (search with post Title 'Process List')



Download WinGetAll.ahk to /Lib



Source
Code:
WinGetAll(Which="Title", DetectHidden="Off"){
O_DHW := A_DetectHiddenWindows, O_BL := A_BatchLines ;Save original states
DetectHiddenWindows, % (DetectHidden != "off" && DetectHidden) ? "on" : "off"
SetBatchLines, -1
    WinGet, all, list ;get all hwnd
    If (Which="Title") ;return Window Titles
    {
        Loop, %all%
        {
            WinGetTitle, WTitle, % "ahk_id " all%A_Index%
            If WTitle ;Prevent to get blank titles
                Output .= WTitle "`n"       
        }
    }
    Else If (Which="Process") ;return Process Names
    {
        Loop, %all%
        {
            WinGet, PName, ProcessName, % "ahk_id " all%A_Index%
            Output .= PName "`n"
        }
    }
    Else If (Which="Class") ;return Window Classes
    {
        Loop, %all%
        {
            WinGetClass, WClass, % "ahk_id " all%A_Index%
            Output .= WClass "`n"
        }
    }
    Else If (Which="hwnd") ;return Window Handles (Unique ID)
    {
        Loop, %all%
            Output .= all%A_Index% "`n"
    }
    Else If (Which="PID") ;return Process Identifiers
    {
        Loop, %all%
        {
            WinGet, PID, PID, % "ahk_id " all%A_Index%
            Output .= PID "`n"       
        }
        Sort, Output, U N ;numeric order and remove duplicates
    }
DetectHiddenWindows, %O_DHW% ;back to original state
SetBatchLines, %O_BL% ;back to original state
    Sort, Output, U ;remove duplicates
    Return Output
}

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Last edited by heresy on June 28th, 2008, 4:42 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2008, 2:54 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
Nice little wrapper, though the line
Quote:
DetectHiddenWindows, %DetectHidden%
should be
Code:
DetectHiddenWindows, % (DetectHidden != "off" && DetectHidden) ? "on" : "off"
to avoid errors and allow smart handling of wierd things in the second parameter.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2008, 4:29 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Thanks. [VxE]
i've forgot that your everlasting love for ternary :)
fixed!

To Moderator : please remove below reply. it's my fault
[ Moderator!: done.. ]

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Last edited by heresy on June 28th, 2008, 4:44 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2008, 1:43 am 
Offline

Joined: August 16th, 2008, 11:08 pm
Posts: 40
newbie question:
which are NOT fixed ? ---- Each time I run a software, the ID changes. I know PID changes....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2008, 10:38 am 
Offline

Joined: August 8th, 2008, 1:40 am
Posts: 36
I'm sorry, I'm not getting it..... :oops:

How do I use this to find hidden windows? Maybe I'm not understanding what a wrapper is.... Is this a command I can add to other scripts? if so, does this script need to be installed somewhere?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: maul.esel and 0 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group