【已解决】笔记本DPI缩放问题,谢谢发哥……
本帖最后由 floor6ggg 于 2021-11-26 17:18 编辑问题出现:_GDIPlus_GraphicsDrawRect 这个函数 在我的笔记本:只能画出屏幕前面1/2的矩形图像,超过的屏幕另外1/2范围的显示不出来…………,找不到问题所在…………
折腾了2天,自己实在搞不定,后面在发哥的帖子找到了答案,加入:SetProcessDPIAware() 函数顺利解决问题,发哥真神人也,想了想,发上来,给有需要的战友,希望大家少走点弯路………………
#include <GdiPlus.au3>
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :@DesktopWidth = ' & @DesktopWidth &@TAB &'@DesktopHeight= ' & @DesktopHeight& @CRLF) ;### Debug Console
$iDPI = 2
Local $aPos_Lefttop = ['100', '136']
$iLeft = $aPos_Lefttop * $iDPI
$iTop = $aPos_Lefttop * $iDPI
_GDIPlus_Startup() ;initialize GDI+
$hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) ok!
$hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
$hPen = _GDIPlus_PenCreate(0xFF00FF00, 4)
For $i = 1 To 40
_GDIPlus_GraphicsDrawRect($hGraphics, $iLeft, $iTop, $i * 30 * $iDPI, $i * 30 * $iDPI, $hPen)
_GDIPlus_GraphicsDrawString($hGraphics, $i, $iLeft + $i * 30 * $iDPI, $iTop , 'Arial', 15)
_GDIPlus_GraphicsDrawString($hGraphics, $i, $iLeft + $i * 30 * $iDPI, $iTop + $i * 30 * $iDPI, 'Arial', 15)
Next
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
发哥原贴地址:https://www.autoitx.com/thread-72066-1-1.html
代码加入进去后:效果:#include <GdiPlus.au3>
SetProcessDPIAware()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :@DesktopWidth = ' & @DesktopWidth &@TAB &'@DesktopHeight= ' & @DesktopHeight& @CRLF) ;### Debug Console
Func SetProcessDPIAware()
Local $Result = DllCall('User32.dll', 'BOOL', 'SetProcessDPIAware')
If @error Then Return SetError(@error, 0, False)
Return $Result
EndFunc ;==>SetProcessDPIAware
$iDPI = 2
Local $aPos_Lefttop = ['100', '126']
$iLeft = $aPos_Lefttop * $iDPI
$iTop = $aPos_Lefttop * $iDPI
_GDIPlus_Startup() ;initialize GDI+
$hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) ok!
$hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
$hPen = _GDIPlus_PenCreate(0xFF00FF00, 4)
For $i = 1 To 40
_GDIPlus_GraphicsDrawRect($hGraphics, $iLeft, $iTop, $i * 30 * $iDPI, $i * 30 * $iDPI, $hPen)
_GDIPlus_GraphicsDrawString($hGraphics, $i, $iLeft + $i * 30 * $iDPI, $iTop , 'Arial', 15)
_GDIPlus_GraphicsDrawString($hGraphics, $i, $iLeft + $i * 30 * $iDPI, $iTop + $i * 30 * $iDPI, 'Arial', 15)
Next
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
;~ Exit
页:
[1]