Usage: tcshell2 /path/to/filename
ULinkProcess.pas
procedure TryToLocateFileInTC(fullpath: string); var htcmd: HWND; //the HWND of Total Commander pbuf: PChar; function FindFileListBox(var idx: Integer): HWND; var title: array[0..1024] of char; hlist: HWND; count, row, len: integer; basename: string; begin Result := 0; idx := -1; basename := ExtractFileName(fullpath); hlist := FindWindowEx(htcmd, 0, 'TMyListBox', nil); while (hlist<>0) do begin GetWindowText(hlist, title, 1024); if StrLen(title)=0 then begin count := SendMessage(hlist, LB_GETCOUNT, 0, 0); for row := 0 to count-1 do begin len := SendMessage(hlist, LB_GETTEXTLEN, row, 0); GetMem(pbuf, len+1); try if LB_ERR<>SendMessage(hlist, LB_GETTEXT, row, Integer(pbuf)) then if SameText(basename, Copy(StrPas(pbuf), 0, Length(basename))) then begin idx := row; Result := hlist; exit; end; finally Dispose(pbuf); end; end; end; //try next listbox hlist := FindWindowEx(htcmd, hlist, 'TMyListBox', nil); end; end; var idx, row: Integer; hlistbox: HWND; title: array[0..1024] of char; begin //don't bother with directory if DirectoryExists(fullpath) then exit; htcmd := FindWindow('TTOTAL_CMD', nil); if (0=htcmd) then exit; GetWindowText(htcmd, title, 1024); idx := -1; hlistbox := FindFileListBox(idx); if (hlistbox=0) or (idx<0) then exit; AppActivate(title); //FIXME: the key can only be sent to the source list, not the target list // so it won't work, if '/S /R' used to invoke TC, SendKeys('{HOME}', true); for row := 0 to idx-1 do SendKeys('{DOWN}', true); end;