Automated setup of DOS command window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Automated setup of DOS command window

#31 Post by miskox » 22 May 2014 10:04

@acferrad:

can you execute this command in your Fortran command prompt:

Code: Select all

echo %comspec%


I think that you are not using Windows' default command prompt but some other version and when you do a START command it launches the default CMD window (with all the settings in that registry hive I mentioned earlier). Your Fortran has settings somewhere else.

Saso

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Automated setup of DOS command window

#32 Post by penpen » 22 May 2014 11:43

1) If the default fonts haven't changed (by win version/edition/system ...; i am using win xp home 32 bit), then you may choose them with CmdFont.exe.
You may compile it (.NET is needed to be installed) by executing this "CmdFont.cs.bat" (use this name to avoid errors):

Code: Select all

// // >nul 2> nul & @goto :main
/*
 * Author: Ulf Schneider aka penpen
 * Free for non profit use only.
 * For profit use contact me at www.dostips.com via private message (PM).
 * CmdFont.cs.bat
 */

/*
:main
   @echo off
   setlocal
   cls

   set "csc="

   pushd "%SystemRoot%\Microsoft.NET\Framework"
   for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
      dir /a-d /b "%%~fi\csc.exe" >nul 2>&1 && set "csc="%%~fi\csc.exe""
   )
   popd

   if defined csc (
      echo most recent C#.NET compiler located in:
      echo %csc%.
   ) else (
      echo C#.NET compiler not found.
      goto :eof
   )

   for %%a in ("%~dpn0") do for %%b in ("%%~dpna") do (
rem      %csc% /?
      %csc% /nologo /optimize /warnaserror /nowin32manifest /unsafe /debug- /target:exe /out:"%%~b.exe" "%~f0"
   )
   exit /B
*/

using System;
using System.Runtime.InteropServices;

using DWORD = System.Int32;
using HANDLE = System.IntPtr;


public class CmdFont {
   public const DWORD STD_OUTPUT_HANDLE = (DWORD) (-11);

   [StructLayout (LayoutKind.Sequential)]
   internal struct COORD {
      internal short X;
      internal short Y;
   }

   [StructLayout (LayoutKind.Sequential)]
   internal unsafe struct CONSOLE_FONT_INFO {
      internal DWORD nFont;
      internal COORD dwFontSize;
   }


   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern int SetConsoleFont (HANDLE hOut, DWORD nFont);

   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern HANDLE GetStdHandle (DWORD nStdHandle);

   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern bool GetCurrentConsoleFont (
      HANDLE         consoleOutput,
      bool         maximumWindow,
      ref CONSOLE_FONT_INFO   lpConsoleCurrentFont
   );

   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern bool GetConsoleFontInfo (
      bool         bMaximumWindow,
      DWORD         nFontCount,
      ref CONSOLE_FONT_INFO   lpConsoleFontInfo
   );

   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern COORD GetConsoleFontSize (
      HANDLE   hConsoleOutput,
      DWORD   nFont
   );

   [DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true, SetLastError=true)]
   private static extern DWORD GetNumberOfConsoleFonts ();


   public const int HELP = 0;
   public const int GET = 1;
   public const int SET = 2;


   public static unsafe void Main (string[] args) {
      int option = HELP;
      int nFont = 0;

      switch (args.Length) {
         case 0:
            option = GET;
            break;

         case 1:
            option = (String.Compare ("GET", args [0], true) == 0) ? GET : HELP;
            break;

         case 2:
            try {
               nFont = int.Parse (args [1]);
               option = (String.Compare ("SET", args [0], true) == 0) ? SET : HELP;
            } catch {
            }
            break;

         default:
            option = HELP;
            break;
      }

      switch (option) {
         case SET:
            SetConsoleFont (GetStdHandle (STD_OUTPUT_HANDLE), nFont);
            break;

         case GET:
            CONSOLE_FONT_INFO info = new CONSOLE_FONT_INFO ();
            GetCurrentConsoleFont (GetStdHandle (STD_OUTPUT_HANDLE), false, ref info);
            COORD fontSize = GetConsoleFontSize (GetStdHandle (STD_OUTPUT_HANDLE), info.nFont);
            Console.WriteLine ("Font number: {0}/{1} ({2}, {3})", info.nFont, GetNumberOfConsoleFonts (), fontSize.X, fontSize.Y);
            Console.WriteLine ("Screen size: {0}, {1}", info.dwFontSize.X, info.dwFontSize.Y);
            Console.Out.Flush ();
            break;

         default:
            Console.WriteLine ("Usage: CmdFont[.exe] [GET|SET nFont]");
            Console.WriteLine ("  [GET]      Displays a message with:");
            Console.WriteLine ("              - the actual font number,");
            Console.WriteLine ("              - the actual font size, and");
            Console.WriteLine ("              - the actual console size.");
            Console.WriteLine ("  SET nFont  Sets the actual font number (nFont)");
            Console.Out.Flush ();
            break;
      }
   }
}
After you have compiled the executable you may set the default fonts (sample: default font number 6):

