Acce Posted October 1, 2020 Posted October 1, 2020 (edited) Hi im trying to make an image move within my gui , this will be part of a slide in menu bar. Here is my current code. My thought is to have a slide in menu using a GUI on top of my main GUI, good idea or bad one ? ;Menu GUI $mGUI = GUICreate("",500, 310,100,200, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW,$hGUI) GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) GUISetState(@SW_SHOW) ;Menu GUI <===== ;Menu GDI ;Canvas $sGraphic = _GDIPlus_GraphicsCreateFromHWND($mGUI) $slide_Bitmap =_GDIPlus_BitmapCreateFromGraphics(384, 216, $sGraphic) $slide_Buffer = _GDIPlus_ImageGetGraphicsContext($slide_Bitmap) _GDIPlus_GraphicsClear($slide_Buffer) ;Load Image $TmpImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "slide.png") $hBitmap1 = _GDIPlus_ImageResize($TmpImage, 384, 216) _GDIPlus_GraphicsClear($slide_Buffer) _GDIPlus_ImageDispose($TmpImage) ; draw images into back buffer for $i = -450 to -300 _GDIPlus_GraphicsDrawImage($slide_Buffer, $hBitmap1, 0, 0) _GDIPlus_GraphicsDrawImageRect($sGraphic, $hBitmap1,$i, 10, 490,210) sleep(20) Next ;Menu GDI <===== EndFunc I have gotten a few unexpected results , First is that the image dont get resized proper, And im a bit uncertain to how I should remove the old image when I load the new one in the loop ? Any help would be much appreciated Edited October 1, 2020 by Acce
Acce Posted October 1, 2020 Author Posted October 1, 2020 After reading the help file I have updated my attempt to this ;Load Image $hImage_1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "slide.png") $hImage_bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "bg.png") ;create buffered graphics frame set for smoother gfx object movements $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($mGUI) ;create a graphics object from a window handle $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics(500, 310, $g_hGfx) ;create a Bitmap object based on a graphics object $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) ;get the graphics context of the image / bitmap to draw on image / bitmap _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) for $i = -400 to -10 _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_1, $i, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_bg, $i, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI Next But Just realising now owerwriting the buffer with a blank file probably dosent erase the old image
Acce Posted October 1, 2020 Author Posted October 1, 2020 Solved Here is what I ended with: Func Sliding_Menu() ;Menu GUI $mGUI = GUICreate("",500, 310,100,200, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW,$hGUI) GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) GUISetState(@SW_SHOW) ;Menu GUI <===== ;Menu GDI ;Load Image $hImage_1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "slide.png") $hImage_bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "bg.png") ;create buffered graphics frame set for smoother gfx object movements $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($mGUI) ;create a graphics object from a window handle $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics(500, 400, $g_hGfx) ;create a Bitmap object based on a graphics object $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) ;get the graphics context of the image / bitmap to draw on image / bitmap _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) ;capture screen $mGUI_Pos = WinGetPos($mGUI) $x = $mGUI_Pos[0] $y = $mGUI_Pos[1] $hHBitmap = _ScreenCapture_Capture("",$x,$y,$x + 500, $y + 300) $hImageBg = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) For $i = -400 to -20 step 2 _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImageBg, 0, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_1, $i, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI sleep(5) Next
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now