Sign in to follow this  
Followers 0
Rawox

[NOT SOLVED] Image not working on transparent GUI?

11 posts in this topic

#1 ·  Posted (edited)

I tried to create an image at a transparent GUI but it doesn't work :S I am sure the file is located in the folder :)

#include <GuiConstants.au3>
#include <WindowsConstants.au3>

$Title = "Test"
HotKeySet("{ESC}", "QuitApp")

GUICreate ( $Title, @DesktopWidth+20, @DesktopHeight+20, -10, -10, BitOr ( $DS_SETFOREGROUND, $WS_POPUPWINDOW, $WS_EX_TOPMOST ) )
GUISetBkColor ( 0x000000 )
WinSetTrans ( $Title, "", 180 )
GUISetState ( @SW_SHOW )

$Main_Gui = GUICreate("", @DesktopWidth+20, @DesktopHeight+20, -10, -10, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

$But1 = GUICtrlCreateButton(" Exit ", 100, 100, 80, 21)
$Logo = GUICtrlCreatePic ( @ScriptDir & "\img\logo.png", 50, 50, 300, 200 )

GUISetControlsVisible($Main_Gui)
GUISetState()

While 1
    If GUIGetMsg() = $But1 Then Exit
WEnd

Func GUISetControlsVisible($hWnd)
    Local $aClassList, $aM_Mask, $aCtrlPos, $aMask
    
    $aClassList = StringSplit(_WinGetClassListEx($hWnd), @LF)
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    
    For $i = 1 To UBound($aClassList) - 1
        $aCtrlPos = ControlGetPos($hWnd, '', $aClassList[$i])
        If Not IsArray($aCtrlPos) Then ContinueLoop
        
        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc

Func _WinGetClassListEx($sTitle)
    Local $sClassList = WinGetClassList($sTitle)
    Local $aClassList = StringSplit($sClassList, @LF)
    Local $sRetClassList = "", $sHold_List = "|"
    Local $aiInHold, $iInHold
    
    For $i = 1 To UBound($aClassList) - 1
        If $aClassList[$i] = "" Then ContinueLoop
        
        If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
            $aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])
            
            If $iInHold = 0 Then $iInHold += 1
            
            $aClassList[$i] &= "~" & $iInHold + 1
            $sHold_List &= $aClassList[$i] & "|"
            
            $sRetClassList &= $aClassList[$i] & @LF
        Else
            $aClassList[$i] &= "~1"
            $sHold_List &= $aClassList[$i] & "|"
            $sRetClassList &= $aClassList[$i] & @LF
        EndIf
    Next
    
    Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc

Func QuitApp()
    Exit
EndFunc
Edited by Rawox

Share this post


Link to post
Share on other sites



GUICtrlCreatePic() doesn't work with png images as far as I know but you can use Yashied's library to overcome this limitation:

#include <GuiConstants.au3>
#include <Icons.au3>
#include <WindowsConstants.au3>

$Title = "Test"
HotKeySet("{ESC}", "QuitApp")

$hGUI = GUICreate ($Title, @DesktopWidth+20, @DesktopHeight+20, -10, -10, BitOr($DS_SETFOREGROUND, $WS_POPUPWINDOW), $WS_EX_TOPMOST)
GUISetBkColor (0x000000)
WinSetTrans ($hGUI, "", 180)
GUISetState ()

$Main_Gui = GUICreate("", @DesktopWidth+20, @DesktopHeight+20, -10, -10, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

$But1 = GUICtrlCreateButton(" Exit ", 100, 100, 80, 21)
$Logo = GUICtrlCreatePic ("", 50, 50, 300, 200 )
_SetImage($Logo, @ScriptDir & "\img\logo.png")

GUISetControlsVisible($Main_Gui)
GUISetState()

Do
Until GUIGetMsg() = $But1

Func GUISetControlsVisible($hWnd)
    Local $aClassList, $aM_Mask, $aCtrlPos, $aMask
    
    $aClassList = StringSplit(_WinGetClassListEx($hWnd), @LF)
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    
    For $i = 1 To UBound($aClassList) - 1
        $aCtrlPos = ControlGetPos($hWnd, '', $aClassList[$i])
        If IsArray($aCtrlPos) Then
            $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
                "long", $aCtrlPos[0], _
                "long", $aCtrlPos[1], _
                "long", $aCtrlPos[0] + $aCtrlPos[2], _
                "long", $aCtrlPos[1] + $aCtrlPos[3])
            DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
        EndIf
    Next
    
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc

