关于gui如何免受系统缩放的影响
请教各位大神,免受系统缩放的真正有效方法?做了个gui,是在100%屏幕缩放下配置的座标和尺寸,结果在放大的电脑屏幕上运行时惨不忍睹,试了论坛里的方法不好用,请教真正有效的方法。
GUICreate('',380,220)
GUISetState()
GUICtrlCreateLabel('',55,0,1,300)
GUICtrlSetBkColor ( -1 , 0x003366)
GUICtrlCreateButton("按钮",10,30,30,20)
GUICtrlCreateCheckbox("选择",10,100,40,20)
While 1
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd
win10系统,第1个是100%,第2个是125% Local $Result = DllCall('User32.dll', 'BOOL', 'SetProcessDPIAware')
If @error Then Return SetError(@error, 0, False)
Return $Result
这个是论坛里找的,不知为何不启作用。 你说的是字体,跟GUI没啥关系,固定字体大小试试? 遇到的是字变大了,导致需要调整按钮,checkbox等的xyw值才能正常,全改一遍一方面是工作量太大了,另一方面只是在当前的缩放比例下看着美观,换一个比例又不行了 如果能禁用当前程序缩放就省事了,不知怎样实现
禁用DPI缩放,来自本论坛
https://www.autoitx.com/forum.php?mod=viewthread&tid=72066&highlight=DPI h111666b 发表于 2023-9-22 17:59
禁用DPI缩放,来自本论坛
https://www.autoitx.com/forum.php?mod=viewthread&tid=72066&highlight=DPI
前面提到了,不好使 如果是因為介面跑位不好ˋ看
那就試著讓它自動縮放?
#Region 編譯資訊
;;使用管理員權限
#RequireAdmin
;;無系統匣圖示
;;#NoTrayIcon
;;https://www.autoitscript.com/wiki/AutoIt3Wrapper_Directives
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Icon=l2.ico
#AutoIt3Wrapper_UseX64=n
;;評論欄
#AutoIt3Wrapper_Res_Comment=
;;描述字段
#AutoIt3Wrapper_Res_Description=
;;文件版本
#AutoIt3Wrapper_Res_Fileversion=3.0.0.0
;;產品版本,默認是使用的 AutoIt3 版本。
;;#AutoIt3Wrapper_Res_ProductVersion=3.0.0.0
;;版權領域
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2022
;;資源語言代碼
#AutoIt3Wrapper_Res_Language=1028
;;請求可用的最高權限
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
;;Dpi感知
#AutoIt3Wrapper_Res_HiDpi=y
#cs
#AutoIt3Wrapper_res_Compatibility=Windows7
#AutoIt3Wrapper_Res_Field=AutoIt 版本|%AutoItVer%
#AutoIt3Wrapper_Res_Field=短日期格式的 PC 日期|%date%
#AutoIt3Wrapper_Res_Field=長日期格式的 PC 日期|%longdate%
#AutoIt3Wrapper_Res_Field=PC 時間格式|%time%
#ce
#EndRegion 編譯資訊
;;原始碼檢錯
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 6 -w 7
;;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#cs
Au3Check [-q] [-d] [-w[-] n]... [-v[-] n]... [-I dir]... file.au3
-q : 靜態 (僅輸出錯誤/警告)
-d : 等價於 Opt("MustDeclareVars", 1)
-w 1: 已包含檔案 (打開)
-w 2: 缺少 # comments-end (打開)
-w 3: 變數已聲明 (關閉)
-w 4: 局部變數在全域範圍內使用 (關閉)
-w 5: 局部變數已聲明, 但未使用 (關閉)
-w 6: 使用 Dim 時警告 (關閉)
-w 7: 傳遞常數或表示式到 ByRef 時警告 (打開)
-I dir: 搜尋其他目錄的包含檔案
-v 1: 顯示包含路徑/檔案 (關閉)
-v 2: 顯示詞法標記 (關閉)
-v 3: 顯示未引用 UDF 和全域變數 (關閉)
退出程式碼:
0: 成功: 沒有錯誤或警告
1: 警告
2: 語法錯誤
3: 使用或輸入錯誤
#ce
#cs ____________________________________
Au3版本:3.3.14.5
SciTE版本:3.6.6
腳本作者:
腳本功能:
參考代碼:
#ce _______________腳本開始_________________
#Region 載入Fuction
#include <WinAPI.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>
#EndRegion 載入Fuction
#Region 前置工作
;;判斷是否以管理員身份執行
Local $Admin
If IsAdmin() Then
$Admin = "目前以管理員權限執行"
Else
$Admin = "目前非管理員權限執行,可能造成部份功能無法使用。"
MsgBox(262144 + 48, '權限提示', $Admin)
EndIf
;;切換起始目錄工作目錄到腳本所在路徑
FileChangeDir(@ScriptDir)
;;防止重複執行
_Singleton(@ScriptName)
#EndRegion 前置工作
#Region 宣告變數
Global $HiDpi
Global $MainGuiWidth = 700 ;;介面寬
Global $MainGuiLength = 500 ;;介面高
;;全局字體及大小(備用字體:'Comic Sans Ms'、'YaHei Consolas Hybrid')
Global $FontSize = 12, $Font_Xing = 400, $Font_Var = Default, $Font_Quality = 5
Global $Font_Name = 'Microsoft JhengHei'
Global $Title = '最佳程式碼實現 DPI-自適應縮放'
Global $Version = 'v1.2.0.0 2022.11.04'
Global $Author = ''
Global $Copyright = $Author & ' 2022 Unlicense.' ;;版權宣告
Global Const $FileLogPath = @ScriptDir & '\_Log\' & @YEAR & "_" & @MON & "_" & @MDAY & ".log"
Global $AutoIt_Error = ObjEvent("AutoIt.Error", "_AutoIt_Error") ;;攔截Com錯誤
Global $LogFlag = 'N' ;;啟用Log模式
#EndRegion 宣告變數
#Region Opt模式
Opt("GUIResizeMode", 1) ;;設定GUI默認縮放模式,afan版主提供
Opt("GUIOnEventMode", 1) ;;使用事件模式
#EndRegion Opt模式
;;判斷是否編譯,使用不同策略設定和取得DPI
If @Compiled Then
If _IsProcessDPIAware() Then
$HiDpi = _GetDpi()
Else
$HiDpi = 1
EndIf
Else
_SetProcessDPIAware()
$HiDpi = _GetDpi()
EndIf
Global $MainGUI = GUICreate($Title & ' ' & $Version, $MainGuiWidth, $MainGuiLength, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetFont($FontSize, $Font_Xing, $Font_Var, $Font_Name, $MainGUI, $Font_Quality) ;;全局字型
GUISetBkColor(0xE6E6E6) ;;將變更背景色彩
GUICtrlCreateLabel('最佳程式碼實現 DPI-自適應縮放', 10, 10)
DPI_Zoom($MainGUI, $HiDpi) ;;以Dpi進行視窗調整
GUISetState(@SW_SHOW, $MainGUI)
;;GUISetState(@SW_LOCK, $MainGUI) ;;鎖定
;;GUISetState(@SW_UNLOCK, $MainGUI) ;;解除鎖定
While 1
Sleep(500)
WEnd
#Region 基本函式
Func _Exit() ;;離開軟體
If MsgBox(262144+36, '', '確定要退出嗎?', 0, $MainGUI) = 6 Then
Exit
EndIf
EndFunc
Func _AutoIt_Error($oError)
If $LogFlag <> 'Y' Then Return
Local $errinfo = ""
;;Do anything here.
$errinfo = @ScriptName & " (" & $oError.scriptline & ") AutoIt.Error : ==> COM Error intercepted !" & @CRLF & '---------------------' & @CRLF &_
@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF
_log($errinfo)
EndFunc ;==>_AutoIt_Error
Func _log($text)
_FileWriteLog($FileLogPath, $text)
EndFunc ;==>_log
#EndRegion 基本函式
#Region DPI函式
Func DPI_Zoom($hGUI, $hDpi) ;;縮放GUI,bfgxp提供
GUISetState(@SW_HIDE, $hGUI)
Local $aPos = WinGetPos($hGUI)
WinMove($hGUI, "", $aPos - ($aPos * $hDpi-$aPos)/2, $aPos - ( $aPos * $hDpi- $aPos)/2, $aPos * $hDpi, $aPos * $hDpi)
#cs
1.GUICreate建立的窗口大小是不包含邊框的,而WinMove改變窗口大小卻是包含邊框的。所以在WinMove之前,最好用WinGetPos獲取包含邊框的真實窗口大小,以便WinMove按比例放大
2.字型放大,經過我在不同DPI中的測試,最佳為 原字號 * (($HiDpi - 1) / 64 + 1)
另外提示愛玩的朋友:
WinMove之前的GUISetState(@SW_HIDE)很重要,沒有這個窗口中的控制項不會自動調整大小與位置
#ce
EndFunc
Func _SetProcessDPIAware()
Local $aRet
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$aRet = DllCall("User32.dll", "BOOL", "IsProcessDPIAware") ;檢查處理程序是否支援DPI感知
Return $aRet
If $aRet = False Then
$aRet = DllCall('User32.dll', 'BOOL', 'SetProcessDPIAware') ;設定:系統DPI感知
If @error Then Return SetError(@error, 0, False)
Return
EndIf
Else
$aRet = DllCall("Shcore.dll", "BOOL", "GetProcessDpiAwareness", "HWND", 0, "int*", 0) ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
If $aRet <> 2 Then ;;0:不支援DPI感知,1:系統DPI感知,2:監視器DPI感知
$aRet = DllCall("Shcore.dll", "BOOL", "SetProcessDpiAwareness", "int", 2) ;設定:監視器DPI感知
If @error Then Return SetError(@error, 0, False)
Return
EndIf
EndIf
EndFunc ;==>_SetProcessDPIAware
Func _GetDpi()
Local $iDPI
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$iDPI = RegRead("HKCU\Control Panel\Desktop\WindowMetrics", "AppliedDPI")
Else
Local $hWnd = _WinAPI_MonitorFromWindow(_WinAPI_GetDesktopWindow())
Local $aRet = DllCall("Shcore.dll", "BOOL", "GetDpiForMonitor", "HANDLE", $hWnd, "int", 0, "int*", 0, "int*", 0)
If @error Then Return SetError(@error, 0, False)
$iDPI = $aRet
EndIf
If $iDPI < 96 Or $iDPI > 480 Then $iDPI = 96
Return $iDPI / 96
EndFunc ;==>_GetDpi
Func _IsProcessDPIAware()
Local $aRet, $aDpi = 0
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$aRet = DllCall("User32.dll", "BOOL", "IsProcessDPIAware") ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
$aDpi = $aRet
Else
$aRet = DllCall("Shcore.dll", "BOOL", "GetProcessDpiAwareness", "HWND", 0, "int*", 0) ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
$aDpi = $aRet
EndIf
Return $aDpi
EndFunc ;==>_IsProcessDPIAware
#EndRegion DPI函式
本帖最后由 anythinging 于 2023-9-22 20:08 编辑
w60711 发表于 2023-9-22 19:08
如果是因為介面跑位不好ˋ看
那就試著讓它自動縮放?
感谢回复,我把这段代码放到你的代码里,好象没什么效果。
GUICtrlCreateLabel('',55,0,1,300)
GUICtrlSetBkColor ( -1 , 0x003366)
GUICtrlCreateButton("按钮",10,30,30,20)
GUICtrlCreateCheckbox("选择",10,100,40,20)
在100%无缩放的情况下,显示不全。 anythinging 发表于 2023-9-22 20:05
感谢回复,我把这段代码放到你的代码里,好象没什么效果。
GUICtrlCreateLabel('',55,0,1,300)
GUICtrl ...
因為我有設置字體大小啊
$FontSize = 12
正確用法為:你在目前的模式下,就應該要調整好文字、控件大小了
編譯以後,會隨著縮放~
如一開始不正確,縮放後還是不會正常的...
#Region 編譯資訊
;;使用管理員權限
#RequireAdmin
;;無系統匣圖示
;;#NoTrayIcon
;;https://www.autoitscript.com/wiki/AutoIt3Wrapper_Directives
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Icon=l2.ico
#AutoIt3Wrapper_UseX64=n
;;評論欄
#AutoIt3Wrapper_Res_Comment=
;;描述字段
#AutoIt3Wrapper_Res_Description=
;;文件版本
#AutoIt3Wrapper_Res_Fileversion=3.0.0.0
;;產品版本,默認是使用的 AutoIt3 版本。
;;#AutoIt3Wrapper_Res_ProductVersion=3.0.0.0
;;版權領域
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2022
;;資源語言代碼
#AutoIt3Wrapper_Res_Language=1028
;;請求可用的最高權限
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
;;Dpi感知
#AutoIt3Wrapper_Res_HiDpi=y
#cs
#AutoIt3Wrapper_res_Compatibility=Windows7
#AutoIt3Wrapper_Res_Field=AutoIt 版本|%AutoItVer%
#AutoIt3Wrapper_Res_Field=短日期格式的 PC 日期|%date%
#AutoIt3Wrapper_Res_Field=長日期格式的 PC 日期|%longdate%
#AutoIt3Wrapper_Res_Field=PC 時間格式|%time%
#ce
#EndRegion 編譯資訊
;;原始碼檢錯
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 6 -w 7
;;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#cs
Au3Check [-q] [-d] [-w[-] n]... [-v[-] n]... [-I dir]... file.au3
-q : 靜態 (僅輸出錯誤/警告)
-d : 等價於 Opt("MustDeclareVars", 1)
-w 1: 已包含檔案 (打開)
-w 2: 缺少 # comments-end (打開)
-w 3: 變數已聲明 (關閉)
-w 4: 局部變數在全域範圍內使用 (關閉)
-w 5: 局部變數已聲明, 但未使用 (關閉)
-w 6: 使用 Dim 時警告 (關閉)
-w 7: 傳遞常數或表示式到 ByRef 時警告 (打開)
-I dir: 搜尋其他目錄的包含檔案
-v 1: 顯示包含路徑/檔案 (關閉)
-v 2: 顯示詞法標記 (關閉)
-v 3: 顯示未引用 UDF 和全域變數 (關閉)
退出程式碼:
0: 成功: 沒有錯誤或警告
1: 警告
2: 語法錯誤
3: 使用或輸入錯誤
#ce
#cs ____________________________________
Au3版本:3.3.14.5
SciTE版本:3.6.6
腳本作者:
腳本功能:
參考代碼:
#ce _______________腳本開始_________________
#Region 載入Fuction
#include <WinAPI.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>
#EndRegion 載入Fuction
#Region 前置工作
;;判斷是否以管理員身份執行
Local $Admin
If IsAdmin() Then
$Admin = "目前以管理員權限執行"
Else
$Admin = "目前非管理員權限執行,可能造成部份功能無法使用。"
MsgBox(262144 + 48, '權限提示', $Admin)
EndIf
;;切換起始目錄工作目錄到腳本所在路徑
FileChangeDir(@ScriptDir)
;;防止重複執行
_Singleton(@ScriptName)
#EndRegion 前置工作
#Region 宣告變數
Global $HiDpi
Global $MainGuiWidth = 700 ;;介面寬
Global $MainGuiLength = 500 ;;介面高
;;全局字體及大小(備用字體:'Comic Sans Ms'、'YaHei Consolas Hybrid')
Global $FontSize = 12, $Font_Xing = 400, $Font_Var = Default, $Font_Quality = 5
Global $Font_Name = 'Microsoft JhengHei'
Global $Title = '最佳程式碼實現 DPI-自適應縮放'
Global $Version = 'v1.2.0.0 2022.11.04'
Global $Author = ''
Global $Copyright = $Author & ' 2022 Unlicense.' ;;版權宣告
Global Const $FileLogPath = @ScriptDir & '\_Log\' & @YEAR & "_" & @MON & "_" & @MDAY & ".log"
Global $AutoIt_Error = ObjEvent("AutoIt.Error", "_AutoIt_Error") ;;攔截Com錯誤
Global $LogFlag = 'N' ;;啟用Log模式
#EndRegion 宣告變數
#Region Opt模式
Opt("GUIResizeMode", 1) ;;設定GUI默認縮放模式,afan版主提供
Opt("GUIOnEventMode", 1) ;;使用事件模式
#EndRegion Opt模式
;;判斷是否編譯,使用不同策略設定和取得DPI
If @Compiled Then
If _IsProcessDPIAware() Then
$HiDpi = _GetDpi()
Else
$HiDpi = 1
EndIf
Else
_SetProcessDPIAware()
$HiDpi = _GetDpi()
EndIf
Global $MainGUI = GUICreate($Title & ' ' & $Version, $MainGuiWidth, $MainGuiLength, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetFont($FontSize, $Font_Xing, $Font_Var, $Font_Name, $MainGUI, $Font_Quality) ;;全局字型
GUISetBkColor(0xE6E6E6) ;;將變更背景色彩
GUICtrlCreateLabel('最佳程式碼實現 DPI-自適應縮放', 10, 10)
GUICtrlCreateLabel('', 75, 30, 1, 300)
GUICtrlSetBkColor(-1, 0x003366)
GUICtrlCreateButton('按钮1', 10, 30)
GUICtrlCreateButton('按钮2', 100, 30, 100, 30)
GUICtrlCreateCheckbox('选择1', 10, 100)
GUICtrlCreateCheckbox('选择2', 100, 100, 100, 30)
DPI_Zoom($MainGUI, $HiDpi) ;;以Dpi進行視窗調整
GUISetState(@SW_SHOW, $MainGUI)
;;GUISetState(@SW_LOCK, $MainGUI) ;;鎖定
;;GUISetState(@SW_UNLOCK, $MainGUI) ;;解除鎖定
While 1
Sleep(500)
WEnd
#Region 基本函式
Func _Exit() ;;離開軟體
If MsgBox(262144+36, '', '確定要退出嗎?', 0, $MainGUI) = 6 Then
Exit
EndIf
EndFunc
Func _AutoIt_Error($oError)
If $LogFlag <> 'Y' Then Return
Local $errinfo = ""
;;Do anything here.
$errinfo = @ScriptName & " (" & $oError.scriptline & ") AutoIt.Error : ==> COM Error intercepted !" & @CRLF & '---------------------' & @CRLF &_
@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF
_log($errinfo)
EndFunc ;==>_AutoIt_Error
Func _log($text)
_FileWriteLog($FileLogPath, $text)
EndFunc ;==>_log
#EndRegion 基本函式
#Region DPI函式
Func DPI_Zoom($hGUI, $hDpi) ;;縮放GUI,bfgxp提供
GUISetState(@SW_HIDE, $hGUI)
Local $aPos = WinGetPos($hGUI)
WinMove($hGUI, "", $aPos - ($aPos * $hDpi-$aPos)/2, $aPos - ( $aPos * $hDpi- $aPos)/2, $aPos * $hDpi, $aPos * $hDpi)
#cs
1.GUICreate建立的窗口大小是不包含邊框的,而WinMove改變窗口大小卻是包含邊框的。所以在WinMove之前,最好用WinGetPos獲取包含邊框的真實窗口大小,以便WinMove按比例放大
2.字型放大,經過我在不同DPI中的測試,最佳為 原字號 * (($HiDpi - 1) / 64 + 1)
另外提示愛玩的朋友:
WinMove之前的GUISetState(@SW_HIDE)很重要,沒有這個窗口中的控制項不會自動調整大小與位置
#ce
EndFunc
Func _SetProcessDPIAware()
Local $aRet
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$aRet = DllCall("User32.dll", "BOOL", "IsProcessDPIAware") ;檢查處理程序是否支援DPI感知
Return $aRet
If $aRet = False Then
$aRet = DllCall('User32.dll', 'BOOL', 'SetProcessDPIAware') ;設定:系統DPI感知
If @error Then Return SetError(@error, 0, False)
Return
EndIf
Else
$aRet = DllCall("Shcore.dll", "BOOL", "GetProcessDpiAwareness", "HWND", 0, "int*", 0) ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
If $aRet <> 2 Then ;;0:不支援DPI感知,1:系統DPI感知,2:監視器DPI感知
$aRet = DllCall("Shcore.dll", "BOOL", "SetProcessDpiAwareness", "int", 2) ;設定:監視器DPI感知
If @error Then Return SetError(@error, 0, False)
Return
EndIf
EndIf
EndFunc ;==>_SetProcessDPIAware
Func _GetDpi()
Local $iDPI
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$iDPI = RegRead("HKCU\Control Panel\Desktop\WindowMetrics", "AppliedDPI")
Else
Local $hWnd = _WinAPI_MonitorFromWindow(_WinAPI_GetDesktopWindow())
Local $aRet = DllCall("Shcore.dll", "BOOL", "GetDpiForMonitor", "HANDLE", $hWnd, "int", 0, "int*", 0, "int*", 0)
If @error Then Return SetError(@error, 0, False)
$iDPI = $aRet
EndIf
If $iDPI < 96 Or $iDPI > 480 Then $iDPI = 96
Return $iDPI / 96
EndFunc ;==>_GetDpi
Func _IsProcessDPIAware()
Local $aRet, $aDpi = 0
If @OSBuild < 9600 Then ;;判斷系統版本 win8.1(9600)
$aRet = DllCall("User32.dll", "BOOL", "IsProcessDPIAware") ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
$aDpi = $aRet
Else
$aRet = DllCall("Shcore.dll", "BOOL", "GetProcessDpiAwareness", "HWND", 0, "int*", 0) ;檢查處理程序是否支援DPI感知
If @error Then Return SetError(@error, 0, False)
$aDpi = $aRet
EndIf
Return $aDpi
EndFunc ;==>_IsProcessDPIAware
#EndRegion DPI函式
anythinging 发表于 2023-9-22 18:11
前面提到了,不好使
这样试试
#include <WinAPI.au3>
Global $GForm1
Local $hDC = _WinAPI_GetDC($GForm1)
Local $iWidtha = _WinAPI_GetDeviceCaps($hDC, 118)
Local $iHeighta = _WinAPI_GetDeviceCaps($hDC, 117)
$GForm1 = GUICreate('', 380, 220)
GUISetState()
GUICtrlCreateLabel('', 55, 0, 1, 300)
GUICtrlSetBkColor(-1, 0x003366)
GUICtrlCreateButton("按钮", 10, 30, 30, 20)
GUICtrlCreateCheckbox("选择", 10, 100, 40, 20)
While 1
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd anythinging 发表于 2023-9-22 17:19
如果能禁用当前程序缩放就省事了,不知怎样实现
Local $W1 = 1440
Local $H1 = 900
$GForm1 = GUICreate('', $W1 / 3.79, $H1 / 4.1);380, 220)
GUISetState()
GUICtrlCreateLabel('', 55, 0, 1, 300)
GUICtrlSetBkColor(-1, 0x003366)
GUICtrlCreateButton("按钮", 10, 30, 30, 20)
GUICtrlCreateCheckbox("选择", 10, 100, 40, 20)
While 1
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd w60711 发表于 2023-9-22 20:28
因為我有設置字體大小啊
按你说的,确实有效果。
不知有没有更简单点的,直接禁用缩放 chzj589 发表于 2023-9-22 21:02
Local $W1 = 1440
Local $H1 = 900
$GForm1 = GUICreate('', $W1 / 3.79, $H1 / 4.1);380, 220)
感谢目前按11楼的方法,能解决缩放带来的字体变大,导致组件显示不全的问题。
禁止缩放可能是我想的简单了,想在100%的屏幕无缩放的环境下弄好的界面,在各种放大后仍然显示原来大小。
页:
[1]
2