PINTO1927

png with background transparent into gui without border

5 posts in this topic

 

Hi guys, I would like to make a gui borderless viewing a png image with transparent background.

 

pretty much has to be visible only the png image with no background..you have any simple example?

Thank's

GUICtrlCreatePic

 

still it provides the image with the background...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is a small example (from @UEZ:

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile("C:\Program Files\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetState()
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

 

Edited by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

Thank's 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here a other example I also think it is from UEZ

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

 _GDIPlus_Startup()

$hSplashlogo = _GDIPlus_ImageLoadFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")


$logoheight = (@DesktopHeight/2) - (_GDIPlus_ImageGetHeight($hSplashlogo)/2) - 50
$logowidth = (@DesktopWidth /2) - (_GDIPlus_ImageGetWidth($hSplashlogo)/2)
$SplashGUIlogo = GUICreate("", _GDIPlus_ImageGetWidth($hSplashlogo), _GDIPlus_ImageGetHeight($hSplashlogo), $logowidth, $logoheight, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW))
_SetBitmap($SplashGUIlogo, $hSplashlogo, 255, _GDIPlus_ImageGetWidth($hSplashlogo), _GDIPlus_ImageGetHeight($hSplashlogo))
GUISetState(@SW_SHOWNA, $SplashGUIlogo)


While 1
    Sleep(20)
WEnd

 _GDIPlus_Shutdown()


Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width = 200, $n_height = 200)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

 

Edited by nend

Share this post


Link to post
Share on other sites

Good

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • ronaldo97
      By ronaldo97
      Hello How can I make the GUI is compatible with all screen sizes ??  
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 445, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZE)) GUISetBkColor(0x1E1E1E) $Label1 = GUICtrlCreateLabel("Welcome Back !!", 424, 64, 161, 29) GUICtrlSetFont(-1, 16, 400, 0, "Tahoma") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd How do I make Gui interface compatible with all screen sizes ?? 800*600
      1024*768
      1280*1024
    • Genotypek
      By Genotypek
      Hello.
      I've got a problem. I want to center my input vertically, but I don't have any single idea how to do it.
      There's my example code:
      #include <GUIConstantsEx.au3> $GUI = GUICreate("Gui", 237, 93, 192, 124) $Input1 = GUICtrlCreateInput("Center vertically isn't correct", 16, 16, 201, 62) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd What could I do?
      Greetings, "genotypek".
    • argv1
      By argv1
      Hi,
      working on my first autoit GUI an got some questions.
      Is it possible to get an action on the first menu level
      For example:
      $StartMenu = GUICtrlCreateMenu("Datei") ... while 1 Switch GUIGetMsg() Case $StartMenu MsgBox(0, "Test", "yes this works") (currently this does not work for me)
      Currently I have to create GUICtrlCreateMenuItem 's this will leed to a result
       
      And a 2nd question. I saw many time this:
      $StartMenu = GUICtrlCreateMenu("&Datei") For what does I need the ampersand? If I leave out the & nothing seems to change
       
      Thank you very much in advance
       
    • Blueman
      By Blueman
      Hey Guys,
      I am Struggling with a issue that i cannot seem to fix.
      I hope that you guys can help me with this.
      I have a GUI with some text attributes, for all i use the following code;
      $Label_ts_Header = GUICtrlCreateLabel("Manual Adress", 60, 10, 500, 50) GUICtrlSetBkColor($Label_ts_Header, $COLOR_WHITE) GUICtrlSetFont ($Label_ts_Header, 26, 800, 0, "Calibri") This is all working like it should, but when i activate the GUI on another pc the text size is bigger and the GUI size is somewhat smaller.
      The problem is that it isn't on all computers, i can't seem to find the problem,..
      If i make it fit on one pc it is to small on another or to big,..
      What am i doing wrong?
       
      Is there some kind of attribute that i need to add to the top of my script to normalize text sizes in the script?
       
      Thanks!
       
      EDIT: Found the problem guys, some computers has changed the text size to 125% // Can i force 100% for my GUI somehow ?
       
      EDIT2: Fixed it guys! // I used the Function Below to get the DPI Setting and used that to determine the text size (example below)
       
      Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96) _GDIPlus_Startup() Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0) If @error Then Return SetError(1, @extended, 0) Local $aResult #forcedef $__g_hGDIPDll, $ghGDIPDll $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0) If @error Then Return SetError(2, @extended, 0) Local $iDPI = $aResult[2] Local $aresults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef] _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_Shutdown() Return $aresults EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio  
      $Label_S2 = GUICtrlCreateLabel("Data from The Base", 10, 300, 400, 20) GUICtrlSetBkColor($Label_S2, $COLOR_WHITE) GUICtrlSetFont ($Label_S2, 13 * _GDIPlus_GraphicsGetDPIRatio()[0])  
       
    • Em4gdn1m
      By Em4gdn1m
      Hey everyone, I'm curious if there is a way to incorporate a checkbox with a combo GUICtrl?
      so for instance I have a GUI that has a bunch of checkboxes that allow me to open certain programs as needed.  (this is just some parsing of my code, sorry, noob here and not sure what the preferred method of displaying code is, please enlighten me)

          $L0742 = GUICtrlCreateCheckbox("L07 4.2", 110, 320, 100)
          $L07502 = GUICtrlCreateCheckbox("L07 5.0.2", 110, 350, 100)
          $GenComm = GUICtrlCreateCheckbox("GenComm", 110, 380, 100)
          $Templates = GUICtrlCreateCheckbox("Templates", 110, 410, 100)
          $MCT = GUICtrlCreateCheckbox("MCT", 110, 440, 100)
          $Desktop_Shortcuts = GUICtrlCreateCheckbox("Desktop Shortcuts by Tester", 110, 470, 200)
       
      ...
      Case $msg = $RunBtn
                  RunPrograms()
       
      ...
      Func RunPrograms()

          if GUICtrlRead($L0742) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel4.2\viva\viva.exe", "")
          if GUICtrlRead($L07502) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel5\viva\viva.exe", "")
          if GUICtrlRead($GenComm) = $GUI_CHECKED then Run("\\Fpanelfs1\FPShared\Desktop_Shortcuts_by_Tester\Matt\CPI Generator\CPI Generator Windows 7 64 Bit\GenComm\GenComm.NET.exe", "")
          if GUICtrlRead($Templates) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\FPProjects\Documentation Controlled\Test_Templates")
          if GUICtrlRead($MCT) = $GUI_CHECKED then Run("\\Fpanelfs1\FPProjects\Documentation Controlled\Manufacturing Software\MCT\MCT.exe","")
          if GUICtrlRead($Desktop_Shortcuts) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\fpshared\Desktop_Shortcuts_by_Tester")
      EndFunc
       
      so i click some checkboxes, and hit a run button and the programs which are checked run, great.
      BUT i want to add a bunch of options under one checkbox. A combo that will list a bunch of versions of a program that can be opened. something like this... but I want that program to be part of a checkbox
      $ViVAComboBox = GUICtrlCreateCombo("L01 Rel 13", 110, 320, 100)
      GUICtrlSetData($ViVAComboBox, "L04|L05|L07 Rel 4.2|L07 Rel 5.0.2|L09", "L07 Rel 4.2")
       
      is this possible? is there another GUICtrl that does this better that i am not aware of?