Jump to content

transparent UI + Picture buttons


Vision
 Share

Recommended Posts

got it so far working but got still a problem there

if i hover over the buttons they are start blinking can you help me fixing this ?

attached you find the code + pictures and includes

#Include <GDIPlus.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

#NoTrayIcon

_GDIPlus_Startup()

$hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\bg_440x440.png')
$hReg = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\big1.png')
$hYellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\small1.png')
$hmail_big = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\big2.png')
$hmail_small = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\small2.png')


$State = Default
$State2 = Default


$height = 500

$hForm = GUICreate('', 440  , 440, -1, $height,$WS_POPUPWINDOW, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))


_Update(0)
;~ _Update1(1)
GUISetState()


While 1
    $Info = GUIGetCursorInfo($hForm)

    _WinAPI_BringWindowToTop($hForm)
        If @error Then
        _Update(0)
        Else


        If ($Info[0] >=10) And ($Info[0] <=210) And ($Info[1] >=10) And ($Info[1] <=210) And (BitAND(_GDIPlus_BitmapGetPixel($hReg, $Info[0] - 10, $Info[1] - 120), 0xFF000000) = 0xFF000000) Then
            _Update(1)
            If $Info[2] Then
                sleep(100)
                MSGBOX(0,"","clicked button1")
            EndIf
        Else
            _Update(0)
        EndIf

        If ($Info[0] >=170) And ($Info[0] <=370) And ($Info[1] >=170) And ($Info[1] <=370) And (BitAND(_GDIPlus_BitmapGetPixel($hmail_big, $Info[0] - 170, $Info[1] - 120), 0xFF000000) = 0xFF000000) Then
            _Update(2)
            If $Info[2] Then
                sleep(100)
                MSGBOX(0,"","clicked button2")
;~
            EndIf
        Else
           _Update(0)
        EndIf



    EndIf
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            ExitLoop
;~ MSGbox(0,"test", $var)
    EndSwitch
WEnd

_GDIPlus_Shutdown()
;~ ######################################################################################################
Func _Update($iState)

    If $iState = $State Then
        Return
    EndIf

    Local $hGraphic, $hImage

    $hImage = _GDIPlus_ImageClone($hBackground)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    Switch $iState
        Case 0
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hYellow,10, 120, 154, 154)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hmail_small,170, 120, 154, 154)
        Case 1
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hReg, 10, 120, 154, 154)
        Case 2
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hmail_big, 170, 120, 154, 154)

    EndSwitch
    _WinAPI_UpdateLayeredWindowEx($hForm, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 255, 1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    $State = $iState
EndFunc   ;==>_Update

;~ #########################################################################################################
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)

    Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipBitmapGetPixel', 'ptr', $hBitmap, 'int', $iX, 'int', $iY, 'ptr*', 0)

    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $aResult[0] Then
            Return SetError($aResult[0], 0, 0)
        EndIf
    EndIf
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel
;~ ###########################################################################################################
Func _GDIPlus_ImageClone($hImage)

    Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCloneImage', 'ptr', $hImage, 'ptr*', 0)

    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $aResult[0] Then
            Return SetError($aResult[0], 0, 0)
        EndIf
    EndIf
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_ImageClone
;~ #############################################################################################################

transparent test.rar

Edited by Vision
Link to comment
Share on other sites

Hi,

#Include <GDIPlus.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

#NoTrayIcon

_GDIPlus_Startup()

$hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\bg_440x440.png')
$hReg = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\big1.png')
$hYellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\small1.png')
$hmail_big = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\big2.png')
$hmail_small = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\small2.png')


$State = Default
$State2 = Default


$height = 500

$hForm = GUICreate('', 440  , 440, -1, $height,$WS_POPUPWINDOW, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))


_Update(0)
;~ _Update1(1)
GUISetState()


While 1
    $Info = GUIGetCursorInfo($hForm)

    _WinAPI_BringWindowToTop($hForm)
    If @error Then
        _Update(0)
    Else
        If ($Info[0] >=10) And ($Info[0] <=144) And ($Info[1] >=120) And ($Info[1] <= 254) And (BitAND(_GDIPlus_BitmapGetPixel($hReg, $Info[0] - 10, $Info[1] - 120), 0xFF000000) = 0xFF000000) Then
            _Update(1)
            If $Info[2] Then
                sleep(100)
                MSGBOX(0,"","clicked button1")
            EndIf
        ElseIf ($Info[0] >=190) And ($Info[0] <=303) And ($Info[1] >=135) And ($Info[1] <=254) And (BitAND(_GDIPlus_BitmapGetPixel($hmail_big, $Info[0] - 190, $Info[1] - 135), 0x00000000) = 0x00000000) Then
            _Update(2)
            If $Info[2] Then
                sleep(100)
                MSGBOX(0,"","clicked button2")
            EndIf
        Else
            _Update(0)
        EndIf

    EndIf
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            ExitLoop
;~ MSGbox(0,"test", $var)
    EndSwitch
WEnd

_GDIPlus_Shutdown()
;~ ######################################################################################################
Func _Update($iState)

    If $iState = $State Then
        Return
    EndIf

    Local $hGraphic, $hImage

    $hImage = _GDIPlus_ImageClone($hBackground)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    Switch $iState
        Case 0
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hYellow,10, 120, 154, 154)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hmail_small,170, 120, 154, 154)
        Case 1
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hReg, 10, 120, 154, 154)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hmail_small,170, 120, 154, 154)
        Case 2
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hYellow,10, 120, 154, 154)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hmail_big, 170, 120, 154, 154)
    EndSwitch
    _WinAPI_UpdateLayeredWindowEx($hForm, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 255, 1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    $State = $iState
EndFunc   ;==>_Update

;~ #########################################################################################################
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)

    Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipBitmapGetPixel', 'ptr', $hBitmap, 'int', $iX, 'int', $iY, 'ptr*', 0)

    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $aResult[0] Then
            Return SetError($aResult[0], 0, 0)
        EndIf
    EndIf
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel
;~ ###########################################################################################################
Func _GDIPlus_ImageClone($hImage)

    Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCloneImage', 'ptr', $hImage, 'ptr*', 0)

    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $aResult[0] Then
            Return SetError($aResult[0], 0, 0)
        EndIf
    EndIf
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_ImageClone
;~ #############################################################################################################

To me this whole script seems very clumsy and finicky to set up per unique button.

I'd prefer a more symmetrical method (which I don't have atm) which can add buttons without working out intricate pixel colors and alignments per button.

But whatever floats your boat :x

Cheers

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...