找回密码
 加入
搜索
查看: 729|回复: 2

[网络通信] 【已解决】笔记本DPI缩放问题,谢谢发哥……

[复制链接]
发表于 2021-11-26 17:03:58 | 显示全部楼层 |阅读模式
本帖最后由 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[2] = ['100', '136']
$iLeft = $aPos_Lefttop[0] * $iDPI 
$iTop = $aPos_Lefttop[1] * $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



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2021-11-26 17:04:55 | 显示全部楼层
 楼主| 发表于 2021-11-26 17:09:33 | 显示全部楼层
代码加入进去后:效果:
#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[0]
EndFunc   ;==>SetProcessDPIAware

$iDPI = 2
Local $aPos_Lefttop[2] = ['100', '126']
$iLeft = $aPos_Lefttop[0] * $iDPI 
$iTop = $aPos_Lefttop[1] * $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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-3-29 19:25 , Processed in 0.071658 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表