ListGlobalVars_and_also_print_arrays()

Post your working scripts, libraries and tools for AHK v1.1 and older
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

ListGlobalVars_and_also_print_arrays()

24 Apr 2017, 13:37

this wrapper function returns a big string that is (i) what you see in ListVars (ii) interspersed with info about the innards of all the objects/arrays (by default, ListVars will give you things like "global_var[Object]: 0x00000000027657B0" when it encounters an object)

it assumes you have lexico's ListGlobalVars() (pasted below) and also some function that returns a string representation of an array (the one i used is pasted below and can be found at the bottom of https://autohotkey.com/board/topic/70490-print-array/)

code is posted to this pastebin (sorry for the inconvenience but i used some special characters that the forum wouldn't accept for some reason and it'd be too much hassle to change them ...)

https://pastebin.com/WDEqareX
Image






Code: Select all


; Written by Lexikos - see: http://www.autohotkey.com/board/topic/20925-listvars/#entry156570
/*
    Loop {
        tick := A_TickCount
        ToolTip % ListGlobalVars()
    }
*/

ListGlobalVars(){
    static hwndEdit, pSFW, pSW, bkpSFW, bkpSW

    if !hwndEdit
    {
        dhw := A_DetectHiddenWindows
        DetectHiddenWindows, On
        Process, Exist
        ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %ErrorLevel%
        DetectHiddenWindows, %dhw%

        astr := A_IsUnicode ? "astr":"str"
        ptr := A_PtrSize=8 ? "ptr":"uint"
        hmod := DllCall("GetModuleHandle", "str", "user32.dll")
        pSFW := DllCall("GetProcAddress", ptr, hmod, astr, "SetForegroundWindow")
        pSW := DllCall("GetProcAddress", ptr, hmod, astr, "ShowWindow")
        DllCall("VirtualProtect", ptr, pSFW, ptr, 8, "uint", 0x40, "uint*", 0)
        DllCall("VirtualProtect", ptr, pSW, ptr, 8, "uint", 0x40, "uint*", 0)
        bkpSFW := NumGet(pSFW+0, 0, "int64")
        bkpSW := NumGet(pSW+0, 0, "int64")
    }

    if (A_PtrSize=8) {
        NumPut(0x0000C300000001B8, pSFW+0, 0, "int64")  ; return TRUE
        NumPut(0x0000C300000001B8, pSW+0, 0, "int64")   ; return TRUE
    } else {
        NumPut(0x0004C200000001B8, pSFW+0, 0, "int64")  ; return TRUE
        NumPut(0x0008C200000001B8, pSW+0, 0, "int64")   ; return TRUE
    }

    ListVars

    NumPut(bkpSFW, pSFW+0, 0, "int64")
    NumPut(bkpSW, pSW+0, 0, "int64")

    ControlGetText, text,, ahk_id %hwndEdit%

    RegExMatch(text, "sm)(?<=^Global Variables \(alphabetical\)`r`n-{50}`r`n).*", text)
    return text
}






PrintArray(Array, Display=1, Level=0){
	Global PrintArray

	Loop, % 4 + (Level*8)
	Tabs .= A_Space

	Output := "Array`r`n" . SubStr(Tabs, 5) . "("

	For Key, Value in Array
	{
		If (IsObject(Value))
		{
			Level++
			Value := PrintArray(Value, 0, Level)
			Level--
		}

		Output .= "`r`n" . Tabs . "[" . Key . "] => " . Value
	}

	Output .= "`r`n" . SubStr(Tabs, 5) . ")"


	If (!Display)
	Return Output

	Gui, PrintArray:+MaximizeBox +Resize
	Gui, PrintArray:Font, s9, Courier New
	Gui, PrintArray:Add, Edit, x12 y10 w850 h750 vPrintArray ReadOnly HScroll, %Output%
	Gui, PrintArray:Show, w876 h774, PrintArray
	Gui, PrintArray:+LastFound
	ControlSend, , {Right}
	WinWaitClose
	Return Output

	PrintArrayGuiSize:
	Anchor("PrintArray", "wh")
	Return

	PrintArrayGuiClose:
	Gui, PrintArray:Destroy
	Return
}





