Acce Posted October 3, 2020 Posted October 3, 2020 Hi im having such a hard time on a seemingly easy task I want to display an png image on a transparent GUI . Seams easy enough but for some reason I get a border around the png. Here is what I have tried: $mGUI = GUICreate("",800, 590,100,120, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW,$hGUI) GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) GUISetState(@SW_SHOW) $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($mGUI) ;create a graphics object from a window handle $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 590, $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) _GDIPlus_GraphicsClear($g_hGfxCtxt) _GDIPlus_GraphicsClear($g_hBitmap) _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_resized, 20, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI Have tried clearing the buffer but this gives a black background , what can be done ?
caramen Posted October 3, 2020 Posted October 3, 2020 Hello, You could make a child Gui without borders/close & maximize button with exact same size of your pic. And import picture into it. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Reveal hidden contents Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Nine Posted October 3, 2020 Posted October 3, 2020 @Acce Hint : You would get much more help if you could post runable script. Giving just a small portion of a script is way too much work for us to replicate your issue. “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Acce Posted October 3, 2020 Author Posted October 3, 2020 Here is a snippet should work: expandcollapse popup#include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <Misc.au3> #include <File.au3> #include <CityBuildingIsoData.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> Global $mGUI Global $hImageBg Sliding_Menu() Func Sliding_Menu() ;Menu GUI $mGUI = GUICreate("",800, 590,100,120, $WS_POPUP) GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) GUISetState(@SW_SHOW) ;Menu GUI <===== ;Menu GDI ;Load Image $hImage_1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "Menu_slider.png") $hImage_resized = _GDIPlus_ImageResize($hImage_1, 650, 500) ;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(800, 590, $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 + 800, $y + 700) $hImageBg = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) For $i = -400 to -20 step 10 ;_GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImageBg, 0, 0) ; Draw to buffer (bg) _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_resized, $i, 0) ; Draw to buffer (Hud) _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI Next sleep(1000) ;slideout() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc Func slideout() ;Load Image $hImage_1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\assets\HUD\" & "Menu_slider.png") $hImage_resized = _GDIPlus_ImageResize($hImage_1, 650, 500) ;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(800, 590, $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) _GDIPlus_GraphicsClear($g_hGfxCtxt) For $i = -20 to -500 step -10 _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImageBg, 0, 0) ; Draw to buffer (background global va) _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_resized, $i, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI Next ;slowdown For $i = -500 to -580 step -1 _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImageBg, 0, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_resized, $i, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI Next GUIDelete($mGUI) $mGUI = GUICreate("",800, 590,100,120, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW) GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) GUISetState(@SW_SHOW) $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($mGUI) ;create a graphics object from a window handle $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 590, $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) _GDIPlus_GraphicsClear($g_hGfxCtxt,0xabcdef) _GDIPlus_GraphicsClear($g_hBitmap,0xabcdef) _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $hImage_resized, 20, 0) ; Draw to buffer _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0) ; draw to GUI EndFunc
Acce Posted October 3, 2020 Author Posted October 3, 2020 @caramen Thanks for your suggestion , what you have suggested is actually what I have done , However loading the image on this transparent GUI proved to be difficult as I need to clear the old image when loading a new in the for loop. I solved this by using screent capture. But I was hoping to end up with a GUI in the end with just the start image
KaFu Posted October 3, 2020 Posted October 3, 2020 Here some code ripped from AMT's drag&drop sink GUI. expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> $h_GUI_AMT_DragDrop = GUICreate('AMT Drag & Drop Interface', 64, 64, 100, 100, $WS_POPUP, BitOR($WS_EX_ACCEPTFILES, $WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUICtrlCreateLabel("", 0, 0, 64, 64, Default, $GUI_WS_EX_PARENTDRAG) GUICtrlSetTip(-1, "Drag & Drop movie files or whole" & @CRLF & "folders here to process with AMT", "AMT Drag & Drop Interface", 1) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetCursor(-1, 9) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\pause.png") $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _SetBitmap($h_GUI_AMT_DragDrop, $hBitmap, 255) _GDIPlus_ImageDispose($hImage) GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() Local $idMsg = 0 While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE EndSelect WEnd _WinAPI_DeleteObject($hBitmap) Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $h_GUI_AMT_DragDrop Return $HTCAPTION EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NCHITTEST Func _SetBitmap($hWnd, $hBitmap, $iOpacity) Local $hDC, $hMemDC, $tBlend, $tSIZE, $tSource $hDC = _WinAPI_GetDC($hWnd) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) _WinAPI_SelectObject($hMemDC, $hBitmap) $tSIZE = _WinAPI_GetBitmapDimension($hBitmap) $tSource = DllStructCreate($tagPOINT) $tBlend = DllStructCreate($tagBLENDFUNCTION) DllStructSetData($tBlend, 'Alpha', $iOpacity) DllStructSetData($tBlend, 'Format', 1) _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, DllStructGetPtr($tSIZE), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>_SetBitmap OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Acce Posted October 3, 2020 Author Posted October 3, 2020 (edited) Hi thanks for that snippet , might be able to use some of that , the png gets displayed correctly , Not sure why my version have a border around the edges .. Can I ask excactly what part of the code that hides the gui and only shows the image ? Edited October 3, 2020 by Acce
Acce Posted October 4, 2020 Author Posted October 4, 2020 Have tried a few different things now , and seams like its the back color that dosent gets cleared completely, resulting in a 1px border around the image GUISetBkColor(0xabcdef) _WinAPI_SetLayeredWindowAttributes($mGUI,0xabcdef) Cause its the color 0xabcdef that can be seen around the image as a small border .
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