Sign in to follow this  
Followers 0
incepator

png image design

2 posts in this topic

Hello guys,

I have a problem trying to do a panel with a png image, the problem is i can not insert a png image buttons.

If anyone has an exemple ....

Thanks...

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

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI secti

_GDIPlus_Startup()

#region
$aRes1 = DisplayImage("1.png", -1, -1, 0)
$aPos = WinGetPos($aRes1[0])

$aRes2 = DisplayImage("bara.png", $aPos[0] + 251 - 30, $aPos[1] + 6)
$aRes3 = DisplayImage("patrat.png", $aPos[0] + 251 - 60, $aPos[1] + 6)
$aRes4 = DisplayImage("inchide.png", $aPos[0] + 251, $aPos[1] + 6)


_Fader($aRes1)
;_Fader($aRes1, False)
#endregion

While True
    $aPos = WinGetPos($aRes1[0])

    WinMove($aRes2[0], "", $aPos[0] + 251 - 30, $aPos[1] + 6)
    WinSetOnTop($aRes2[0], "", 1)

    WinMove($aRes3[0], "", $aPos[0] + 251 - 60, $aPos[1] + 6)
    WinSetOnTop($aRes3[0], "", 1)

    WinMove($aRes4[0], "", $aPos[0] + 251, $aPos[1] + 6)
    WinSetOnTop($aRes4[0], "", 1)
WEnd

_GDIPlus_Shutdown()

;Exit

Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True)
    Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image
    If @error Then Return SetError(1, 0, 0) ;image cannot be loaded
    Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image
    Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI)
    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
    GUISetState(@SW_SHOW, $hGUI) ;show GUI

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap

    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions
    Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context
    Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height)
    DllStructSetData($tSize, "X", $iW) ;set data for width
    DllStructSetData($tSize, "Y", $iH) ;set data for height
    Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info
    DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent
    DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels
    DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen

    ;release resources otherwise memory will filled up (memory leak)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $aResource[7] = [$hGUI, $hScrDC, $hHBitmap, $hMemDC, $tBlend, $tSize, $tSource] ;return the handle to release it later
    Return $aResource
EndFunc

Func ReleaseResources(ByRef $aResource)
    If Not IsArray($aResource) Then Return SetError(1, 0, 0)
    If UBound($aResource) <> 7 Then Return SetError(2, 0, 0)
    _WinAPI_ReleaseDC($aResource[0], $aResource[1])
    _WinAPI_DeleteDC($aResource[3])
    _WinAPI_DeleteObject($aResource[2])
    GUIDelete($aResource[0])
EndFunc

Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10)
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    Switch $bIn
        Case True
            For $a = 0 To $iTrans Step $speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
        Case Else
            For $a = $iTrans To 0 Step -$speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
    EndSwitch
EndFunc   ;==>_Fader

#region GDI and GDI+ functions
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
#endregion GDI and GDI+ functions

post-75717-0-72498500-1385378107_thumb.ppost-75717-0-83298400-1385378107_thumb.ppost-75717-0-14913400-1385378108_thumb.ppost-75717-0-25337400-1385378108_thumb.p

Share this post


Link to post
Share on other sites



Does this help? Double-click the Min,Max or Close buttons(or png) and see them in action

#include-once
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#region ### START Koda GUI secti

Global Const $SC_DRAGMOVE = 0xF012

_GDIPlus_Startup()

#region
$aRes1 = DisplayImage("1.png", -1, -1, 0, True, True)

$aRes2 = DisplayImage("bara.png", 251 - 30, -30) ;min
$aRes3 = DisplayImage("patrat.png", 251 - 60, -30) ;max
$aRes4 = DisplayImage("inchide.png", 251, -30) ;close


_Fader($aRes1)
;_Fader($aRes1, False)
#endregion

While True
    $nMsg = GUIGetMsg(1) ;check helpfile for GUIGetMsg in advanced mode

    Switch $nMsg[0]
        Case $GUI_EVENT_PRIMARYDOWN ;mouse down event

            Switch $nMsg[1]
                Case $aRes1[0]
                    _SendMessage($aRes1[0], $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)    ;for window drag

                Case $aRes2[0]
                    WinSetState($aRes1[0], "", @SW_MINIMIZE)

                Case $aRes3[0]
                    WinSetState($aRes1[0], "", @SW_MAXIMIZE)

                Case $aRes4[0]
                    ExitLoop

            EndSwitch

    EndSwitch
WEnd

ReleaseResources($aRes1)
ReleaseResources($aRes2)
ReleaseResources($aRes3)
ReleaseResources($aRes4)

_GDIPlus_Shutdown()

Exit

Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True, $bMain = False)

    Static $hMainWin

    Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image
    If @error Then Return SetError(1, 0, 0) ;image cannot be loaded
    Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image
    Local $hGUI

    If $hMainWin Then
        $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW, $WS_EX_MDICHILD), $hMainWin)
    Else
        $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW))
    EndIf

    If $bMain Then $hMainWin = $hGUI

    ;the following would conflict with main GUI mousedown message
    ;///If $bMovable Then GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging


    GUISetState(@SW_SHOW, $hGUI) ;show GUI

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap

    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions
    Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context
    Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height)
    DllStructSetData($tSize, "X", $iW) ;set data for width
    DllStructSetData($tSize, "Y", $iH) ;set data for height
    Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info
    DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent
    DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels
    DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen

    ;release resources otherwise memory will filled up (memory leak)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $aResource[7] = [$hGUI, $hScrDC, $hHBitmap, $hMemDC, $tBlend, $tSize, $tSource] ;return the handle to release it later
    Return $aResource
EndFunc   ;==>DisplayImage

Func ReleaseResources(ByRef $aResource)
    If Not IsArray($aResource) Then Return SetError(1, 0, 0)
    If UBound($aResource) <> 7 Then Return SetError(2, 0, 0)
    _WinAPI_ReleaseDC($aResource[0], $aResource[1])
    _WinAPI_DeleteDC($aResource[3])
    _WinAPI_DeleteObject($aResource[2])
    GUIDelete($aResource[0])
EndFunc   ;==>ReleaseResources

Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10)
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    For $a = 0 To $iTrans Step _Iif($bIn, $speed, -$speed)
        DllStructSetData($res1[4], "Alpha", $a)
        DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
        Sleep($delay)
    Next

EndFunc   ;==>_Fader

#region GDI and GDI+ functions
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
#endregion GDI and GDI+ functions

Regards :)

1 person likes this

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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