Develop Delphi: how to set focus to left/right tab?

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

Moderators: Hacker, petermad, Stefan2, white

Post Reply
cadsky
Junior Member
Junior Member
Posts: 2
Joined: 2016-01-08, 10:34 UTC

Develop Delphi: how to set focus to left/right tab?

Post by *cadsky »

How I can set focus left tab after change directory?

Code: Select all

function TotalCommanderToSwitchDir(LeftPanelTargetDir: string): Boolean;
const
 MY_UTF8_HEADER:RawByteString=AnsiChar($EF)+AnsiChar($BB)+AnsiChar($BF);
var
 tcWnd: THandle;
 DataStruct: TCopyDataStruct;
 OutputString: RawByteString;
begin
  tcWnd := FindWindow('TTOTAL_CMD', nil);
  if tcWnd <> 0 then
  begin      
     OutputString:=MY_UTF8_HEADER+UTF8Encode(LeftPanelTargetDir+#$0D)
     DataStruct.dwData := Ord('C') + 256 * Ord('D');
     DataStruct.cbData := length(OutputString)+1;
     DataStruct.lpData := PAnsiChar(OutputString);
     SendMessage(tcWnd, WM_COPYDATA, {self}Application.Handle, Integer(@DataStruct));
     result := True;
  end
  else
   result := False;
end;
[/code]
User avatar
Dalai
Power Member
Power Member
Posts: 9960
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

I just posted my full example in this post. You can use it to open a directory in left or right panel. When doing so, TC will set the focus accordingly to left or right panel.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

The only thing I want to mention: this won't set focus to left or right tab, this will only change current directories in active tabs of left and right panels and (optionally) focus specific files in these tabs.

In order to make left panel active one should send cm_FocusLeft command:

Code: Select all

SendMessage(tcWnd, $433, 4001, 0);
(here $433 is a special message for passing internal commands to TC and 4001 is cm_FocusLeft command id)
User avatar
Dalai
Power Member
Power Member
Posts: 9960
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

2MVV
Well, you're right if the goal is to set focus on the left/right panel only. Taking the OP's other topic into account, there may be a need to change the directory (or set the focus on some file), too. Just wanted to mention this.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Post Reply