MsgBox % "当前主显示器缩放:" A_ScreenDPI//A_ScreenDPI*100

MsgBox % "新的主显示器缩放:" SetPrimaryMonitorScaling(150)

; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=94218
SetPrimaryMonitorScaling(value) {
; possible values 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500
   static SPI_GETLOGICALDPIOVERRIDE := 0x009E
        , SPI_SETLOGICALDPIOVERRIDE := 0x009F
        , SPIF_UPDATEINIFILE := 0x00000001
        , MONITOR_DEFAULTTOPRIMARY := 0x00000001
        , ScaleValues := [100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500]
        
   for k, v in ScaleValues
      if (value = v && found := true)
         break
   if !found
      throw "Incorrect value: " . value . ". Allowed values: 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500"
   if !DllCall("SystemParametersInfo", "UInt", SPI_GETLOGICALDPIOVERRIDE, "Int", 0, "IntP", v, "UInt", 0)
      throw "SPI_GETLOGICALDPIOVERRIDE unsupported"
   if !recommendedScaling := ScaleValues[ 1 - v ]
      throw "Something wrong"
   for k, v in ScaleValues {
      (v = value && s := k)
      (v = recommendedScaling && r := k)
   } until s && r
   if !DllCall("SystemParametersInfo", "UInt", SPI_SETLOGICALDPIOVERRIDE, "Int", s - r, "Ptr", 0, "UInt", SPIF_UPDATEINIFILE)
      throw "Failed to set new scale factor"
   hMon := DllCall("MonitorFromWindow", "Ptr", 0, "UInt", MONITOR_DEFAULTTOPRIMARY, "Ptr")
   DllCall("Shcore\GetScaleFactorForMonitor", "Ptr", hMon, "UIntP", scale)
   Return scale
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。