GDI绘图,怎么重绘?[已解决]
本帖最后由 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中的例子,窗口最小化后,或者被遮挡后,所绘的图就不见了,请问怎么才能让它自动重绘? 截取WM_PAINT消息,所有的绘图操作都应该在这个WM_PAINT消息函数中完成。 谢谢超版,可以了#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
#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
谢谢,已解决
{:face (382):}我的代码怎么没高亮 WM_PAINT调用实在太频繁了 如果你的CPU比较弱小,会发现闪屏灰常厉害,建议把重绘代码直接放在主体循环里面 返回GUI_RUNDEFMSG,AutoIt处理器会调用默认的窗口过程 进行绘图,这很可能会覆盖掉之前已经画好的。
正确的做法是在绘图代码之前调用User32.dll中的BeginPaint开始绘制,在绘图代码之后调用User32.EndPaint结束绘制,最后返回0。 回复 6# 蜘蛛抱蛋
那怎么判断什么时候执行重绘? 回复 7# pusofalse
{:face (245):}
自己DLLCall?
不懂. . . 收藏了~~~~~~
页:
[1]