找回密码
 加入
搜索
查看: 4720|回复: 9

[GUI管理] GDI绘图,怎么重绘?[已解决]

  [复制链接]
发表于 2011-5-1 22:08:18 | 显示全部楼层 |阅读模式
本帖最后由 cxm23 于 2011-5-1 22:27 编辑
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
        Local $hGUI, $hWnd, $hGraphic

        ; Create GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        $hWnd = WinGetHandle("GDI+")
        GUISetState()

        ; Draw an ellipse
        _GDIPlus_Startup ()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
        _GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Clean up resources
        _GDIPlus_GraphicsDispose ($hGraphic)
        _GDIPlus_Shutdown ()

EndFunc   ;==>_Main
这是UDF中的例子,窗口最小化后,或者被遮挡后,所绘的图就不见了,请问怎么才能让它自动重绘?
发表于 2011-5-1 22:11:08 | 显示全部楼层
截取WM_PAINT消息,所有的绘图操作都应该在这个WM_PAINT消息函数中完成。
 楼主| 发表于 2011-5-1 22:23:49 | 显示全部楼层
谢谢超版,可以了
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>


Opt('MustDeclareVars', 1)

Global $hGUI, $hWnd, $hGraphic

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

_Main()

Func _Main()
        ; Create GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        $hWnd = WinGetHandle("GDI+")
        GUISetState()

        ; Draw an ellipse
        _GDIPlus_Startup ()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
        _GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Clean up resources
        _GDIPlus_GraphicsDispose ($hGraphic)
        _GDIPlus_Shutdown ()

EndFunc   ;==>_Main

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    
        _GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)
        
    Return $GUI_RUNDEFMSG
EndFunc
发表于 2011-5-1 22:24:56 | 显示全部楼层

#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)

Global $hGraphic

_Main()

Func _Main()
        Local $hGUI, $hWnd
        ; 创建界面
        $hGUI = GUICreate("GDI+", 400, 300)
        $hWnd = WinGetHandle("GDI+")
        ; 绘制椭圆
        _GDIPlus_Startup()
        GUIRegisterMsg(0x0f, "WM_PAINT")
        GUISetState()

        ; 循环至用户退出
        Do
        Until GUIGetMsg() = -3

        ; 清除资源
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
        _GDIPlus_GraphicsDrawEllipse($hGraphic, 130, 100, 140, 70)
        Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT
 楼主| 发表于 2011-5-1 22:28:08 | 显示全部楼层
谢谢,已解决
我的代码怎么没高亮
发表于 2011-5-1 22:43:20 | 显示全部楼层
WM_PAINT调用实在太频繁了 如果你的CPU比较弱小,会发现闪屏灰常厉害,建议把重绘代码直接放在主体循环里面
发表于 2011-5-1 22:50:05 | 显示全部楼层
返回GUI_RUNDEFMSG,AutoIt处理器会调用默认的窗口过程 进行绘图,这很可能会覆盖掉之前已经画好的。
正确的做法是在绘图代码之前调用User32.dll中的BeginPaint开始绘制,在绘图代码之后调用User32.EndPaint结束绘制,最后返回0。
 楼主| 发表于 2011-5-1 22:57:02 | 显示全部楼层
回复 6# 蜘蛛抱蛋
那怎么判断什么时候执行重绘?
 楼主| 发表于 2011-5-1 22:59:04 | 显示全部楼层
回复 7# pusofalse



自己DLLCall?
不懂. . .
发表于 2011-5-6 08:48:17 | 显示全部楼层
收藏了~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-2 22:10 , Processed in 0.075624 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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