Jump to content

png Background and png button help me???


Recommended Posts

png Background and png button help me???

Click png button then Button color failure ????????

You help me to answer the same time, please give me an example. Thank you. .

Note: that I use are all PNG files thanks

Please Run the script in reply Please try again Thank you

I need every one help!~~~

post-57811-12752958388144_thumb.jpg

#Include <GUICtrlSetOnHover.au3>
#Include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#Include <GUICtrlSetOnHover.au3>

;
#NoTrayIcon
#include <GDIPlus.au3>
#include <GuiComboBox.au3>
#include <File.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
;#include <_Animate_Window_UDF.au3>
#include <inet.au3>
#include <ie.au3>
#include <WinAPI.au3>


;Opt('MustDeclareVars', 1)

Global $hForm, $Pic1, $hPic1, $Pic2, $hPic2, $nMsg

_GDIPlus_Startup()




Global Const $AC_SRC_ALPHA = 1

Global $old_string = "", $runthis = ""
Global $launchDir = 'C:\'

; Load PNG file as GDI bitmap
_GDIPlus_Startup()
$pngSrc = @ScriptDir&"\background.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)

; Create layered window
$GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 0)

;A label - On Parent GUI NOT displaying
GUICtrlCreateLabel("A label", ($width + 100) / 2, 5, 100, 35)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

For $i = 0 To 255 Step 10
    Sleep(10)
    SetBitmap($GUI, $hImage, $i)
Next
WinSetOnTop($GUI, "", 1)
GUISetState()


$hForm = GUICreate('Form1', $width, $height, -1, -1,$WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)

GUICtrlSetState(-1, $GUI_DISABLE)

$bt1=GUICtrlCreateButton("test",100,100)


$Pic2 = GUICtrlCreatePic('', 132, 112, 162, 59)
$hPic2 = GUICtrlGetHandle($Pic2)
_SetImageHover($Pic2, @ScriptDir & '\performance.png')
GUICtrlSetOnHover($Pic2, 'HoverPic', 'LeaveHoverPic')

GUISetState()
GUISetBkColor($GUI_BKCOLOR_TRANSPARENT, $hForm)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bt1 
            Exit
    EndSwitch
WEnd

Func HoverPic($CtrlID)
    Select
        Case $CtrlID = $Pic2
            _WinAPI_InvalidateRect($hPic1, _ControlGetRect($hPic2))
            _SetImageHover($Pic2, @ScriptDir & '\performance_over.png')
            _WinAPI_InvalidateRect($hPic2)
    EndSelect
EndFunc   ;==>HoverPic

Func LeaveHoverPic($CtrlID)
    Select
        Case $CtrlID = $Pic2
            _WinAPI_InvalidateRect($hPic1, _ControlGetRect($hPic2))
            _SetImageHover($Pic2, @ScriptDir & '\performance.png')
            _WinAPI_InvalidateRect($hPic2)
    EndSelect
EndFunc   ;==>LeaveHoverPic

Func _ControlGetRect($hWnd)

    Local $Pos = ControlGetPos($hWnd, '', '')
    Local $tRect = DllStructCreate('int;int;int;int')

    DllStructSetData($tRect, 1, $Pos[0])
    DllStructSetData($tRect, 2, $Pos[1])
    DllStructSetData($tRect, 3, $Pos[0] + $Pos[2])
    DllStructSetData($tRect, 4, $Pos[1] + $Pos[3])
    Return $tRect
EndFunc   ;==>_ControlGetRect

Func _SetImageHover($ControlID, $sImage)

    Local $hWnd = GUICtrlGetHandle($ControlID)
    Local $hImage, $hBitmap

;    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromFile($sImage)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
;    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0173))
    _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    $hImage = _SendMessage($hWnd, 0x0173)
    If $hImage <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
EndFunc   ;==>_SetImageHover



Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func SetBitmap($hGUI, $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", $AC_SRC_ALPHA)
    _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
;

pngwith buttun.rar

Edited by loveau3
Link to comment
Share on other sites

  • 2 months later...

Hope This Help

#include <GDIPlus.au3>; this is where the magic happens, people
#include<IE.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiImageList.au3>




$dll=DllOpen("user32.dll")
_GDIPlus_Startup()


#Region ### START Koda GUI section ### Form=
$gui1 = GUICreate("Form1", 744, 464, 233, 359, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_DLGFRAME,$WS_GROUP,$WS_TABSTOP))
GUISetState(@SW_SHOW)





$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\01.png")
$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\02.png")
; Extract image width and height from PNG

$hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\03.png")

$gui2 = GUICreate("Form1", 0, 0, 500,300,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$gui1)
SetBitmap($gui2,$hImage,255)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
buttonpng($gui2,$hImage,$hImage1,$hImage2)

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd



Func SetBitmap($hGUI, $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($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



func buttonpng($guicanset,$anh1,$anh2,$anh3)
        if hander()=$guicanset then
            SetBitmap($guicanset,$anh2,255)
    Do
        if event() then
            Do
                if hander()<>$guicanset then
                SetBitmap($guicanset,$anh1,255)
            Else
                    SetBitmap($guicanset,$anh3,255)
                    EndIf
                                Until not event()
        if hander()=$guicanset then
                SetBitmap($guicanset,$anh2,255)
        MsgBox(0,"","Sample Button")
        EndIf
EndIf
                    Until hander()<>$guicanset
    SetBitmap($guicanset,$anh1,255)
EndIf

EndFunc




Func hander()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc

Func event($sHexKey="01", $vDLL = $dll)
    ; $hexKey must be the value of one of the keys.
    ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R[0], 0x8000) <> 0
EndFunc   ;==>_IsPressed

Button.zip

4m848p10.gif 

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