|
本帖最后由 sz_kent 于 2024-4-12 18:08 编辑
优化,结合分辨率与DPI比较,改当前DPI,可在PEcmd添加加载,
log在%ProgramFiles%\WinXShell\路径查看。
//更改DPI
EXEC !"%ProgramFiles%\WinXShell\WinXShell.exe" -luacode "ondisplaychanged(true)"
规则:
1920以下用100dpi
2k以下用120dpi
4k以下用150dpi
高于4k用170dpi
根据自己实际情况调整,
function ondisplaychanged(event)
local cur_res_x = Screen:GetX()
local cur_res_Y = Screen:GetY()
local cur_DPI = Screen:GetDPI()
writeLogFile = io.open("X:/Program Files/WinXShell/Display DPI Change.log", "a") --打开文件,添加方式
writeLogFile:write("--------------------------------------" .. "\n")
if event ~= nil then
writeLogFile:write(os.date("%H%M%S ") .. "Specify Change Display DPI" .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "Event Call Change Display DPI" .. "\n")
end
if cur_DPI ~= nil then
writeLogFile:write(os.date("%H%M%S ") .. "cur_DPI=" .. cur_DPI .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "cur_DPI=" .. type(cur_DPI) .. "\n")
cur_DPI = 0
end
if cur_res_x ~= nil then
writeLogFile:write(os.date("%H%M%S ") .. "cur_res_X=" .. cur_res_x .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "cur_res_X=" .. type(cur_res_x) .. "\n")
cur_res_x = 0
end
if cur_res_Y ~= nil then
writeLogFile:write(os.date("%H%M%S ") .. "cur_res_Y=" .. cur_res_Y .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "cur_res_Y=" .. type(cur_res_Y) .. "\n")
cur_res_x = 0
end
writeLogFile:write(os.date("%H%M%S ") .. "Display DPI will Be Change ..." .. "\n")
if cur_res_x >= 3840 then
if cur_DPI < 170 then
Screen:DPI(170) --设置4K(3840x2160)以上 --4K(3840x2160)、5K(5120x2880)、8K(7680x4320)
writeLogFile:write(os.date("%H%M%S ") .. "Display DPI change to 170." .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "No changes required, Display DPI is " .. cur_DPI .. " \n")
end
elseif cur_res_x >= 2560 then
if cur_DPI < 150 then
Screen:DPI(150) --设置2K(2560x1440)以上,4K以下
writeLogFile:write(os.date("%H%M%S ") .. "Display DPI change to 150." .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "No changes required, Display DPI is " .. cur_DPI .. " \n")
end
elseif cur_res_x > 1920 then
if cur_DPI < 120 then
Screen:DPI(120) --设置1K(1920x1080)以上,2K以下
writeLogFile:write(os.date("%H%M%S ") .. "Display DPI change to 120." .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "No changes required, Display DPI is " .. cur_DPI .. " \n")
end
else
if cur_DPI ~= 100 then
Screen:DPI(100) --设置1K(1920x1080)以下
writeLogFile:write(os.date("%H%M%S ") .. "Display DPI change to 100." .. "\n")
else
writeLogFile:write(os.date("%H%M%S ") .. "No changes required, Display DPI is " .. cur_DPI .. " \n")
end
end
cur_res_x = Screen:GetX()
cur_res_Y = Screen:GetY()
cur_DPI = Screen:GetDPI()
writeLogFile:write(os.date("%H%M%S ") .. "cur_DPI=" .. cur_DPI .. "\n")
writeLogFile:write(os.date("%H%M%S ") .. "cur_res_X=" .. cur_res_x .. "," .. "cur_res_Y=" .. cur_res_Y .. "\n")
writeLogFile:write(os.date("%H%M%S ") .. "Exit Display DPI set." .. "\n")
writeLogFile:write(" " .. "\n")
writeLogFile:close() --关闭文件
end |
|