In accordance with my wish I decided to put my money where my mouth is and start a library of functions dedicated to retrieving all available information about certain items based on existing commands and lumping them into an object to be returned. Once returned the user can choose which information they would like to use from the object. I think the exercise of creating a library like this may have future implications for AHK; if there is no significant time loss to retrieve all available information about an item it may prove more satisfactory to return all data in objects in the future rather than a single piece in a variable.
For example, a function DriveInfo() to retrieve all information about all available drives, which can be limited by specifying a type of drive as a parameter:
drives := DriveInfo() For k,v in drives { dk := k, dr := v For k,v in dr res .= (v ? ((!res ? "" : "`n") k ": " v) : "") MsgBox, Information for drive %dk%:`n`n%res% res := dr := "" } ; separate example MsgBox % DriveInfo("C").Label return
Or FileInfo(), which will retrieve all information about a file:
file := FileInfo(filename := "C:\Program Files\AutoHotkey\AutoHotkey.exe") For k,v in file res .= (!res ? "" : "`n") k ": " v MsgBox, Information for %filename%`n`n%res% return
Bear in mind this is only a preliminary list, and any additions would be welcome.
DriveInfo(drive="") { cmd=Capacity,Filesystem,Label,Serial,Type,Status,StatusCD if (drive && !FileExist(RegExReplace(drive,"\W") ":\")) { MsgBox, 48, Warning, Invalid parameter for drive, please select an existing drive on your machine. return False } if drive { res := Object("FreeSpace",DriveSpaceFree(drive)) Loop, parse, cmd, `, res[A_LoopField] := DriveGet(A_LoopField,drive) return res } res := Object(), dlist := DriveGet("List") Loop, parse, dlist { tmp := A_LoopField, obj := Object("FreeSpace",DriveSpaceFree(tmp)) Loop, parse, cmd, `, obj[A_LoopField] := DriveGet(A_LoopField,tmp) res[tmp] := obj } return res } DriveGet(cmd,value="") { ; helper function for DriveObj() DriveGet, res, %cmd%, % value ? RegExReplace(value,"\W") ":\" : "" return res } DriveSpaceFree(path) { ; helper function for DriveObj() DriveSpaceFree, res, % RegExReplace(path,"\W") ":\" return res } FileInfo(fpath) { FileGetTime, ftm, %fpath%, M FileGetTime, ftc, %fpath%, C FileGetTime, fta, %fpath%, A FileGetVersion, fv, %fpath% return Object("Attributes",FileExist(fpath) ,"Modified",ftm,"Created",ftc,"Last Access",fta,"Version",fv) } MouseObj(opt="") { ; opt may only be 1,2 or 3 MouseGetPos, x, y, w, c, %opt% return Object("x",x,"y",y,"window",w,"control",c) } WinGetActiveStats() { WinGetActiveStats, t, w, h, x, y return Object("title",t,"width",w,"height",h,"x",x,"y",y) } WinInfo(win="A",text="",extitle="",extext="") { cmd := "PID,ProcessName,MinMax,ControlList,ControlListHwnd," . "Transparent,TransColor,Style,ExStyle" WinGetTitle, t, %win%, %text%, %extitle%, %extext% WinGetPos, x, y, w, h, %win%, %text%, %extitle%, %extext% WinGetText, text, %win%, %text%, %extitle%, %extext% WinGetClass, class, %win%, %text%, %extitle%, %extext% res := Object("title",t,"width",w,"height",h,"x",x,"y",y,"text",text,"class",class) Loop, parse, cmd, `, res[A_LoopField] := WinGet(win,A_LoopField) return res } WinGet(win,cmd,text="",extitle="",extext="") { ; helper function for WinObj() WinGet, res, %cmd%, %win%, %text%, %extitle%, %extext% return res } PathInfo(ByRef InputVar) { SplitPath, InputVar, f, d, e, n, dr return Object("FileName",f,"Dir",d,"Extension",e,"NameNoExt",n,"Drive",dr) } MonitorInfo() { cmd=Monitor,MonitorWorkArea,MonitorName c := SysGet("MonitorCount") res := Object("Count",c,"PrimaryMonitor",SysGet("MonitorPrimary")) if (c > 1) { Loop % c { m := A_Index, %m% := Object() Loop,parse,cmd, `, %m%[(A_LoopField="Monitor") ? "Coords" : SubStr(A_LoopField,8)] := SysGet(A_LoopField,m) res[A_Index] := %m% } } return res } SysGet(Subcmd,Param3="") { SysGet, r, %Subcmd%, %Param3% Return In(subcmd,"Monitor,MonitorWorkArea") ? rLeft "," rTop "," rRight "," rBottom : r } ImageSearch(X1,Y1,X2,Y2,ImageFile) { ImageSearch, X, Y, %X1%, %Y1%, %X2%, %Y2%, %ImageFile% return Object("x",X,"y",Y) } PixelSearch(X1,Y1,X2,Y2,ColorID,Variation = "",Mode = "") { PixelSearch, X, Y, %X1%, %Y1%, %X2%, %Y2%, %ColorID%, %Variation%, %Mode% return Object("x",X,"y",Y) } In(ByRef var, MatchList) { If var in %MatchList% Return True } WinGetList(win="A",type="List",text="",extitle="",extext="") { if !In(type,"List,Control") { MsgBox, 48, Warning, Invalid type parameter, only List or Control are accepted. return False } res := Object() If (type = "List") { WinGet, out, List, %win%, %text%, %extitle%, %extext% Loop % out { WinGetTitle, t, % "ahk_id " out%A_Index% res[A_Index] := Object("Title",t,"hWnd",out%A_Index%) } } else { WinGet, cout, ControlList, %win%, %text%, %extitle%, %extext% WinGet, hout, ControlListHwnd, %win%, %text%, %extitle%, %extext% StringSplit, n, cout, `n StringSplit, h, hout, `n Loop % n0 res[A_Index] := Object("Name",n%A_Index%,"hWnd",h%A_Index%) } return res }
20101230
[*:gpb7c0or]changed the object var format in the first example and removed 'Obj' from applicable function names, replaced by 'Info'.
[*:gpb7c0or]Updated the DriveInfo function to accomodate a call to a single drive, updated and added helper functions for DriveInfo
[*:gpb7c0or]Added additional functions
20110102 - Added RegExM() and WhileRegExM().
20110106 - Modified WinGetList() to accept only 'List' and 'Control' in the type parameter; 'List' now returns the title and hWnd for each matching window and 'Control' now returns the name and hWnd of each control in the window.