Press: Win+S, create the Test Listbox
Press: Shift+Win+A, Test the Listbox
Switch over to TC when it's active Panel is in TC's install DIR
Press: Shift+Win+T, to Test TC's "LB_FindString" on TC's Listbox which fails (returns MAXINT).
All of the normal ListBox messages seem to work with TC except for LB_FINDSTRING and LB_FINDSTRINGEXACT ...
Code: Select all
return
#s::
Gui Add, ListBox, vColorChoice Multi R10, Red|Green|Blue|Black|White|Cyan|Yellow|Magenta
Gui Show, , Test of ListBox
Return
+#t::TCPanelTest()
+#a::LBTest()
LBTest()
{
ControlGet, lbID, HWND,, ListBox1, % "ahk_id " WinExist("Test of ListBox ahk_class AutoHotkeyGUI")
retVal:=LB_FindString( lbID, "Bl", select:=TRUE)
MsgBox, retVal: %retVal%
return
}
TCPanelTest()
{
panel:=LB_QueryActivePanelID(cID, cID2)
retVal:=LB_FindString( panel, "TotalCMD.exe", select:=TRUE )
MsgBox, retVal: %retVal%
return
}
LB_QueryCursor( byRef cID )
{
LB_GETCURSEL = 0x188
NULL = 0x0
SendMessage, LB_GETCURSEL, NULL, NULL,, ahk_id %cID%
return ( ErrorLevel <> "FAIL" ? ErrorLevel + 1 : 0 )
}
LB_SelectItem( cID, item="" )
{
LB_SETSEL = 0x0185
NULL = 0x0
item:=(item="") ? LB_QueryCursor(cID) : item
SendMessage, LB_SETSEL, TRUE, % item - 1,, ahk_id %cID%
return
}
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
}
LB_ControlGetID( byRef cID, cName, wID="" )
{
LB_QueryActiveWinID( winID )
ControlGet, cID, HWND,, %cName%, ahk_id %wID%
return cID
}
LB_Swap( byRef v1, byRef v2, dx="" )
{
v3:=v1,v1:=v2,v2:=v3
return (dx=="" ? TRUE : v%dx%)
}
LB_QueryActivePanelID( byRef cID2, byRef cID1="", absolute=FALSE, force=FALSE )
{
if(!winID:=WinActive("ahk_class TTOTAL_CMD"))
{
return LB_QueryFocusedCtrlID( cID2, winID:="A" )
; return !(ErrorLevel:=2)
}
dx:=( LB_ControlGetID(cID3, "TMyListBox3", winID) ? 2 : 1)
cID1:=LB_ControlGetID(cID1, "TMyListBox" dx, winID)
cID2:=LB_ControlGetID(cID2, "TMyListBox" (++dx), winID)
Loop, 2
{
ControlGetFocus, aCF, ahk_id %winID%
cID3:=LB_ControlGetID(cID3, aCF, winID)
if( (!ErrorLevel:=!(cID3==cID2 || (cID3==cID1 && (absolute || LB_Swap(cID1,cID2))) ) ) || !force)
break
Send, {ESC}
Sleep, 0
}
return (ErrorLevel ? 0 : cID3)
}
LB_FindString( cID, sFind="", select=TRUE )
{
LB_FINDSTRING = 0x018F
MAXINT:=4294967295, PrevError:=-1
if( !cID )
{
MsgBox,,, No ListBox!,1
return
}
While( NextError <> "FAIL" && ((begin:=(begin=="" ? 0 : NextError)) || TRUE ))
{
SendMessage, LB_FINDSTRING, %begin%, &sFind,, ahk_id %cID%
if( ((NextError:=ErrorLevel) <= PrevError ) || (NextError==MAXINT) )
break
PrevError:=NextError, result.=NextError "`n"
if( select )
{
LB_SelectItem( cID, PrevError + 1 )
}
}
;MsgBox, result: %result%`nNextError: %NextError%
return ( result ? result : NextError )
}
GuiClose:
GuiEscape:
ExitApp