本帖最后由 yakeyun 于 2023-1-15 14:25 编辑
回复 1# bcetl
既然只使用仅当前屏幕和扩展2种状态,那么直接检测当前系统的分辨率就可以了。如果分辨率屏幕宽度数值大于当前屏幕值,就属于扩展模式。反之相等就是仅当前屏幕模式。
弄错了,是检测截图的图片尺寸。借助了第三方截图工具(Snipaste),可以全屏截图2个屏幕,如果有更好的截图工具替代更好。- @echo off & setlocal enabledelayedexpansion
- cd /d %~dp0
-
- if exist JT.jpg del JT.jpg
- if exist JT.txt del JT.txt
- :RUN
- @Start Snipaste.exe snip --full -o .\JT.jpg
- timeout -t 2 >NUL
- IF NOT EXIST JT.jpg GOTO RUN
- ::设置要搜索的图片格式
- set Pic=JT.jpg
- ::设置要搜索的文件主路径
- set DirPath=.\
- call :CreatVBS
- timeout -t 2 >NUL
- cd /d "%DirPath%"
- (for /f "delims=" %%a in ('dir /a-d/s/b %Pic%') do (
- for /f "tokens=1-4 delims=x" %%b in ('cscript -nologo "%tmp%\GetImgInfo.vbs" "%%~sa"') do (
- echo 文件名: %%~nxa 像素: %%~bx%%~c 原始格式: %%~e 路径: %%~dpa
- )
- ))>"%~dp0JT.txt"
- timeout -t 2 >NUL
- for /f %%a in ('type "JT.TXT" ^|find "1920x1080"') do set DPI=1
- if defined DPI (displayswitch /extend)
- if NOT defined DPI (displayswitch /internal)
- EXIT
-
-
- :CreatVBS
- (echo '获取图片文件的宽、高、DPI、格式
- echo On Error Resume Next
- echo Dim Img
- echo Set Img = CreateObject^("WIA.ImageFile"^)
- echo Img.LoadFile WScript.Arguments^(0^)
- echo Wscript.Echo Img.Width ^& "x" ^& Img.Height ^& "x" ^& Img.HorizontalResolution ^& "x" ^& Img.FileExtension)>"%tmp%\GetImgInfo.vbs"
- goto :eof
复制代码 测试文件包:https://sanli.lanzoub.com/iokSL0l21gof |