Tales of DOS Window sizes and position - Know what is yours to control

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Tales of DOS Window sizes and position - Know what is yours to control

#1 Post by thefeduke » 15 Sep 2017 17:29

There have been several topics about adjusting sizes, positions and fonts. This is to make it easier to see what you actually have to work with.

Here is what you can take away from this topic:
  • a subroutine to textify some registry DWORD values
  • a batch script to display selected values for the subkeys of the HKCU Console registry entry.

I am interested in how the subkeys are created. I'll try to document my actions to make them appear, and hope that the more knowledgeable can help.

Meanwhile, here is the subroutine:

Code: Select all

:CoLines RegString Cols Lines -- returns columns and lines from registry string
::                 -- RegStr [in]  - variable name of the registry DWORD value,
::                                   where hiword is lines and loword is columns
::                 -- Cols   [out] - variable to return the horizontal component
::                 -- Lines  [out] - variable to return the vertical component
::
@Echo Off&SetLOCAL EnableDelayedExpansion
Rem Start "" http://www.dostips.com/forum/viewtopic.php?p=53345#p53345
::  Post subject: Re: commands to change CmdPrompt buffer size?
::  Posted: Fri Aug 11, 2017 6:39 am by elzooilogico
::  Last edited by elzooilogico on Thu Aug 17, 2017 8:01 am, edited 1 time in total.
::  08/12/2017 forked to CmdLayout.bat by thefeduke
::  09/15/2017 forked to CONstats.bat by thefeduke
    set "s=!%~1!"
    set "x=!s:~-4!"
    For %%L in ("!x!") Do set "y=!s:%%~L=!"
    set "x=0x!x!"
rem convert to Decimal
    set/a "x=x, y=y"
(ENDLOCAL & REM RETURN VALUES
    IF "%~2" NEQ "" SET /a %~2=%x%
    IF "%~3" NEQ "" SET /a %~3=%y%
)
Exit /B
and usage:

Code: Select all

set "rG=0x14a0064"
Call :coLines RG RGx RGy
set rG

In the Topic: Automated setup of DOS command window
acferrad wrote:No, FaceName for me is not in the key Console, it is in a key beneath Console called %SystemRoot%_system32_cmd.exe:

HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe

This is the problem: %SystemRoot% has a backslash in it.
[Edit: this was solved within that topic], but the following shows the results of that query as well as some window placement and dimensions:
Output wrote:[Console] ScreenBufferSize 0xe10064 100,225
[Console] WindowPosition 0x3f003f 63,63
[Console] WindowSize 0x190050 80,25

[Console\%SystemRoot%_system32_cmd.exe] WindowSize 0x370050 80,55

[Console\Command Prompt] ScreenBufferSize 0x13c0060 96,316
[Console\Command Prompt] WindowSize 0x1a0060 96,26

[Console\top Left] ScreenBufferSize 0x1bc0090 144,444
[Console\top Left] WindowPosition 0x160010 16,22
[Console\top Left] WindowSize 0x2a0051 81,42
That was the output on one of my Win7 systems. [Edit: This batch script has been reworked for flexibility]:

Code: Select all

@Echo Off&SetLOCAL EnableDelayedExpansion &Rem.and keep environment uncluttered.
::  CONstats.bat - 09/15/2017 forked from CMDstats.bat by thefeduke

::  backup of console registry item
    If NOT Exist "%Temp%\~Docs~\HKCU" MD "%Temp%\~Docs~\HKCU"
    for /f %%i in ('WMIC OS GET LocalDateTime /value') do for /f "tokens=2 delims==" %%j in ("%%i") do (set "dt=%%j"
        call set "dt=!dt:~,4!-!dt:~4,2!-!dt:~6,2!_!dt:~8,2!-!dt:~10,2!")
    >nul reg export "HKCU\Console" "%Temp%\~Docs~\HKCU\Console_%dt%.reg" /y

::  Reset work files
    If Exist "%Temp%\~Docs~\HKCU\Console_reg.txt" (
    Del "%Temp%\~Docs~\HKCU\Console_reg.txt")
    If Exist "%Temp%\~Docs~\HKCU\Console_stats.csv" (
    Del "%Temp%\~Docs~\HKCU\Console_stats.csv")

::  Store registry CONSOLE values for the whole tree in a list file
        For /F "tokens=1* delims=\" %%A in ('reg query "HKCU\Console" /S'
        ) Do (
Rem         Handle blanks in HKCU key and eliminate trailing blanks
            If /I "%%~B" EQU "" (
                >> "%Temp%\~Docs~\HKCU\Console_reg.txt" Echo.%%~A
            ) Else (
                >> "%Temp%\~Docs~\HKCU\Console_reg.txt" Echo.%%~A %%~B
            )
        )