/*
	Function: Anchor
		Defines how controls should be automatically positioned relative to the new dimensions of a window when resized.

	Parameters:
		cl - a control hwnd, associated variable name or ClassNN to operate on
		a - (optional) one or more of the anchors: 'x', 'y', 'w' (width) and 'h' (height),
			optionally followed by a relative factor, e.g. "x h0.5"
		r - (optional) true to redraw controls, recommended for GroupBox and Button types

	Examples:
> "xy"
> "w0.5"
> "h"

	Remarks:
		To assume the current window size for the new bounds of a control (i.e. resetting) simply omit the second and third parameters.
		However if the control had been created with DllCall() and has its own parent window,
			the container AutoHotkey created GUI must be made default with the +LastFound option prior to the call.
		For a complete example see anchor-example.ahk.

	License:
		- Version 4.60a <http://www.autohotkey.net/~Titan/#anchor>
		- Simplified BSD License <http://www.autohotkey.net/~Titan/license.txt>
*/
Anchor(i, a = "", r = false) {
	static c, cs = 12, cx = 255, cl = 0, g, gs = 8, gl = 0, gpi, gw, gh, z = 0, k = 0xffff
	If z = 0
		VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
	If (!WinExist("ahk_id" . i)) {
		GuiControlGet, t, hwnd, %i%
		If ErrorLevel = 0
			i := t
		Else ControlGet, i, hwnd, , %i%
	}
	VarSetCapacity(gi, 68, 0), DllCall("GetWindowInfo", "UInt", gp := DllCall("GetParent", "UInt", i), "UInt", &gi)
		, giw := NumGet(gi, 28, "Int") - NumGet(gi, 20, "Int"), gih := NumGet(gi, 32, "Int") - NumGet(gi, 24, "Int")
	If (gp != gpi) {
		gpi := gp
		Loop, %gl%
			If (NumGet(g, cb := gs * (A_Index - 1)) == gp) {
				gw := NumGet(g, cb + 4, "Short"), gh := NumGet(g, cb + 6, "Short"), gf := 1
				Break
			}
		If (!gf)
			NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, "Short"), NumPut(gh := gih, g, gl + 6, "Short"), gl += gs
	}
	ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
	Loop, %cl%
		If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
			If a =
			{
				cf = 1
				Break
			}
			giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, "Short")
				, cw := dw, dw := NumGet(c, cb + 8, "Short"), ch := dh, dh := NumGet(c, cb + 10, "Short")
			Loop, Parse, a, xywh
				If A_Index > 1
					av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
						, d%av% += (InStr("yh", av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1)
			DllCall("SetWindowPos", "UInt", i, "Int", 0, "Int", dx, "Int", dy
				, "Int", InStr(a, "w") ? dw : cw, "Int", InStr(a, "h") ? dh : ch, "Int", 4)
			If r != 0
				DllCall("RedrawWindow", "UInt", i, "UInt", 0, "UInt", 0, "UInt", 0x0101)
			Return
		}
	If cf != 1
		cb := cl, cl += cs
	bx := NumGet(gi, 48), by := NumGet(gi, 16, "Int") - NumGet(gi, 8, "Int") - gih - NumGet(gi, 52)
	If cf = 1
		dw -= giw - gw, dh -= gih - gh
	NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short")
		, NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
	Return, true
}










Last edited by 20170201225639 on 24 Apr 2017, 14:12, edited 3 times in total.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: ListGlobalVars_and_also_print_arrays()

24 Apr 2017, 13:46

is this a joke? poop emojis a variable names?

20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: ListGlobalVars_and_also_print_arrays()

24 Apr 2017, 13:53

well, not really ... speaking for myself at least emojis are great as variable names. they really help visually set apart variables from other things. so it's more for readability than anything else.
poop is used as the name of all return values in functions because poop is the .. output of the body (i mean seriously, you can look at the function and instantly see all the places where the return value is being manipulated (where all the poops are). you can hardly do the same if you had named it 'ret' or something like that. and there's not even the need to use a code editor and double-click to "highlight all instances" )
the Dango emoji is used for arrays because ... it just looks like an array
the knife is for strings waiting to be parsed i.e. chopped up, etc.
stealzy
Posts: 91
Joined: 01 Nov 2015, 13:43

Re: ListGlobalVars_and_also_print_arrays()

25 Apr 2017, 10:46

poop is the .. output of the body
What about parameters? Just wondering which emojis used for.
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: ListGlobalVars_and_also_print_arrays()

26 Apr 2017, 06:54

stealzy wrote:
poop is the .. output of the body
What about parameters? Just wondering which emojis used for.
it depends on the type. i use (had to post an image because emojis forum doesn't accept emojis):
Image

etc.
http://www.emojicode.org/ has some inspirations!
User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: ListGlobalVars_and_also_print_arrays()

26 Apr 2017, 07:24

Isn't it a pain having to copy the emojis every time you need to reference them?
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: ListGlobalVars_and_also_print_arrays()

26 Apr 2017, 07:58

are you telling me you don't have a dedicated emoji modifier? :D

Image

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 177 guests