Func _WinGetClassListEx($sTitle)
    Local $sClassList = WinGetClassList($sTitle)
    Local $aClassList = StringSplit($sClassList, @LF)
    Local $sRetClassList = "", $sHold_List = "|"
    Local $aiInHold, $iInHold
    
    For $i = 1 To UBound($aClassList) - 1
        If $aClassList[$i] = "" Then ContinueLoop
        
        If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
            $aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])
            
            If $iInHold = 0 Then $iInHold += 1
            
            $aClassList[$i] &= "~" & $iInHold + 1
            $sHold_List &= $aClassList[$i] & "|"
            
            $sRetClassList &= $aClassList[$i] & @LF
        Else
            $aClassList[$i] &= "~1"
            $sHold_List &= $aClassList[$i] & "|"
            $sRetClassList &= $aClassList[$i] & @LF
        EndIf
    Next
    
    Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc

Func QuitApp()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok, It didn't made my day :) I am using an transparent picture, and now??

Edited by Rawox

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Doesn't work is very dull, can you tell what you wanted to achieve and what happened instead?

Edited by Authenticity

Share this post


Link to post
Share on other sites

Doesn't work is very dull, can you tell what you wanted to achieve and what happened instead?

The example you gave me works with non-transparent pictures but I am trying to use an transparent PNG file and it doesn't show the transparency in that way, is that clear enough? :)

Share this post


Link to post
Share on other sites

The example you gave me works with non-transparent pictures but I am trying to use an transparent PNG file and it doesn't show the transparency in that way, is that clear enough? :)

This example by Yashied might help.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Ahh it does not work, Ohh... You have not thought about that, not all will run your code. You should be more correct to ask a question.

This example you can see (or find) a few days ago. Basically, everything here is what you need.

#Include <GDIPlus.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

Global Const $sPng = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\Examples\GUI\Advanced\Images\Torus.png'

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sPng)

$hMain = GUICreate('Test', 250, 250, 400, 400)
GUISetBkColor(0xF0B7FD)
$Button = GUICtrlCreateButton('OK', 93, 216, 70, 23)
GUISetState()

$hPopup = GUICreate('', 193, 184, 400 + 45 + 3, 400 + 28 + 29, BitOR($WS_DISABLED, $WS_POPUP), $WS_EX_LAYERED, $hMain)
GUISetState()

GUIRegisterMsg($WM_MOVE, "WM_MOVE")

$Timer = TimerInit()
$Trans = 255
$Direction  = -1
$Step = 5
$TimeOut = 30

Do
    If TimerDiff($Timer) > $TimeOut Then
        $Trans += $Step * $Direction
        If $Direction > 0 Then
            If $Trans > 255  Then
                $Trans = 255
                $Direction = -1
            EndIf
        Else
            If $Trans < 0  Then
                $Trans = 0
                $Direction = +1
            EndIf
        EndIf
        _SetBitmap($hPopup, $hImage, $Trans)
        $Timer = TimerInit()
    EndIf
Until GUIGetMsg() = -3

_GDIPlus_Shutdown()

Func _SetBitmap($hWnd, $hImage, $iOpacity)

    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', _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, 'Y', _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 1)
    _WinAPI_UpdateLayeredWindow($hWnd, $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

Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hMain
            WinMove($hPopup, '', BitAND($lParam, 0xFFFF) + 45, BitShift($lParam, 16) + 28)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

Share this post


Link to post
Share on other sites

Well.

I don't think I get it, but I think I have another solution for now, first I'm going to sleep.

Thanks anyway :)

You guys rock!

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Good night. Morning wiser than the evening (or something like that).

:)

From the last verse of "the Ryhme of the Ancient Mariner" by Samuel Coleridge

He went like one that hath been stunned,

And is of sense forlorn :

A sadder and a wiser man,

He rose the morrow morn.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
Sign in to follow this  
Followers 0