Actually, Samuel - it's not safe to assume even under TC 7.56 - that the listboxes will be TMyListBox1 and TMyListBox2 --- when you display the various Tree's (or FTP is active if I recall) - the main fileList listboxes will change number (higher) - but they will always be the last ListBoxes.
This is how I safely get the TMyListBox control numbers:
/*
** Basically, it finds all of the controls that are TMyListBox#
** and the File ListBoxes will be the last 2.
*/
Code: Select all
LB_QueryActiveWinID( aWin="A", winText="", notTitle="", notText="" )
{
return WinActive(aWin+0 ? "ahk_id " aWin : aWin, winText, notTitle, notText)
}
LB_QueryFocusedCtrlID( byRef aControl, byRef aWin="", winText="", notTitle="", notText="" )
{
LB_QueryActiveWinID( aWin, winText, notTitle, notText )
if( !aControl )
ControlGetFocus, aControl, ahk_id %aWin%, %winText%, %notTitle%, %notText%
;MsgBox, QFC: %aControl%`naWin:%aWin%
ControlGet, aControl, HWND,, %aControl%, ahk_id %aWin%
return aControl
}
;;
;; Returns the active FilePanel's controlID, and both FileList controlID's byRef.
;;
LB_QueryPanelIDsOnly(byRef cID2="", byRef cID1="", aWin="A", byRef activeLR=1)
{
cID3:=0x1, dx:=0, aLR:=activeLR ;absolute:=(activeLR <> "S")
if( aWin=="" && !winID:=WinActive("ahk_class TTOTAL_CMD"))
return LB_QueryFocusedCtrlID( cID2, winID:="A" )
onErrorExit(!winID:=WinExistA(aWin), "ERROR: Cannot Find Window [ " aWin " ]", A_ThisFunc)
while( (cID2:=cID3) && LB_ControlGetID(cID3, "TMyListBox" (++dx), winID) && cID1:=cID2 )
continue
ControlGetFocus, cFocus, ahk_id %winID%
LB_ControlGetID( cID3, cFocus, winID )
return (inStr(cID1 "," cID2, cID3) == 1 ? cID1 : cID2)
;; The return value used to be inStr(cID1 "," cID2, cID3)
;; --- I don't recall why I did that, I changed it to the above for this post.
;; --- but it could very likely just be:
;; -----> return ( cID1 == cID3 ? cID1 : cID2 )
}
onErrorExit( checkEval, errMsg="", fn="", delay=3 )
{
if( !checkEval )
return 0
if((!ErrorLevel || ErrorLevel:=1) && !errMsg)
Exit
RegExMatch(fn, "^([^:]+)(::([^ ].*))?$", rTmp )
msg := ( rTmp1 ? rTmp1 "(" rTmp3 "): " : "" ) errMsg
MsgBox,, % A_ScriptName " :: " rTmp1, % msg, % delay
Exit
}
How to use, with TC7, as my whole TC.ahk library will need to be changed for TC8.
And at this point I don't know if I can make my TC.ahk and LB.ahk libraries compatible with TC8 x64 or not.
TC_HWND:=WinActive("ahk_class TTOTAL_CMD")
aPanel:=LB_QueryPanelIDsOnly(TC_HWND, cPanelA:="", cPanelB:="")
Then there's this one, which was the original function, it can determine which FilePanel is "active" even when TC is minimized or not the active window.
Code: Select all
/*
** TC_QueryPanelID()
**
** Return: HWND (ID) of the Active FileList Panel (TMyListBox#)
**
** Input Parameters: Output Parameters:
1& cID2: "" ID of L.Panel (if input activeLR<>1), else Source
2& cID1: "" ID of R.Panel (if input activeLR<>1), else Target
3 aWin: "WinTitle" or HWND -
4& activeLR: 0,1 (Boolean) "Left" or "Right" (active Panel)
**
*/
LB_QueryPanelID(byRef cID2="", byRef cID1="", aWin="A", byRef activeLR=1)
{
cID3:=0x1, dx:=0, aLR:=activeLR ;absolute:=(activeLR <> "S")
if( aWin=="" && !winID:=WinActive("ahk_class TTOTAL_CMD"))
return LB_QueryFocusedCtrlID( cID2, winID:="A" )
onErrorExit(!winID:=WinExistA(aWin), "ERROR: Cannot Find Window [ " aWin " ]", A_ThisFunc)
while( (cID2:=cID3) && LB_ControlGetID(cID3, "TMyListBox" (++dx), winID) && cID1:=cID2 )
continue
if( !ErrorLevel:=!(WinActive("A") == winID) )
{
; MsgBox, sending ESC...
; Send, {ESC}
ControlGetFocus, activeLR, ahk_id %winID%
}
else
{
TC_CMD("cm_ShowQuickSearch", winID)
WinWait, QUICKSEARCH ahk_class TQUICKSEARCH
WinGetPos, tpX,,,, % "ahk_id " LB_ControlGetID( tp1, "TPanel1", winID )
WinGetPos, qsX,,,, % "ahk_id " qikS:=WinExist("QUICKSEARCH ahk_class TQUICKSEARCH")
ControlSend,, {ESC}, ahk_id %qikS%
activeLR:="TMyListBox" (qsX > tpX ? dx-2 : dx-1) ; ? "Right" : "Left")-
}
LB_ControlGetID( cID3, activeLR, winID )
activePanel:=activeLR
if((activeLR:=(cID3 == cID1 ? "Right" : "Left")) && aLR && cID3 == cID1)
LB_Swap(cID1, cID2)
;MsgBox, winID: %winID%`nActivePanel: %cID3% (%activePanel%) [%activeLR%]`nReturnValue: %cID2%`nOtherPanel:: %cID1%
return (cID2)
}
LB_Swap( byRef v1, byRef v2, dx="" )
{
v3:=v1,v1:=v2,v2:=v3
return (dx=="" ? TRUE : v%dx%)
}
LB_ControlGetID( byRef cID, cName, wID="" )
{
;; LB_QueryActiveWinID( winID )
ControlGet, cID, HWND,, %cName%, ahk_id %wID%
return cID
}
Replace TC_CMD() with the relevant command# for activating quickSearch --- as that is a lot more code that more heavily relies on my TC.ahk LIB and self-defined functions in AHK_F.ahk