Creator of Delphi module with cm_ commands variables

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
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Creator of Delphi module with cm_ commands variables

Post by *olesio »

Hello. I hope code below may be usefull for people who want to use send
cm_ commands from Delphi to TC using not Command as digits but as a
cm_XXXXXX constants. File totalcmd.inc in the same directory as project
is requeired. Output file - will be looks like this and below is source code.
I do not know how to add this code to wiki. Is is useful enought for wiki?

Usefyl function:

Code: Select all

var
  Tc_H : HWND;
begin
  TC_H := FindWindow('TTOTAL_CMD', nil);
  if TC_H <> 0 then
  begin
    SendTCCommand(cm_FocusLeft);
    SendTCUserCommand('em_openirclogstab');
    SetForegroundWindow(TC_H);
  end;
end.
Syntax

Code: Select all

  SendTCCommand(cm_FocusLeft);
Small cut of module (output file):

Code: Select all

unit tc_cm_consts;

interface

const
  cm_SrcComments = 300;
  // ... cut ...
  cm_ContentStopLoadFields = 5514;

implementation

end.
Source code of tc_cm_consts.pas creator:

Code: Select all

program tc_inc;

{$APPTYPE GUI}

uses
  Windows;

function FileExists(FileName : string) : boolean;
var
  Find : THandle;
  WFD : TWin32FindData;
begin
  Find := Windows.FindFirstFile(PChar(FileName), WFD);
  Result := Find <> INVALID_HANDLE_VALUE;
  FindClose(Find);
end;

const
  Sep1 = '=';
  Sep2 = ';';
  In_FileName = 'totalcmd.inc';
  Out_FileName = 'tc_cm_consts.pas';
  AppTitle = 'Creator of Delphi module with cm_ commands variables - by olesio';
var
  Line, Output : string;
  OldH, AppHandle : HWND;
  Sep1Pos, Sep2Pos : Word;
  InFile, OutFile : TextFile;
begin
  OldH := GetForegroundWindow;
  AppHandle := FindWindow('Shell_TrayWnd', nil);
  if FileExists(In_FileName) = False then
  begin
    MessageBox(AppHandle, PChar('Cannot find file: ' + In_FileName +
      ' - program terminated!'), PChar(AppTitle), MB_OK + MB_ICONERROR);
  end
  else
  begin
    Assign(InFile, In_FileName);
{$I-}
    Reset(InFile);
{$I+}
    if IOResult <> 0 then
    begin
      MessageBox(AppHandle, PChar('Cannot access file: ' + In_FileName +
        ' - program terminated!'), PChar(AppTitle), MB_OK + MB_ICONERROR);
    end
    else
    begin
      Assign(OutFile, Out_FileName);
{$I-}
      Rewrite(OutFile);
{$I+}
      if IOResult <> 0 then
      begin
        MessageBox(AppHandle, PChar('Cannot create file: ' + Out_FileName +
          ' - program terminated!'), PChar(AppTitle), MB_OK + MB_ICONERROR);
      end
      else
      begin
        Writeln(OutFile, 'unit ' + Copy(Out_FileName, 1, Pos('.', Out_FileName) - 1) + ';');
        Writeln(OutFile);
        Writeln(OutFile, 'interface');
        Writeln(OutFile);
        Writeln(OutFile, 'const');
        while EOF(InFile) = False do
        begin
          Readln(InFile, Line);
          if Pos('cm_', Line) = 1 then
          begin
            Sep1Pos := Pos(Sep1, Line);
            Sep2Pos := Pos(Sep2, Line);
            Output := Copy(Line, 1, Sep1Pos - 1) + ' = ' + Copy(Line, Sep1Pos + 1, Sep2Pos - Sep1Pos - 1);
            Writeln(OutFile, #32#32 + Output + ';');
          end;
        end;
        Writeln(OutFile);
        Writeln(OutFile, 'implementation');
        Writeln(OutFile);
        Write(OutFile, 'end.');
        Close(InFile);
        Close(OutFile);
        MessageBox(AppHandle, PChar('File: ' + Out_FileName +
          ' created.'), PChar(AppTitle), MB_OK + MB_ICONINFORMATION);
      end;
    end;
  end;
  SetForegroundWindow(OldH);
end.
Best regards: olesio
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I think better way is to use totalcmd.inc file to resolve command names because new TC versions may have new commands, and you will need to recompile application if you will use own constants module.
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Post by *olesio »

MAybe you have right, but in that case user - can recompile my code using new totalcmd.inc file
I guest numbers assigned to cm_ commands before do not change too often in new TC versions.
Best regards: olesio
User avatar
Alextp
Power Member
Power Member
Posts: 2321
Joined: 2004-08-16, 22:35 UTC
Location: Russian Federation
Contact:

Post by *Alextp »

2olesio
I do not know how to add this code to wiki. Is is useful enought for wiki?
I think not needed to post to wiki. This code is known(maybe w/o creating consts file), but consts file is also easy to get.
Post Reply