@Mr.Ghisler, TC's ListBoxes (Panels) ?

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

@Mr.Ghisler, TC's ListBoxes (Panels) ?

Post by *Balderstrom »

I have tested the below AHK code on many ListBoxes, and it works fine. Yet for TC it always fails.

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
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

BUMP.

Any reason why the windows messages, LB_FINDSTRING and LB_FINDSTRINGEXACT are non-functional in TC's Listboxes?
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48118
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Because they are virtual listboxes and contain no strings. You can use LB_GETTEXT (and LB_GETTEXTLEN) to get the details for each file.
Author of Total Commander
https://www.ghisler.com
Post Reply