找回密码
 加入
搜索
查看: 423|回复: 5

[网络通信] 【已解决】请教GDI绘制更新文字时如何避免闪烁?

[复制链接]
发表于 2023-5-5 08:21:30 | 显示全部楼层 |阅读模式
本帖最后由 zghwelcome 于 2023-5-5 09:12 编辑

请教各位大佬, GDI绘制、更新文字时,如何避免闪烁?





#include <StaticConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#AutoIt3Wrapper_UseX64 = n

HotKeySet('{esc}','_Exit');退出
$Form1 = GUICreate("Form1", @DesktopWidth, @DesktopHeight)
GUICtrlCreatePic(@ScriptDir & "\1.jpg", 0, 0, @DesktopWidth, @DesktopHeight, BitOR($WS_CLIPSIBLINGS, $SS_NOTIFY))
GUICtrlSetState(-1, 128)
GUISetBkColor(0)
GUISetState(@SW_SHOW)
Global $iTime = 200

_GDIPlus_Startup()
Global $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hGraphic
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
$hFont = _GDIPlus_FontCreate($hFamily, 40, 1, 2)
$tLayout = _GDIPlus_RectFCreate(@DesktopWidth / 2, @DesktopHeight / 2, 100, 70)

AdlibRegister('_time', 1000)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        _Exit()

        EndSwitch
WEnd

Func _time()
        If $iTime < 0 Then
                AdlibUnRegister('_time')
        Else
                ;// 更新数字
                $iTime -= 1
                ConsoleWrite('$iTime: ' & $iTime & @CRLF)
                GUISetState(@SW_DISABLE, $Form1)
                _WinAPI_InvalidateRect($Form1)
                GUISetState(@SW_ENABLE, $Form1)
                _GDIPlus_GraphicsDrawStringEx($hGraphic, $iTime, $hFont, $tLayout, $hFormat, $hBrush)
        EndIf
EndFunc   ;==>_time
Func _Exit()
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
        Exit
EndFunc   ;==>_Exit




发表于 2023-5-5 09:02:04 | 显示全部楼层
如此,这样?
#NoTrayIcon
#include <StaticConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#AutoIt3Wrapper_UseX64 = n

HotKeySet('{esc}', '_Exit');退出

$Form1 = GUICreate("Form1", @DesktopWidth, @DesktopHeight)
GUICtrlCreatePic('', 0, 0, @DesktopWidth, @DesktopHeight, BitOR($WS_CLIPSIBLINGS, $SS_NOTIFY))
GUICtrlSetState(-1, 128)
GUISetBkColor(0)
GUISetState(@SW_SHOW)
Global $iTime = 200

_GDIPlus_Startup()
Global $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hGraphic
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)

Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphic)
Global $hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global $hImage = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\1.jpg")
_GDIPlus_GraphicsDrawImageRect($hBackBuffer, $hImage, 0, 0, @DesktopWidth, @DesktopHeight)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)

$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
$hFont = _GDIPlus_FontCreate($hFamily, 40, 1, 2)
$tLayout = _GDIPlus_RectFCreate(@DesktopWidth / 2, @DesktopHeight / 2, 100, 70)

AdlibRegister('_time', 1000)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        _Exit()

        EndSwitch
WEnd

Func _time()
        If $iTime < 0 Then
                AdlibUnRegister('_time')
        Else
                ;// 更新数字
                $iTime -= 1
                ConsoleWrite('$iTime: ' & $iTime & @CRLF)
                GUISetState(@SW_DISABLE, $Form1)
                _GDIPlus_GraphicsClear($hBackBuffer ,  0xFF000000 )
                _GDIPlus_GraphicsDrawImageRect($hBackBuffer, $hImage, 0, 0, @DesktopWidth, @DesktopHeight)
                _GDIPlus_GraphicsDrawStringEx($hBackBuffer, $iTime, $hFont, $tLayout, $hFormat, $hBrush)
                _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
        EndIf
EndFunc   ;==>_time
Func _Exit()
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
        Exit
EndFunc   ;==>_Exit


评分

参与人数 1金钱 +60 收起 理由
zghwelcome + 60 很给力! 感谢大佬

查看全部评分

发表于 2023-5-6 21:12:50 | 显示全部楼层
win 7- 64bit

autoit 3.3.14.2
經測試會有如圖狀況,數字影像重疊,在找原因中

本帖子中包含更多资源

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

×
发表于 2023-5-7 08:44:32 | 显示全部楼层
yohoboy 发表于 2023-5-6 21:12
win 7- 64bit

autoit 3.3.14.2

因为你没有1.jpg
发表于 2023-5-7 10:52:32 | 显示全部楼层
yohoboy 发表于 2023-5-6 21:12
win 7- 64bit

autoit 3.3.14.2

代码更新了,再试试吧
发表于 2023-5-7 12:23:35 | 显示全部楼层
抱歉挽回覆,目前測試正常,不管是否有背景圖作背景,還沒透徹代碼,感謝回覆。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 16:39 , Processed in 0.077143 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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