How to directly preview a file programlly?
Moderators: Hacker, petermad, Stefan2, white
How to directly preview a file programlly?
From link1, it is possible to place cursor on a desired file, although not very robust right now.
The reason I would like to use the script actually is to preview the desired file using TC quick view.
So I am wondering is there any command that can be used to direclty preview a file, while no need to place the cursor on the file first.
link1:
viewtopic.php?t=78299
The reason I would like to use the script actually is to preview the desired file using TC quick view.
So I am wondering is there any command that can be used to direclty preview a file, while no need to place the cursor on the file first.
link1:
viewtopic.php?t=78299
Re: How to directly preview a file programlly?
Assuming that you have a filename of a file in question (that you want to be displayed in QuickView) in the clipboard, the following command will do the trick:
usercmd.ini:
How it works (example):
- copy a file name of one of the files in the active pane in the clipboard,
- place the cursor somewhere else (on other file),
- activate em_test_tc_command2 (e.g. from button bar),
- then:
--- cm_LoadSelectionFromClip (the first command in the commands chain) will select the file, which name is in the clipboard,
--- cm_GoToFirstEntry,cm_GoToNextSelected (the second, and third commands in the commands chain) will place the cursor on the said file,
--- cm_ClearAll (the fourth command in the commands chain) will remove the selection,
--- cm_SrcQuickview (the last command in the commands chain) will show the contents of the said file in the Quickview mode.
Notes:
The first, second, and third commands in the chain have no other purpose than to move the cursor on the file in question (there is no other known way to do that; then the fourth command clears the selection, thus clearing the traces of the command chain except the cursor positioning; in fact, the end user doesn't see that those commands are there, the user is just getting the result they needed).
In its turn, such a construction is required since the cm_SrcQuickview works only with a file under the cursor and doesn't accept arguments (such as filename; otherwise the entire command could be much simpler).
Example button:
Or you can use just a button (without a user command in usercmd.ini):
Edit:
With a bit different approach to place the cursor on the file in question using em_cd proxy command (thanks to Fla$her):
Note: as you can see, the command chain is native, no other tools/scripts are involved.
usercmd.ini:
Code: Select all
[em_test_tc_command2]
cmd=cm_LoadSelectionFromClip,cm_GoToFirstEntry,cm_GoToNextSelected,cm_ClearAll,cm_SrcQuickview
- copy a file name of one of the files in the active pane in the clipboard,
- place the cursor somewhere else (on other file),
- activate em_test_tc_command2 (e.g. from button bar),
- then:
--- cm_LoadSelectionFromClip (the first command in the commands chain) will select the file, which name is in the clipboard,
--- cm_GoToFirstEntry,cm_GoToNextSelected (the second, and third commands in the commands chain) will place the cursor on the said file,
--- cm_ClearAll (the fourth command in the commands chain) will remove the selection,
--- cm_SrcQuickview (the last command in the commands chain) will show the contents of the said file in the Quickview mode.
Notes:
The first, second, and third commands in the chain have no other purpose than to move the cursor on the file in question (there is no other known way to do that; then the fourth command clears the selection, thus clearing the traces of the command chain except the cursor positioning; in fact, the end user doesn't see that those commands are there, the user is just getting the result they needed).
In its turn, such a construction is required since the cm_SrcQuickview works only with a file under the cursor and doesn't accept arguments (such as filename; otherwise the entire command could be much simpler).
Example button:
Code: Select all
TOTALCMD#BAR#DATA
em_test_tc_command2
WCMICON2.DLL
0
10028
Code: Select all
TOTALCMD#BAR#DATA
cm_LoadSelectionFromClip,cm_GoToFirstEntry,cm_GoToNextSelected,cm_ClearAll,cm_SrcQuickview
WCMICON2.DLL
0
-1
With a bit different approach to place the cursor on the file in question using em_cd proxy command (thanks to Fla$her):
Code: Select all
[em_cd_proxy]
cmd=cd
param=%S1\:
Code: Select all
[em_final_command]
cmd=cm_LoadSelectionFromClip,em_cd_proxy,cm_ClearAll,cm_SrcQuickview
Code: Select all
TOTALCMD#BAR#DATA
em_final_command
WCMICON2.DLL
0
-1
Last edited by beb on 2024-02-02, 07:27 UTC, edited 1 time in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Re: How to directly preview a file programlly?
No. For quick viewing, placing the cursor on the file is required. See the suggestions:valuex wrote: 2024-02-01, 14:40 UTC is there any command that can be used to direclty preview a file, while no need to place the cursor on the file first.
https://ghisler.ch/board/viewtopic.php?p=399570
https://ghisler.ch/board/viewtopic.php?p=414311
https://ghisler.ch/board/viewtopic.php?p=433591
2beb
Why such difficulties if there is CD command?
usercmd.ini:
Code: Select all
[em_cd]
cmd=cd
param=%Z%A
Overquoting is evil! 👎
Re: How to directly preview a file programlly?
2Fla$her
The cd command just wasn't working when I tested it in that scenario. I even suspected a bug, then installed the previous TC version, and it still didn't work for me, don't know why.
The cd command just wasn't working when I tested it in that scenario. I even suspected a bug, then installed the previous TC version, and it still didn't work for me, don't know why.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Re: How to directly preview a file programlly?
2beb
In which scenario exactly? Maybe you did something wrong?in that scenario
Overquoting is evil! 👎
Re: How to directly preview a file programlly?
2Fla$her
Because I tried it directly and it didn't work that way.
With the proxy em_cd it does work, though:
Because I tried it directly and it didn't work that way.
With the proxy em_cd it does work, though:
Code: Select all
[em_cd_proxy]
cmd=cd
param=%S1\:
Code: Select all
[em_final_command]
cmd=cm_LoadSelectionFromClip,em_cd_proxy,cm_ClearAll,cm_SrcQuickview
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Re: How to directly preview a file programlly?
That's what I assumed.
Then I'm even more perplexed. What is %S1, cm_LoadSelectionFromClip and cm_ClearAll for?

Overquoting is evil! 👎
Re: How to directly preview a file programlly?
Thanks for your reply.
CD command is really a little bit tricky.
This is the autohotkey V2 script that can focus on the desired file. (Open preview panel in TC first)
However, the VBA version (64bit) does not work. Any help will be appricated.
CD command is really a little bit tricky.

This is the autohotkey V2 script that can focus on the desired file. (Open preview panel in TC first)
Code: Select all
F1::
{
ThisFile:="D:\xxx\xxx.mhtml"
newPath:=ThisFile . "\:`r" . "\0"
SendMessage(0x433,4001,0,,"ahk_class TTOTAL_CMD") ; FocusLeft
SendMessage(0x433,3001,0,,"ahk_class TTOTAL_CMD") ; NewTab
TC_SetPath(newPath) ; CD to place cursor on file
}
TC_SetPath(userCommand)
{
; https://www.autohotkey.com/boards/viewtopic.php?p=538463&sid=4471e03917209854441ac07ebdc70901#p538463
static dwData := 17475 ;;Ord("C") +256*Ord("D")
static WM_COPYDATA := 0x4A
cbData := Buffer(StrPut(userCommand, 'CP0'))
StrPut(userCommand, cbData, 'CP0')
COPYDATASTRUCT := Buffer(A_PtrSize * 3)
NumPut('Ptr', dwData, 'Ptr', cbData.size, 'Ptr', cbData.ptr, COPYDATASTRUCT)
MsgResult:=SendMessage( WM_COPYDATA,, COPYDATASTRUCT,, 'ahk_class TTOTAL_CMD')
return MsgResult
}
However, the VBA version (64bit) does not work. Any help will be appricated.
Code: Select all
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPtr
Public Type CopyDataStruct
dwData As LongPtr
cbData As LongPtr
lpData As LongPtr
End Type
Private Const WM_COPYDATA = &H4A
Sub test()
Dim newPath As String
ThisFile = "D:\xxx\xxx.mhtml"
newPath = ThisFile & "\:\n" & "\0"
hwndTC = FindWindow("TTOTAL_CMD", vbNullString)
result = SendMessage(hwndTC, 1075, 4001, 0) 'FocusLeft
result = SendMessage(hwndTC, 1075, 3001, 0) 'NewTab
Call TC_SetPath(hwndTC, newPath) 'CD to place cursor on file
End Sub
Sub TC_SetPath(hwndTarget, UserCMD As String)
Dim cds As CopyDataStruct
cds.dwData = Asc("C") + 256 * Asc("D")
cds.cbData = Len(UserCMD) + 1
cds.lpData = StrPtr(UserCMD)
' Send the WM_COPYDATA message
result = SendMessage(hwndTarget, WM_COPYDATA, 0, cds)
End Sub
Re: How to directly preview a file programlly?
It is robust to place the cursor on the desired file.
Using this method, the origin application who send the message will lose focus.
I got to switch back the focus, which is not good for continous preview.
So if possible, please kindly consider to allow sendmessage to preview file without having to activate TC.
Thanks.
Re: How to directly preview a file programlly?
Will using cm_SeparateQuickView make any difference?
Re: How to directly preview a file programlly?
I've given you three topics where you can join with support.valuex wrote: 2024-02-04, 03:22 UTC So if possible, please kindly consider to allow sendmessage to preview file without having to activate TC.
No. This is a minimized analogue of F3, with the only difference being that it can be closed by the same command from the main TC window.
Overquoting is evil! 👎