找回密码
 加入
搜索
查看: 6074|回复: 12

[GUI管理] 请问如何清除GDI创建的文字和图形呀

  [复制链接]
发表于 2015-1-6 17:17:44 | 显示全部楼层 |阅读模式
_GDIPlus_GraphicsClear
使用这个函数不行,一用就全屏都成黑色了。

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

_Main()

Func _Main()
        Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
        Local $sString = "Hello world", $aInfo

        ; 创建 GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        GUISetState()

        ; 描绘字符串
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
        $tLayout = _GDIPlus_RectFCreate(140, 110, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)

        ; 循环直到用户退出
        ;Do
        ;Until GUIGetMsg() = $GUI_EVENT_CLOSE
        MsgBox(0,1,_GDIPlus_GraphicsClear($hGraphic))
        ; 清理资源
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
       
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

以上是示范代码,创建的文字没法清除呀!!!
 楼主| 发表于 2015-1-6 17:25:38 | 显示全部楼层

木有人知道吗
发表于 2015-1-6 21:30:09 | 显示全部楼层
区域刷新。。。。。
 楼主| 发表于 2015-1-6 21:46:06 | 显示全部楼层
回复 3# zhouhaijin


用哪个函数刷啊,求指点
发表于 2015-1-6 22:11:03 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>


_Main()

Func _Main()
        Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
        Local $sString = "Hello world", $aInfo

        ; 创建 GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        GUISetState()

        ; 描绘字符串
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
        $tLayout = _GDIPlus_RectFCreate(140, 110, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)

        ; 循环直到用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        $myWinPos = WinGetPos($hGUI)
        $tPoint = _WinAPI_CreateRect($myWinPos[0], $myWinPos[1], $myWinPos[0] + $myWinPos[2], $myWinPos[1] + $myWinPos[3])
        _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), $tPoint, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
        ; MsgBox(0,1,_GDIPlus_GraphicsClear($hGraphic))
        ; 清理资源
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main
 楼主| 发表于 2015-1-7 11:54:32 | 显示全部楼层
回复 5# zhouhaijin
那样清理不掉的,按一次esc后,hello word还在
 楼主| 发表于 2015-1-7 11:55:39 | 显示全部楼层
感觉太不科学了啊,GDI画出来的东西为啥不能清理
发表于 2015-1-7 12:54:17 | 显示全部楼层
虽然不懂 但期待有高手出来指点下
发表于 2015-1-11 16:00:52 | 显示全部楼层
回复 6# solo_k


    我测试可以清理掉
发表于 2015-1-12 19:24:34 | 显示全部楼层
看下  学习下
发表于 2015-1-12 20:26:32 | 显示全部楼层
#Include <GDIPlus.au3>
_GDIPlus_GraphicsReleaseDC
试试看,不行的话用这个再试试
#Include <GDIPlusEx.au3>
_GDIPlus_GraphicsFlush
发表于 2015-1-13 09:16:07 | 显示全部楼层
学习了,感谢分享!
发表于 2015-1-13 16:06:34 | 显示全部楼层
学习了,感谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-29 21:33 , Processed in 0.083513 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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