added my archive of older versions of WindowSpy.ahk for v2 alpha
2021/06/21
tested and working on a137
2021/05/29
made some changes suggested by lexikos
cleaned up some redundant code
found an instance of crashes and fixed it (thanks again to lexikos)
2021/05/08
changes for a134
changed BufferAlloc() to Buffer()
2021/04/16
tested and working on a131
2021/03/08
updated for a128
added &VarRef entries where needed
declared Global oGui where needed within functions
changed function references from strings to the function name (unquoted)
~*Ctrl:: and ~*Shift:: have been changed to ~Ctrl:: and ~Shift (the * seemed to break both the key up and key down events when present on the keydown event)
2020/09/10
re-pasted my latest working copy of WindowSpy (haven't used #Include TheArkive_Debug.ahk for a while, not sure how this post got out of sync, but it is back in sync now
previously -DPIScale caused the scaling to be handled by windows without issues. Now +DPIScale seems to be required in order to maintain the scaling.
2020/09/07
No update - works in a122
2020/07/31
Test on a119 - no issues so far
2020/07/19
Line 165-166: Added Try to avoid occasional errors when LastWindowDetected isn't found.
Line 198-201: Simplified this statement to be more appropriate for AHK v2 and to avoid an unexpected memory read/write error.
Working on a117 - changes made should function well on a115-a116 in case you revert back to these versions.
2020/07/17
Fixed minor error with CoordMode "Mouse", "Relative" - changed "Relative" to "Window"
Now working on AHK v2-a116
2020/07/01
Tested on v2-a113, with rapidly changing window focus, no issues so far
2020/06/20
changed GuiCreate() to Gui.New()
removed A_IsUnicode
2020/06/18
added braces for multi-line hotkeys
2020/06/11
a few stability fixes when quickly moving the mouse over several windows
@burque505 glad to know it's helping someone ... I've been wanting to mess around with AHKv2 for a while, but only a few months ago did I have time to really dig in to the installation, syntax, and everything else. I found this tool to be vital for me to find window information to figure out how to compose certain scripts.
@TheArkive Thank u for preserving all the original calculations and stuff. This code, when compared to the original v1 code side by side, can be a good example for ones struggling to convert v1 GUI code for v2-108!
@vvhitevvizard
That was part of the idea for sure, and it makes life easier when really digging in to AHK v2 and setting up your system to really start AHK v2 coding.
Looks nearly identical, not sure if this because of DPI scaling but with Win 10 at 125% DPI I get the text boxes pushed too far to the left. Here is a comparison of me running a AHK .exe file of Window Spy for v1 next to your v2 version.
Nice work! I was just actually about to make this myself the other day but got distracted and did something else :p
Thanks @Steely Wing, I updated the OP and included your link.
My rewrite is currently working in a122 so I'm not updating mine yet. I'll take a closer look at yours at some point too.
I haven't bothered to do a true "rewrite" yet... I was just wanted to maintain a functional version for AHK v2 alpha, and I wanted to make minimal changes to preserve the original code (as mush as possible) for people looking for some potential examples of AHK v1 / v2 equivalent code.
Just tried this out again and still getting some odd control sizing again. Seems like nothing works as good as a compiled v1 version XD.
Also, you need to take out the #INCLUDE TheArkive_Debug.ahk from the top of the script since I don't think you intended to leave that in there
On a side note, the #SingleInstance, Ignore is annoying lol but I understand that's probably leftovers from original author.
Example:
I also tried @Steely Wing's version which appeared to work a little better visually, however I did get a string warnings and errors when trying to take this screenshot using ShareX:
declared Global oGui where needed within functions
changed function references from strings to the function name (unquoted)
~*Ctrl:: and ~*Shift:: have been changed to ~Ctrl:: and ~Shift (the * seemed to break both the key up and key down events when present on the keydown event)
Would you like to submit a pull request to AutoHotkey-Release, adding this under installer/source/WindowSpy.v2.ahk? (Ideally after fixing the following issues.)
Your indentation style looked a bit strange, until I realized that some lines used spaces and the rest used tabs (like the original script). GitHub shows the tabs as 8 spaces, so it really stands out.
The script often shows an error message when I close a window, or (strangely enough) open a window. It also shows an error message if I activate a hidden window, which happens when any script displays a popup menu with Menu Name, Show or MenuObj.Show(). It is impossible to predict when the target window will be closed, so I suppose it would be appropriate to abort the update when an error occurs. At first I thought it could empty the GUI or show that there was an error, but a subsequent update would overwrite it, and if there's no subsequent update (because a hidden window is still active), it's better to retain whatever was already in the GUI. This appears to be sufficient:
Steely Wing's version uses OnError to suppress all error messages. I would not use OnError this way in an "official" script, even if the end result is actually the same.
There are (at least?) two errors in WinGetTextFast:
The buffer size is half what it should be (also, I would remove the comment; Buffer and A_IsUnicode never existed in the same version).
The lack of "`r`n" causes all of the text to be lumped together, like SourceSourceRunAHKToolbar4SciTETab.
The error handling in WinGetTextFast makes it closer to its counterpart in Window Spy v1, but inconsistent with WinGetText. I think it would be better to instead let exceptions propagate to the caller, so they are handled (or unhandled) the same way as for WinGetText. In other words, remove Try, If and Else and let the caller handle the error.
If I was to use control := ""try control := WinGetControlsHwnd(), I would tend to prefer if controls or if controls != "" over if (Type(controls) = "Array"), since the type name of the value isn't really relevant; only that the function succeeded, in which case it always returns an Array. In v2.0-a131+, this is valid:
; WinGetText ALWAYS uses the "fast" mode - TitleMatchMode only affects to retrieve the text
; of each control. WinText/ExcludeText parameters. In Slow mode, GetWindowText() is used.
The part in red appears to be a copy-paste error, or maybe a failed attempt to fix the "slow" and "fast" being around the wrong way, which is an error in the original script. The fixed version of the original comment is:
; WinGetText ALWAYS uses the "slow" mode - TitleMatchMode only affects
; WinText/ExcludeText parameters. In "fast" mode, GetWindowText() is used
; to retrieve the text of each control.
This code, when compared to the original v1 code side by side, can be a good example for ones struggling to convert v1 GUI code for v2
Do you want me to remove all the instances of Try in the TryUpdate func? Your solution of wrapping it in its own func and using one Try statement is of course cleaner.
EDIT: All those Try instances were me trying to do what you just suggested
No. The overall try should cover cases where the target window disappears mid-update or wasn't detected to begin with, but there are other possible errors.
For instance, curCtrlClassNN := ControlGetClassNN(curCtrl) will fail if there is no control, so now the info won't update if "Follow Mouse" is on and you mouse over the window itself and not a control; or if the window has no controls. It's actually not even used until after if (curCtrl) is checked, so it should just be moved there (no try needed for that one).
I would suggest replacing GetClientSize with WinGetClientPos. Aside from eliminating redundant code, it might be useful to show the position of the client area (which is in screen coordinates) rather than x: 0 y: 0.