::  Get registry CONSOLE values from the list file
    For /F "usebackq tokens=1-2,*" %%B in (
        `Type "%Temp%\~Docs~\HKCU\Console_reg.txt"`
    ) Do (
        If /I "%%B" NEQ "HKEY_CURRENT_USER" (
            If /I "!HKEYsw!" EQU "1" (
                >> "%Temp%\~Docs~\HKCU\Console_stats.csv" Echo.!HKCU!,%%~B,%%D
            )
        ) Else (
            Set "HKEYsw=1"
Rem         Handle blanks in HKCU key and eliminate trailing blanks
            If /I "%%~D" EQU "" (
                Set HKCU=%%C
            ) Else (
                Set HKCU=%%C %%D
            )
        )
    )
Echo.

::  order for display of all Console Windows
    Sort "%Temp%\~Docs~\HKCU\Console_stats.csv" ^
      /O "%Temp%\~Docs~\HKCU\Console_stats.csv"

::  display of all Console Windows dimensions
    For /F "usebackq tokens=1-3 delims=," %%B IN (
        `findstr /i "windowsize screenbuffersize windowposition" "%Temp%\~Docs~\HKCU\Console_stats.csv"`
    ) Do (
        If /I "%%~B" NEQ "!PrevLine!" Echo.
        set RG=%%~D
        Call :coLines RG RGx RGy
        Echo.[%%~B] %%~C %%~D !RGx!,!RGy!
        Set "PrevLine=%%~B"
    )

::  display some font info for all Console Windows
    For /F "usebackq tokens=1-3 delims=," %%B IN (
        `findstr /i "facename fontsize" "%Temp%\~Docs~\HKCU\Console_stats.csv"`
    ) Do (
        If /I "%%~B" NEQ "!PrevLine!" Echo.
        If /I "%%~C" EQU "facename" Set "Font=%%~D"
        If /I "%%~C" EQU "fontsize" (
            set RG=%%~D
            Call :coLines RG RGx RGy
            Echo.[%%~B] "!Font!" %%~C %%~D !RGx! !RGy!
        )
        Set "PrevLine=%%~B"
    )

Rem string %%SystemRoot%% was problematic but solved elsewhere
Rem in call reg query "HKCU\console\%%SystemRoot%%_system32_cmd.exe"
::  display of any Console name containing %systemroot% is a byproduct
    For /F "usebackq tokens=1-3 delims=," %%B IN (
        `findstr /i "systemroot" "%Temp%\~Docs~\HKCU\Console_stats.csv"`
    ) Do (
        If /I "%%~B" NEQ "!PrevLine!" Echo.
        set RG=%%~D
        Call :coLines RG RGx RGy
        Echo.[%%~B] %%~C %%~D !RGx!,!RGy!
        Set "PrevLine=%%~B"
    )

    Exit/B


:CoLines RegString Cols Lines -- returns columns and lines from registry string
::                 -- RegStr [in]  - variable name of the registry DWORD value,
::                                   where hiword is lines and loword is columns
::                 -- Cols   [out] - variable to return the horizontal component
::                 -- Lines  [out] - variable to return the vertical component
::
@Echo Off&SetLOCAL EnableDelayedExpansion
Rem Start "" http://www.dostips.com/forum/viewtopic.php?p=53345#p53345
::  Post subject: Re: commands to change CmdPrompt buffer size?
::  Posted: Fri Aug 11, 2017 6:39 am by elzooilogico
::  Last edited by elzooilogico on Thu Aug 17, 2017 8:01 am, edited 1 time in total.
::  08/12/2017 forked to CmdLayout.bat by thefeduke
::  09/15/2017 forked to CONstats.bat by thefeduke
    set "s=!%~1!"
    set "x=!s:~-4!"
    For %%L in ("!x!") Do set "y=!s:%%~L=!"
    set "x=0x!x!"
rem convert to Decimal
    set/a "x=x, y=y"
(ENDLOCAL & REM RETURN VALUES
    IF "%~2" NEQ "" SET /a %~2=%x%
    IF "%~3" NEQ "" SET /a %~3=%y%
)
Exit /B
[Edit: I have added Facename and some other font values that do not need the DWORD interpreted.]

John A.

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

Re: Tales of DOS Window sizes and position - Know what is yours to control

#2 Post by thefeduke » 16 Sep 2017 00:22

The following code was added to the original post:

Code: Select all

::  display some font info for all Console Windows
    For /F "usebackq tokens=1-3 delims=," %%B IN (
        `findstr /i "facename fontsize" "%Temp%\~Docs~\HKCU\Console_stats.csv"`
    ) Do (
        If /I "%%~B" NEQ "!PrevLine!" Echo.
        If /I "%%~C" EQU "facename" Set "Font=%%~D"
        If /I "%%~C" EQU "fontsize" (
            set RG=%%~D
            Call :coLines RG RGx RGy
            Echo.[%%~B] "!Font!" %%~C %%~D !RGx! !RGy!
        )
        Set "PrevLine=%%~B"
    )
Here is some sample output
Output wrote:[Console] "Terminal" FontSize 0x10000c 12 16

[Console\Command Prompt] "Lucida Console" FontSize 0x120000 0 18
Note that only font height is available for the non-raster font.

The code in the original example script was redone to be more general for additional queries like the one in this post.

John A.

Post Reply