欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

命令行窗口自動居中之批處理版實現(xiàn)代碼(娛樂)

 更新時間:2023年07月05日 11:20:22   作者:Batcher  
這篇文章主要介紹了命令行窗口自動居中之批處理版實現(xiàn)代碼(娛樂),需要的朋友可以參考下

【方案一】比較原始的方法,思路比較容易理解。

@echo off
::Batcher@bbs.bathome.net
::2009-03-04
::命令行窗口自動居中之批處理版@CMD@XP
::http://bbs.bathome.net/thread-3582-1-1.html
setlocal enabledelayedexpansion
::指定命令行窗口字體大?。J(rèn)是8*16)
set FontWidth=8
set FontHeight=16
::指定命令行窗口大?。J(rèn)是80*25)
set WinCol=80
set WinRow=25
::ClearOldConf
for /f "tokens=3 delims=\" %%a in ('reg query HKEY_CURRENT_USER\Console^|findstr "_system32_cmd.exe"') do (
  if "%%a" neq "" (
    reg delete HKEY_CURRENT_USER\Console\%%a /va /f
  )
)
::SetFontSize
call :Dec2Hex %FontWidth% FontWidthH
call :Dec2Hex %FontHeight% FontHeightH
set FontWidthH=0000%FontWidthH%
set FontWidthH=%FontWidthH:~-4%
reg add HKEY_CURRENT_USER\Console /v FontSize /t reg_dword /d 0x%FontHeightH%%FontWidthH% /f
::SetWinSize
call :Dec2Hex %WinCol% WinColH
call :Dec2Hex %WinRow% WinRowtH
set WinColH=0000%WinColH%
set WinColH=%WinColH:~-4%
reg add HKEY_CURRENT_USER\Console /v WindowSize /t reg_dword /d 0x%WinRowtH%%WinColH% /f
::GetWinSize
set /a WinWidth=WinCol*FontWidth+33
set /a WinHeight=WinRow*FontHeight+45
::GetSrcSize
for /f "tokens=2 delims==" %%a in ('wmic desktopmonitor get screenwidth /value') do (
  set ScrWidth=%%a
  goto :GetSrcHeight
)
:GetSrcHeight
for /f "tokens=2 delims==" %%a in ('wmic desktopmonitor get screenheight /value') do (
  set ScrHeight=%%a
  goto :GetPosition
)
:GetPosition
set /a PosLeft=(ScrWidth-WinWidth)/2
set /a PosTop=(ScrHeight-WinHeight)/2
call :Dec2Hex %PosLeft% PosLeftH
call :Dec2Hex %PosTop% PosTopH
set PosLeftH=0000%PosLeftH%
set PosLeftH=%PosLeftH:~-4%
set PosTopH=0000%PosTopH%
set PosTopH=%PosTopH:~-4%
reg add HKEY_CURRENT_USER\Console /v WindowPosition /t reg_dword /d 0x%PosTopH%%PosLeftH% /f
start cmd
goto :eof
:Dec2Hex
set num=%1
set str=0123456789ABCDEF
set numDiv=%num%
set numConn=
:LoopD2H
set /a numMod=numDiv%%16
set numMod=!str:~%numMod%,1!
set /a numDiv/=16
set numConn=%numMod%%numConn%
if %numDiv% equ 0 (
  set %2=%numConn%
  goto :eof
)
goto :LoopD2H

【方案二】采用18樓pusofalse兄的方法:移位+或,可以縮短代碼、提高執(zhí)行效率。

@echo off
::Batcher@bbs.bathome.net
::2009-03-17
::命令行窗口自動居中之批處理版@CMD@XP
::http://bbs.bathome.net/thread-3582-1-1.html
setlocal enabledelayedexpansion
::指定命令行窗口字體大?。J(rèn)是8*16)
set FontWidth=8
set FontHeight=16
::指定命令行窗口大?。J(rèn)是80*25)
set WinCol=80
set WinRow=25
::SetFontSize
set /a "FontSizeD=FontHeight<<16|FontWidth"
call :Dec2Hex %FontSizeD% FontSizeH
reg add HKEY_CURRENT_USER\Console /v FontSize /t reg_dword /d 0x%FontSizeH% /f
::SetWinSize
set /a "WinSizeD=WinRow<<16|WinCol"
call :Dec2Hex %WinSizeD% WinSizeH
reg add HKEY_CURRENT_USER\Console /v WindowSize /t reg_dword /d 0x%WinSizeH% /f
::GetWinSize
set /a WinWidth=WinCol*FontWidth+33
set /a WinHeight=WinRow*FontHeight+45
::GetSrcSize
for /f "tokens=2 delims==" %%a in ('wmic desktopmonitor get screenwidth /value') do (
  set ScrWidth=%%a
  goto :GetSrcHeight
)
:GetSrcHeight
for /f "tokens=2 delims==" %%a in ('wmic desktopmonitor get screenheight /value') do (
  set ScrHeight=%%a
  goto :GetPosition
)
:GetPosition
set /a PosLeft=(ScrWidth-WinWidth)/2
set /a PosTop=(ScrHeight-WinHeight)/2
echo %PosLeft% %PosTop%
set /a "PosD=PosTop<<16|PosLeft"
call :Dec2Hex %PosD% PosH
reg add HKEY_CURRENT_USER\Console /v WindowPosition /t reg_dword /d 0x%PosH% /f
start cmd
goto :eof
:Dec2Hex
set num=%1
set str=0123456789ABCDEF
set numDiv=%num%
set numConn=
:LoopD2H
set /a numMod=numDiv%%16
set numMod=!str:~%numMod%,1!
set /a numDiv/=16
set numConn=%numMod%%numConn%
if %numDiv% equ 0 (
  set %2=%numConn%
  goto :eof
)
goto :LoopD2H

要刪除注冊表項才能還原了

到此這篇關(guān)于命令行窗口自動居中之批處理版實現(xiàn)代碼(娛樂)的文章就介紹到這了,更多相關(guān)命令行窗口自動居中內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論