Jump to content

Overlapping multiple PNG files using Skin UDF. Is it possible?


cloudofxyz
 Share

Recommended Posts

Hi everybody,

I am still newbie in this GDI+ things. However, I will keep learning to improve myself.

I just realized that there is an UDF (Skin UDF) from @Yashied which can handle PNG files quite well, thus I decided to play around with it.

 

Until I reached a point where I can't find any clue in how to solve the problem.

I inserted my sample script ("Apples.au3") inside the attachment including the necessary PNG files.

Basically, I am trying to achieve the result similar to below code:

#cs
Modified sample code from :
https://www.autoitscript.com/forum/topic/196831-need-help-adding-text-atop-a-gdi-object/

#ce

;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

;~ #include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>


HotKeySet("{Esc}","Close")



Global $hGUIMain = GUICreate("", 10, 15, -1, -1, $WS_POPUP,$WS_EX_LAYERED)

GUISetState(@SW_SHOW, $hGUIMain)


_GDIPlus_Startup()



Global $hBitmap1, $hBitmap2, $hBitmap3
Global $hBitmap1Disabled, $hBitmap2Disabled, $hBitmap3Disabled
Global $hGUI, $hGUI2, $hGUI3
Global $hGUI1Disabled, $hGUI2Disabled, $hGUI3Disabled


$hGUI1 = GUICreate("", 66, 66, 500, 200, $WS_POPUP, $WS_EX_LAYERED, $hGUIMain)
GUISetState(@SW_SHOW,$hGUI1)
$hGUI1Disabled = GUICreate("", 66, 66, 500, 200, $WS_POPUP, $WS_EX_LAYERED, $hGUIMain)


$hGUI2 = GUICreate("", 66, 66, 540, 200, $WS_POPUP, $WS_EX_LAYERED,$hGUIMain)
GUISetState(@SW_SHOW, $hGUI2)
$hGUI2Disabled = GUICreate("", 66, 66, 540, 200, $WS_POPUP, $WS_EX_LAYERED,$hGUIMain)

$hGUI3 = GUICreate("", 66, 66, 520, 210, $WS_POPUP, $WS_EX_LAYERED, $hGUIMain)
GUISetState(@SW_SHOW, $hGUI3)
$hGUI3Disabled = GUICreate("", 66, 66, 520, 210, $WS_POPUP, $WS_EX_LAYERED, $hGUIMain)



  $Bitmap1 = _GDIPlus_BitmapCreateFromFile('apple_red.png')
  $hBitmap1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap1)
  $Bitmap1Disabled = _GDIPlus_BitmapCreateFromFile('apple_disabled.png')
  $hBitmap1Disabled = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap1Disabled)

  $Bitmap2 =_GDIPlus_BitmapCreateFromFile('apple_green.png')
  $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap2)
  $Bitmap2Disabled = _GDIPlus_BitmapCreateFromFile('apple_disabled.png')
  $hBitmap2Disabled = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap2Disabled)

  $Bitmap3 =_GDIPlus_BitmapCreateFromFile('apple_yellow.png')
  $hBitmap3 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap3)
  $Bitmap3Disabled = _GDIPlus_BitmapCreateFromFile('apple_disabled.png')
  $hBitmap3Disabled = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap3Disabled)

  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap1, $hGUI1)
  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap1Disabled, $hGUI1Disabled)
  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap2, $hGUI2)
  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap2Disabled, $hGUI2Disabled)
  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap3, $hGUI3)
  _WinAPI_BitmapDisplayTransparentInGUI($hBitmap3Disabled, $hGUI3Disabled)



    While 1
        Sleep(10)
        $msg = GUIGetMsg($GUI_EVENT_ARRAY)


        Switch $msg[1]
            Case $hGUI1
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI1Disabled)
                        GUISetState(@SW_HIDE,$hGUI1)
                        call("ZOrder")
                        ConsoleWrite("You've clicked Red Apple" & @CR)
                EndSwitch

            Case $hGUI2
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI2Disabled)
                        GUISetState(@SW_HIDE,$hGUI2)
                        Call("ZOrder")
                        ConsoleWrite("You've clicked Green Apple" & @CR)
                EndSwitch

            Case $hGUI3
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI3Disabled)
                        GUISetState(@SW_HIDE,$hGUI3)
                        ConsoleWrite("You've clicked Yellow Apple" & @CR)
                EndSwitch

            Case $hGUI1Disabled
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI1)
                        GUISetState(@SW_HIDE,$hGUI1Disabled)
                        call("ZOrder")
                        ConsoleWrite("Red Apple has been resumed" & @CR)
                EndSwitch
            Case $hGUI2Disabled
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI2)
                        GUISetState(@SW_HIDE,$hGUI2Disabled)
                        Call("ZOrder")
                        ConsoleWrite("Green Apple has been resumed" & @CR)
                EndSwitch
            Case $hGUI3Disabled
                Switch $msg[0]
                    Case $GUI_EVENT_PRIMARYDOWN
                        Sleep(100)
                        GUISetState(@SW_SHOW,$hGUI3)
                        GUISetState(@SW_HIDE,$hGUI3Disabled)
                        ConsoleWrite("Yellow Apple has been resumed" & @CR)
                EndSwitch


        EndSwitch

    WEnd

Func ZOrder()
    Local $hWnd = WinGetHandle("[ACTIVE]")
    WinSetOnTop($hWnd, "", $WINDOWS_NOONTOP)
    WinSetOnTop($hGUI3Disabled, "", $WINDOWS_ONTOP)
    WinSetOnTop($hGUI3, "", $WINDOWS_ONTOP)
    WinSetOnTop($hGUI3, "", $WINDOWS_NOONTOP)   ;prevent always on top when other application has focus
EndFunc


Func Close()
    _GDIPlus_BitmapDispose($Bitmap1)
    _GDIPlus_BitmapDispose($Bitmap2)
    _GDIPlus_BitmapDispose($Bitmap3)
    _GDIPlus_BitmapDispose($Bitmap1Disabled)
    _GDIPlus_BitmapDispose($Bitmap2Disabled)
    _GDIPlus_BitmapDispose($Bitmap3Disabled)

    _WinAPI_DeleteObject($hBitmap1)
    _WinAPI_DeleteObject($hBitmap2)
    _WinAPI_DeleteObject($hBitmap3)

    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>Close

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

 

Please disregard the missing GUI and its background as I just need the functionality to overlap some PNG files while maintaining the clickable area within the non-transparent part.

In my sample file of Skin UDF, this causing the overlapped PNG files did not shown properly as what I expected (it become non-transparent PNG files when they are overlapped).

Is this limitation of Skin UDF can be overcome by adding some GDI+ command prior/after the "_Skin_AddButton"  or  "_Skin_AddButtonEx" ?

 

I prefer using Skin UDF as it is much more convenient with those Hover function and shorter code.

I have an idea of future usage of the Skin UDF in which involving more than a hundred overlapping PNG files at once where each of PNG can be clicked individually. If I'm going to use above code, then I'll need to create more than a hundred GUIs and longer codes compared to using Skin UDF.

 

I did try to dig into the forum but unable to find solution for it. (Or maybe I just did not dig deep enough)

Nevertheless, I will be happy enough already with above code if someone confirmed that nothing can be done into Skin UDF.

 

Thanks.

Multiple PNG Test.zip

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...