Discovered AHK 3 weeks before now. Its awesome and I want to thank the developpers first.
So before posting I have red the AHK docs ALOT and found many useful info also many useful forums topics.
But I still can't figure out this case. Any help would be greatly appreciated
This post is about dealing with variable/changing ClassNN of CONTROLS.
I have managed to deal with variable Windows Classes containing subpatterns because RegEx SetTitleMatchMode allows us to do this very well.
The problem is that it doesn't work for me when its related to variable/changing CONTROL CLASSNN.
Here is a visualisation of what I'm talking about before I go further. WindowSpy reports:
Focused Window: ahk_class WindowsForms10.Window.8.app.0.141b42a_r38_ad1
Focused Control: ClassNN: WindowsForms10.EDIT .app.0.141b42a_r38_ad17
As you can see there are clear subpatterns and this is fine. Its not the problem. I understand them now in this particular program.
Problem is the subpattern, that is changing from client to client with this program (Sage 50 Canadian edition),
is the colored part in the middle of the haystack.
What I want to do now, instead of having a complex RexExMatch() everytime there is a variable CONTROL to act on in the script,
1. Find what is the active Window's SUBPATTERN on auto-execute of script
2. Store it in a variable containing it as long as the script runs
3. Insert this found and stable subpattern in the middle of ANY variable CONTROL classNN to identifie them without requiring a unneccessary RegExMatch
Why I want this:
-Because, if the common and fixed subpattern is found on auto-execute as shown bellow in code example, then why would it need to RegExMatch each CONTROL CLASSNN anytime I need to use them?
-Documentation seems to say in many palces that RegExMatch is not the fastest performing and I want the fastest/lightest way of coding this script.
-I think it is much easier to find the pattern once on auto-execute and use it everywhere in the script as needed rather than re-running a RegExMatch every time a CONTROL CLASSNN needs to be identified exactly
Here is the code example taken from a part of the script:
;This is PART of auto-execute section:
;Please focus your attention on the fact that I find the current subpattern on auto-execute so the variable contains the subpattern for all windows and controls of this client
SetTitleMatchMode, RegEx ; Changes WinTitle, WinText, ExcludeTitle, and ExcludeText to accept regular expressions.
if WinExist(.SAI) ; Sage openned active client WinTitle Exists
WinGetTitle, SageActiveClient ;I use the current Wintitle for my client name in GUI
SageActiveClient:=StrReplace(SageActiveClient, ".SAI") ;I need to get rid of the .SAI extension found in Wintitle previously
WinGetClass, SageWinClassPattern ;I retrieve the Full Class of this main Window because it contains the unique Subpattern and it will be my Haystack from which to retrieve it
;MsgBox %SageWinClassPattern% ;ahk_class WindowsForms10.Window.8.app.0.141b42a_r38_ad1
SageWinClassPattern:=SubStr(SageWinClassPattern, 31, -8) ; "WindowsForms10.Window.8.app.0." "_r38_ad1" (This Returns found string between start 31 and -8 from the end)
;MsgBox %SageWinClassPattern% ; 141b42a (this is the retrieved and stored to variable subpattern. It is present in all of this program's windows and controls)
MsgBox Open the Sage Client before loading the script.
;... more code under this auto-execute part
Later in the script only way I can make it work is using RegExMatch like this example which works in my script:
; Skip to TRANSPORT
winget, controls, ControlList, Achats|fournisseurs|Charges ;RegEx TitleMatchMode with different options
Loop, Parse, controls, `n
if(RegExMatch(A_LoopField, "WindowsForms10.EDIT.app.0.(?:.*)_r38_ad114", Match)) ; RegExMatch this control with the current subpattern
ControlClick, %Match%, Achats|fournisseurs|Charges,, Left
I want to do something like this but nothing I tried worked. I need to go back to the complex RegExMatch example as shown before.
ThisButtonClassNN:= WindowsForms10.EDIT.app.0.%SageWinClassPattern%_r38_ad114 ; I want to insert the found subpattern stored in the variable from the auto-execute example
;MsgBox %ThisButtonClassNN% ;Returns: WindowsForms10.EDIT.app.0.141b42a_r38_ad114
ControlClick, %ThisButtonClassNN%, Achats|fournisseurs|Charges,, Left
Ok so I think its the clearer I can get because I myself have trouble following all of this complexity.
Is it possible to do something like this, if not what are the best and simplest/most performant solutions?
THANKS a alot in advance for your time and help