continyu 0 Posted December 5, 2010 hey there, i'm learning GDI+ functions. but i have one problem. If you just run the script and than press arrow keys, new merlin images will drawen but old ones doesn't erasing, expandcollapse popup#include <GuiConstantsEx.au3> #include <Misc.au3> ; #include <Memory.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) _Main() While 1 Sleep(100) WEnd Func _Main() Global $hGUI, $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone,$hBitmap1, $hGraphic1,$hBitmap2, $hGraphic2, $merl HotKeySet("{RIGHT}", "MoveRight" ) HotKeySet("{LEFT}", "MoveLeft" ) HotKeySet("{UP}", "MoveUP" ) HotKeySet("{DOWN}", "MoveDown" ) HotKeySet("{ESC}", "End" ) ; Create GUI $hGUI = GUICreate("GDI+", 700, 400) GUISetOnEvent($GUI_EVENT_CLOSE, "End") GUISetState() ; Initialize GDI+ library _GDIPlus_Startup () ; Save bitmap to file ; Clean up resources _GDIPlus_BitmapDispose ($hClone) _GDIPlus_BitmapDispose($hImage) _WinAPI_DeleteObject ($hBMP) ; Draw bitmap to GUI $hBitmap = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\proxy.jpg") $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) $hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif") $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND ($hGUI) Global $merl = _GDIPlus_GraphicsDrawImageRect ($hGraphic1, $hBitmap1, 3,3, 68,71) Global $posx = 3 Global $posy = 3 EndFunc ;==>_Main Func MoveRight () _WinAPI_DeleteObject($merl) ;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif") ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) $posx = $posx + 68 If $posx > 632 Then $posx = $posx - 68 _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy, 68,71) Sleep(1000) EndFunc Func MoveDown () _WinAPI_DeleteObject($merl) ;This line doesn ;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif") ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy+71, 68,71) $posy = $posy +71 Sleep(1000) EndFunc Func MoveLeft () _WinAPI_DeleteObject($merl) ;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif") ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx-68 ,$posy, 68,71) $posx = $posx - 68 Sleep(1000) EndFunc Func MoveUp () _WinAPI_DeleteObject($merl) ;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif") ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy-71, 68,71) $posy = $posy - 71 Sleep(1000) EndFunc Func End() ; Clean up resources _GDIPlus_GraphicsDispose ($hGraphic1) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_BitmapDispose ($hBitmap) _GDIPlus_BitmapDispose ($hBitmap1) _GDIPlus_ShutDown () Exit EndFunc Share this post Link to post Share on other sites
continyu 0 Posted December 5, 2010 Still no replies? What is the problem? is this question too simple or idiotic or too hard? Please guys leave comments for leading me Share this post Link to post Share on other sites
Zedna 279 Posted December 5, 2010 Don't bump your posts within 24 hours. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Share this post Link to post Share on other sites
Fubarable 1 Posted December 5, 2010 Why not simply re-draw the background whenever you re-draw Merlin? _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;; added _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy-71, 68,71) Share this post Link to post Share on other sites
continyu 0 Posted December 5, 2010 Why not simply re-draw the background whenever you re-draw Merlin? _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;; added _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy-71, 68,71) Well for two reasons, 1-i feel like they all stacking over and over, i don't know if thats true but feels like if i dont delete the old images the new ones just cover the old ones not deleting it. 2- i think it will take more time than just erasing old merlin. But as i sad i don't know for sure if i'm right... Share this post Link to post Share on other sites
AdmiralAlkex 125 Posted December 5, 2010 (edited) GDI+ draws to the screen, and you can't delete stuff from the screen, you redraw them. Stacking doesn't apply to graphics but to controls and windows.2- i think it will take more time than just erasing old merlin.Only redraw the background where Merlin was standing, not everything. Edited December 5, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Share this post Link to post Share on other sites