Code: Select all

CmdFont.exe SET 6
You may also like to see some few infos using:

Code: Select all

CmdFont.exe GET

In windows xp these modes are possible:

Code: Select all

Default fonts by number:
 0 Raster Font    width:  4, height:  6   
 1 Raster Font    width:  6, height:  8
 2 Raster Font    width:  8, height:  8
 3 Raster Font    width: 16, height:  8
 4 Raster Font    width:  5, height: 12
 5 Raster Font    width:  7, height: 12
 6 Lucida Console width:  7, height: 12
 7 Raster Font    width:  8, height: 12
 8 Raster Font    width:  8, height: 12
 9 Raster Font    width: 16, height: 12
10 Raster Font    width: 12, height: 16
11 Raster Font    width: 10, height: 18
(Sad to say there is only one Lucida consle font available.)

2) The first task could be done by using:

Code: Select all

mode CON COLS=132 LINES=9999
The second task could be done using c# again, just use this function in the main method:

Code: Select all

using System;

public class CmdScreen {
   public static void Main (string[] args) {
      try {
         int screen_x = int.Parse (args [0]);
         int screen_y = int.Parse (args [1]);

         Console.SetWindowSize (screen_x, screen_y);
      } catch {
      }
   }
}

3) I have no idea, how to enable QuickEdit and InsertMode without using the registry, sorry.

penpen

acferrad
Posts: 17
Joined: 21 May 2014 09:11

Re: Automated setup of DOS command window

#33 Post by acferrad » 22 May 2014 12:31

@Squashman ah yes sorry :lol:
Last edited by acferrad on 22 May 2014 12:36, edited 1 time in total.

acferrad
Posts: 17
Joined: 21 May 2014 09:11

Re: Automated setup of DOS command window

#34 Post by acferrad » 22 May 2014 12:35

wow thanks penpen, too much to fathom tonight, I'll take a look tomorrow.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Automated setup of DOS command window

#35 Post by thefeduke » 05 Sep 2017 22:47

penpen wrote:1) If the default fonts haven't changed (by win version/edition/system ...; i am using win xp home 32 bit), then you may choose them with CmdFont.exe.
You may compile it (.NET is needed to be installed) by executing this "CmdFont.cs.bat" (use this name to avoid errors):
A few places pointed me here. The posted output of this utility seemed attractive to parse for some screen and window calculations. The compilation appeared OK, the .exe file was created, but here is the kind of output that I got:
output wrote:C:\Users\Jancis\~Scripts~>cmdfont set 11

C:\Users\Jancis\~Scripts~>cmdfont get
Font number: 11/12 (13, 20)
Screen size: 13, 20

C:\Users\Jancis\~Scripts~>cmdfont set 10

C:\Users\Jancis\~Scripts~>cmdfont get
Font number: 10/12 (12, 20)
Screen size: 12, 20

C:\Users\Jancis\~Scripts~>where cmdfont /t
5632 9/4/2017 3:34:39 PM C:\Users\Jancis\~Scripts~\CmdFont.exe
I appreciate that this is dated material, but I could use a little help. The Screen size is not, but just a mirror of the font size.

Also, the numbers for font size become zeroes when I try to redirect the output. I tried on win7Pro, Win10Home and Win10Pro.

John A.

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

Re: Automated setup of DOS command window

#36 Post by nnnmmm » 06 Sep 2017 00:47

Code: Select all

>Because I open up other DOS windows in my BAT files, using START. When you do this it knows nothing about your default icon on the desktop and its defaults. So it gives you the Windows default, the dinky 80/300/80/25 with 8x12 Raster font.


this is exactly the same thing that happens in my win 8.1, unfixable so far.
win10 is remembering somewhat ok, console size doesnt match, but fonts type and its size stay the same as my default, so it is ok.
XP has no problem with it.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Automated setup of DOS command window

#37 Post by penpen » 06 Sep 2017 07:24

I had not much time to fix it since i noticed, that it is not working under newer windows versions.
This might help you until i created a new version:
http://www.dostips.com/forum/viewtopic.php?p=53304#p53304.


penpen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Automated setup of DOS command window

#38 Post by aGerman » 06 Sep 2017 09:50

Recently I worked again on penpen's script. I know he wanted to enumerate the installed raster fonts instead of using the array literal. It's implemented in the attached script.

(@penpen If you disagree with this upload just remove it.)

Steffen

CmdFont.cs.zip
(3.45 KiB) Downloaded 551 times

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Automated setup of DOS command window

#39 Post by aGerman » 24 Nov 2017 15:08

C# is annoying :(
Bugfix for unrecognized console output handle in redirections.

Steffen
Attachments
CmdFont.cs.zip
(3.63 KiB) Downloaded 552 times

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Automated setup of DOS command window

#40 Post by aGerman » 25 Nov 2017 10:18

EDIT Source Code updated (doesn't influence the functionality of the former version):
Signedness of variables corrected, CloseHandle added.
Attachments
CmdFont.cs.zip
(3.74 KiB) Downloaded 573 times

Post Reply