Jump to content

PNG Form and Progress bar


PlayHD
 Share

Recommended Posts

Hy....

1st i want to sorry for my english

Now.. I have a problem.... I want to make a Gui Png

But wont work to add a progress bar or other Controls....

Can help me?

Thanks in Advance

gui.rar

UPDATE

How i can add a PNG pic...

With _SetImage from not working....

Or set Transparent Background on Label

GuiCtrlSetBkColor($label_Info,-2)
down't work...

Thanks in advance!

Edited by PlayHD
Link to comment
Share on other sites

Try this:

Main.au3

#include <GuiSkin.au3>
Global $MY_GUIIMAGE = "gui.png"
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($MY_GUIIMAGE)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)

$GUI = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 0)

Global Const $IMAGE_BITMAP = 0
Global Const $STM_SETIMAGE = 0x0172
$GUI_Child = GUICreate("", $width, $height, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $GUI)
GUICtrlCreateProgress(30,30,100,20)
GUICtrlSetData(-1, 50)
$idButton = GUICtrlCreateButton("Exit", $width - 120, $height - 100, 80, 80)
GUISetControlsVisible($GUI_Child)

$GUI_Child2 = GUICreate("", 193, 184, 50, 100, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_LAYERED, $GUI)
GUISetBkColor(0xD6E9F2, $GUI_Child2)
$idPic = GUICtrlCreatePic("", 0, 0, 193, 184)
$hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png"))
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
_WinAPI_SetLayeredWindowAttributes($GUI_Child2, 0xD6E9F2)

GUISetState(@SW_SHOW, $GUI)
GUISetState(@SW_SHOW, $GUI_Child2)
GUISetState(@SW_SHOW, $GUI_Child)

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

For $i = 0 To 255 Step 10  ;fade
    SetBitmap($GUI, $hImage, $i)
Next

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3, $idButton
            ExitLoop
    EndSwitch
WEnd

_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete($GUI_Child)
GUIDelete($GUI)
Exit

Func GUISetControlsVisible($hWnd)
    Local $aM_Mask, $aCtrlPos, $aMask

    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))

    For $i = 3 To $aLastID[0]
        $aCtrlPos = ControlGetPos($hWnd, '', $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

Edit: added 2nd child GUI for PNG image.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thank you ;)

you realy good :)

I'm a kind of beginner...

Thanks again

UPDATE

How i can add a PNG pic...

With _SetImage from not working....

Or set Transparent Background on Label

GuiCtrlSetBkColor($label_Info,-2)
down't work...

Thanks in advance!

Edited by PlayHD
Link to comment
Share on other sites

and here another solution:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "GUICtrlPic.au3"
Global $aHoverBtn[5][5]
$aHoverBtn[0][1] = @ScriptDir & "PicturesUp.png" ;D:ProgrammeAutoIt3MyDemosPicturesup.png
$aHoverBtn[0][2] = @ScriptDir & "PicturesUpHover.png"
$aHoverBtn[0][3] = @ScriptDir & "PicturesUpPress.png"
$aHoverBtn[0][4] = False
$aHoverBtn[1][1] = @ScriptDir & "PicturesDown.png"
$aHoverBtn[1][2] = @ScriptDir & "PicturesDownHover.png"
$aHoverBtn[1][3] = @ScriptDir & "PicturesDownPress.png"
$aHoverBtn[1][4] = False
$aHoverBtn[2][1] = @ScriptDir & "PicturesLeft.png"
$aHoverBtn[2][2] = @ScriptDir & "PicturesLeftHover.png"
$aHoverBtn[2][3] = @ScriptDir & "PicturesLeftPress.png"
$aHoverBtn[2][4] = False
$aHoverBtn[3][1] = @ScriptDir & "PicturesRight.png"
$aHoverBtn[3][2] = @ScriptDir & "PicturesRightHover.png"
$aHoverBtn[3][3] = @ScriptDir & "PicturesRightPress.png"
$aHoverBtn[3][4] = False
$aHoverBtn[4][1] = @ScriptDir & "PicturesExit.png"
$aHoverBtn[4][2] = @ScriptDir & "PicturesExitHover.png"
$aHoverBtn[4][3] = @ScriptDir & "PicturesExitPress.png"
$aHoverBtn[4][4] = False
Global $hGui = GUICreate("Hovered Ping-Buttons", 612, 369, 271, 235)
Local $sAutoItPath = StringReplace(@AutoItExe, "autoit3.exe", "")
ConsoleWrite($sAutoItPath & "ExamplesGUImsoobe.jpg" & @CRLF)
Local $Background = _GUICtrlPic_Create($sAutoItPath & "ExamplesGUImsoobe.jpg", 0, 0, 612, 369, $SS_CENTERIMAGE, Default)
GUICtrlSetState(-1, $Gui_DISABLE)
Local $idTorus = _GUICtrlPic_Create($sAutoItPath & "ExamplesGUITorus.png", 8, 8, 68, 71, $SS_CENTERIMAGE, Default)
GUICtrlSetState(-1, $Gui_DISABLE)
$aHoverBtn[0][0] = _GUICtrlPic_Create($aHoverBtn[0][1], 460, 8, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Up
$aHoverBtn[1][0] = _GUICtrlPic_Create($aHoverBtn[1][1], 460, 138, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Down
$aHoverBtn[2][0] = _GUICtrlPic_Create($aHoverBtn[2][1], 400, 73, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Left
$aHoverBtn[3][0] = _GUICtrlPic_Create($aHoverBtn[3][1], 520, 73, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Right
$aHoverBtn[4][0] = _GUICtrlPic_Create($aHoverBtn[4][1], 540, 266, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Exit
GUISetState()
While 1
    #Region ;Hover Or Not?
    $Info = GUIGetCursorInfo($hGui)
    For $i = 0 To UBound($aHoverBtn) - 1
        If $Info[4] = $aHoverBtn[$i][0] Then
            If $aHoverBtn[$i][4] Then _GUICtrlPic_SetImage($aHoverBtn[$i][0], $aHoverBtn[$i][2], True)
            $aHoverBtn[$i][4] = False
        Else
            If Not $aHoverBtn[$i][4] Then _GUICtrlPic_SetImage($aHoverBtn[$i][0], $aHoverBtn[$i][1], True)
            $aHoverBtn[$i][4] = True
        EndIf
    Next
    #EndRegion
    $nMsg = GUIGetMsg()
    $aPos = ControlGetPos($hGui, "", $idTorus)
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            Exit
        Case $aHoverBtn[0][0]
            If _AnimButton($hGui, $aHoverBtn[0][0], $aHoverBtn[0][1], $aHoverBtn[0][3]) Then $aPos[1] -= 5 ;nach oben
        Case $aHoverBtn[1][0]
            If _AnimButton($hGui, $aHoverBtn[1][0], $aHoverBtn[1][1], $aHoverBtn[1][3]) Then $aPos[1] += 5 ;nach unten
        Case $aHoverBtn[2][0]
            If _AnimButton($hGui, $aHoverBtn[2][0], $aHoverBtn[2][1], $aHoverBtn[2][3]) Then $aPos[0] -= 5 ;nach links
        Case $aHoverBtn[3][0]
            If _AnimButton($hGui, $aHoverBtn[3][0], $aHoverBtn[3][1], $aHoverBtn[3][3]) Then $aPos[0] += 5 ;nach rechts
        Case $aHoverBtn[4][0]
            If _AnimButton($hGui, $aHoverBtn[4][0], $aHoverBtn[4][1], $aHoverBtn[4][3]) Then Exit
    EndSwitch
    ControlMove($hGui, "", $idTorus, $aPos[0], $aPos[1])
WEnd
;==================================================================================================
; Function Name:    _AnimButton($IDgui, $IDbtn [, $delay=150])
; Description:      animiert ein Pic, wie einen geklickten Button
; Parameter(s):     $IDgui    ID der GUI
;                   $IDbtn    ID des Picture als Button
;                   $sNormal    Pfad zum angezeigten Bild des Buttons im nrmalen Zustand
;                   $sPress     Pfad zum angezeigten Bild des Buttons im gedrückten Zustand
; Author:          BugFix
; modified:         autoBert
;==================================================================================================
Func _AnimButton($IDgui, $IDbtn, $sNormal = "", $sPress = "")
    ;ConsoleWrite($IDbtn & @TAB & $sNormal & @TAB & $sPress & @CRLF)
    If $IDbtn = 0 Then Return
    Local $pos = ControlGetPos($IDgui, '', $IDbtn)
    Local $pWin = WinGetPos(GUICtrlGetHandle($IDbtn))
    If $sPress <> "" And FileExists($sPress) Then _GUICtrlPic_SetImage($IDbtn, $sPress)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1] + 1, $pos[2] - 1, $pos[3] - 1)
    $return = 1
    Do
        $x = GUIGetCursorInfo($IDgui)
        If $x[4] <> $IDbtn Then $return = 0
        Sleep(10)
    Until $x[2] = 0
    If $sNormal <> "" And FileExists($sNormal) Then _GUICtrlPic_SetImage($IDbtn, $sNormal, True)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1], $pos[2], $pos[3])
    Return $return
EndFunc   ;==>_AnimButton
to run this example you need GuiCtrlPic (@Großvater):
; #INDEX# =======================================================================================================================
; Title .........: GUICtrlPic
; AutoIt Version : 3.3.6.1
; Description ...: Ergänzende Funktionen für Pic-Controls
; Author(s) .....: Großvater
; Dll ...........: GDI32.dll, GDIPlus.dll
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _GUICtrlPic_Create
; _GUICtrlPic_SetImage
; _GUICtrlPic_LoadImage
; _GUICtrlPic_ScaleBitmap
; _GUICtrlPic_GradientFill
; _GUICtrlPic_Invert
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Create
; Description ...: Pic-Control für alle von GDIPlus unterstützten Formate ggf. mit Transparenz erstellen.
; Syntax.........: _GUICtrlPic_Create($sPicPath, $iLeft, $iTop[, $iWidth = 0[, $iHeight = 0[, $uStyles = -1[, $uExStyles = -1[, $bKeepAspectRatio = False]]]]])
; Parameters ....: Die Parameter entsprechen bis auf den letzten der AU3-Funktion GUICtrlCreatePic()
;                 $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten:
;                 |True - ja
;                 |False   - nein
;                 |Default - nein
; Return values .: Im Erfolgsfall: ControlID aus GUICtrlCreatePic()
;                 Im Fehlerfall: False, @error und @extended enthalten ergänzende fehlerbeschreibende Werte.
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_Create($sPicPath, $iLeft, $iTop, $iWidth = 0, $iHeight = 0, $uStyles = -1, $uExStyles = -1, $bKeepAspectRatio = False)
    Local Const $IMAGE_BITMAP = 0x0000
    Local Const $STM_SETIMAGE = 0x0172
    Local $aResult, $hBitmap, $hImage, $Height, $Width, $CtrlID
    Local $aBitmap = _GUICtrlPic_LoadImage($sPicPath)
    If @error Then Return SetError(@error, @extended, False)
    $hBitmap = $aBitmap[0]
    $Width = $aBitmap[1]
    $Height = $aBitmap[2]
    If $iWidth = 0 And $iHeight = 0 Then
        $iWidth = $Width
        $iHeight = $Height
    Else
        $hBitmap = _GUICtrlPic_ScaleBitmap($hBitmap, $iWidth, $iHeight, $Width, $Height, $bKeepAspectRatio)
        If @error Then Return SetError(@error, @extended, False)
    EndIf
    $CtrlID = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $uStyles, $uExStyles)
    GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBitmap)
    Return $CtrlID
EndFunc   ;==>_GUICtrlPic_Create
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetImage
; Description ...: Neues Bild in Pic-Control erstellen.
; Syntax.........: _GUICtrlPic_SetImage($idPic, $sPicPath[, $bKeepAspectRatio = False])
; Parameters ....: $idPic           - ID des PIC-Controls
;                 $sPicPath      - vollständiger Pfad der Bilddatei
;                 $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten:
;                 |True - ja
;                 |False   - nein
;                 |Default - nein
; Return values .: Im Erfolgsfall: True
;                 Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_SetImage($idPic, $sPicPath, $bKeepAspectRatio = False)
    Local Const $IMAGE_BITMAP = 0x0000
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $STM_GETIMAGE = 0x0173
    Local $aSize, $hBM, $hBitmap, $Height, $Width
    Local $aBitmap = _GUICtrlPic_LoadImage($sPicPath)
    If @error Or $aBitmap[0] = 0 Then Return SetError(@error, @extended, False)
    $hBitmap = $aBitmap[0]
    $Width = $aBitmap[1]
    $Height = $aBitmap[2]
    $aSize = WinGetClientSize(GUICtrlGetHandle($idPic))
    $hBitmap = _GUICtrlPic_ScaleBitmap($hBitmap, $aSize[0], $aSize[1], $Width, $Height, $bKeepAspectRatio)
    $hBM = GUICtrlSendMsg($idPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0)
    If $hBM Then DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBM)
    GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBitmap)
    GUICtrlSetState($idPic, $GUI_SHOW)
    Return True
EndFunc   ;==>_GUICtrlPic_SetImage
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_LoadImage
; Description ...: Bilddatei laden und HBITMAP erzeugen
; Syntax.........: _GUICtrlPic_LoadImage($sPicPath)
; Parameters ....: $sPicPath         - vollständiger Pfad der Bilddatei
; Return values .: Im Erfolgsfall: Array mit drei Einträgen, Array[0] enthält ein HBITMAP-Handle,
;                                 Array[1] die Breite und Array[2] die Höhe der Bitmap
;                 Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......: Die Funktion kann auch einzeln genutzt werden, um eine Bitmap zu laden und dann per
;                 GUICtrlSendMsg($idPIC, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) einem Pic-Control zuzuweisen.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_LoadImage($sPicPath)
    Local $aResult, $hBitmap, $hImage, $Height, $Width
    Local $aBitmap[3] = [0, 0, 0]
    Local $hGDIPDll = DllOpen("GDIPlus.dll")
    If $hGDIPDll = -1 Then Return SetError(1, 2, $aBitmap)
    Local $tInput = DllStructCreate("UINT Version;ptr Callback;BOOL NoThread;BOOL NoCodecs")
    Local $pInput = DllStructGetPtr($tInput)
    Local $tToken = DllStructCreate("ULONG_PTR Data")
    Local $pToken = DllStructGetPtr($tToken)
    DllStructSetData($tInput, "Version", 1)
    $aResult = DllCall($hGDIPDll, "INT", "GdiplusStartup", "Ptr", $pToken, "Ptr", $pInput, "Ptr", 0)
    If @error Then Return SetError(@error, @extended, $aBitmap)
    $aResult = DllCall($hGDIPDll, "INT", "GdipLoadImageFromFile", "WStr", $sPicPath, "Ptr*", 0)
    If @error Or $aResult[2] = 0 Then
        Local $Error = @error, $Extended = @extended
        DllCall($hGDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data"))
        DllClose($hGDIPDll)
        Return SetError($Error, $Extended, $aBitmap)
    EndIf
    $hImage = $aResult[2]
    $aResult = DllCall($hGDIPDll, "INT", "GdipGetImageWidth", "Handle", $hImage, "UINT*", 0)
    $Width = $aResult[2]
    $aResult = DllCall($hGDIPDll, "INT", "GdipGetImageHeight", "Handle", $hImage, "UINT*", 0)
    $Height = $aResult[2]
    $aResult = DllCall($hGDIPDll, "INT", "GdipCreateHBITMAPFromBitmap", "Handle", $hImage, "Ptr*", 0, "DWORD", 0xFF000000)
    $hBitmap = $aResult[2]
    DllCall($hGDIPDll, "INT", "GdipDisposeImage", "Handle", $hImage)
    DllCall($hGDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data"))
    DllClose($hGDIPDll)
    $aBitmap[0] = $hBitmap
    $aBitmap[1] = $Width
    $aBitmap[2] = $Height
    Return $aBitmap
EndFunc   ;==>_GUICtrlPic_LoadImage
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_ScaleBitmap
; Description ...: Geladene Bitmap skalieren.
; Syntax.........: _GUICtrlPic_ScaleBitmap($hBitmap, $iNewW, $iNewH[, $iBitmapW[, $iBitmapH[, $bKeepAspectRatio = False]]])
; Parameters ....: $hBitmap       - HBITMAP-Handle
;                 $iNewW            - gewünschte Breite in Pixeln
;                 $iNewH            - gewünschte Höhe in Pixeln
;                 $iBitmapW      - aktuelle Breite der Bitmap (wird nur für das Skalieren im Seitenverhältnis benötigt
;                 $iBitmapH      - aktuelle Höhe der Bitmap (wird nur für das Skalieren im Seitenverhältnis benötigt
;                 $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten:
;                 |True - ja
;                 |False   - nein
;                 |Default - nein
; Return values .: Im Erfolgsfall: HBITMAP-Handle für die skalierte Bitmap
;                 Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......: Die Funktion kann auch einzeln genutzt werden, um eine Bitmap zu skalieren und dann per
;                 GUICtrlSendMsg($idPIC, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) einem Pic-Control zuzuweisen.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_ScaleBitmap($hBitmap, $iNewW, $iNewH, $iBitmapW, $iBitmapH, $bKeepAspectRatio = False)
    Local Const $IMAGE_BITMAP = 0x0000
    If $bKeepAspectRatio Then
        If $iBitmapW >= $iBitmapH Then
            $iBitmapH *= $iNewW / $iBitmapW
            $iBitmapW = $iNewW
            If $iBitmapH > $iNewH Then
                $iBitmapW *= $iNewH / $iBitmapH
                $iBitmapH = $iNewH
            EndIf
        Else
            $iBitmapW *= $iNewH / $iBitmapH
            $iBitmapH = $iNewH
            If $iBitmapW > $iNewW Then
                $iBitmapH *= $iNewW / $iBitmapW
                $iBitmapW = $iNewW
            EndIf
        EndIf
    Else
        $iBitmapW = $iNewW
        $iBitmapH = $iNewH
    EndIf
    Local $aResult = DllCall("User32.dll", "Handle", "CopyImage", _
            "Handle", $hBitmap, "UINT", $IMAGE_BITMAP, "INT", $iBitmapW, "INT", $iBitmapH, "UINT", 0x4 + 0x8)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_GUICtrlPic_ScaleBitmap
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_GradientFill
; Description ...: Füllt ein Pic-Control mit einem zweifarbigen linearen Farbverlauf.
; Syntax.........: _GUICtrlPic_GradientFill($idCTRL, $C1, $C2[, $D = 1[, $3D = 3[, $GC = 0[, $BW = 0[, $BH = 0]]]]])
; Parameters ....: $idCTRL  - ID des Pic-Controls aus GUIStrlCreatePic()
;                 $C1     - Startfarbe als 6-stelliger RGB-Hexstring ("RRGGBB")
;                 $C2     - Zielfarbe als 6-stelliger RGB-Hexstring ("RRGGBB")
;                 $D       - Verlaufsrichtung:
;                 |0       - horizontal
;                 |1       - vertikal
;                 |2       - diagonal (links oben -> rechts unten)
;                 |3       - diagonal (rechts oben -> links unten)
;                 |Default - 0
;                 $3D     - Verlaufsart:
;                 |1       - flacher Verlauf (Startfarbe -> Zielfarbe)
;                 |2       - "3D"-Verlauf (Startfarbe -> Zielfarbe -> Startfarbe)
;                 |3       - erhaben (wie 2, die Startfarbe bleibt aber im Randbereich)
;                 |Default - 1
;                 $GC     - Gammakorrektur:
;                 |0       - ohne
;                 |1       - mit
;                 |Default - 0
;                 $BW     - Breite des Verlaufs in Pixeln
;                 |Default - 0 (Breite des Controls)
;                 $BH     - Höhe des Verlaufs in Pixeln
;                 |Default - 0 (Höhe des Controls)
; Return values .: Bei erfolgreicher Ausführung: Handle der erzeugten Bitmap (HBITMAP)
;                 Im Fehlerfall: False, @error wird auf 1 gesetzt
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......: Das Control muss mit GUICtrlCreatePic() erzeugt worden sein, sonst geschieht nichts.
;                 Die Parameter $BW und $BH laden zum Experimentieren ein.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_GradientFill($idCTRL, $C1, $C2, $D = 1, $3D = 3, $GC = 0, $BW = 0, $BH = 0)
    Local Static $STM_SETIMAGE = 0x172
    Local Static $IMAGE_BITMAP = 0x0
    Local Static $BITSPIXEL = 0xC
    Local $hWnd
    If IsHWnd($idCTRL) Then
        $hWnd = $idCTRL
    Else
        $hWnd = GUICtrlGetHandle($idCTRL)
    EndIf
    Local $aResult = DllCall("User32.dll", "Int", "GetClassName", "Hwnd", $hWnd, _
            "Str", "", "Int", 256)
    If $aResult[2] <> "Static" Then
        Return False
    EndIf
    Local $GDIPDll = DllOpen("GDIPlus.dll")
    If $GDIPDll = -1 Then
        Return SetError(1, 0, False)
    EndIf
    Local $SI = DllStructCreate("UInt Version;Ptr Callback;Bool NoThread;Bool NoCodecs")
    Local $Token = DllStructCreate("ulong_ptr Data")
    DllStructSetData($SI, "Version", 1)
    $aResult = DllCall($GDIPDll, "Int", "GdiplusStartup", _
            "Ptr", DllStructGetPtr($Token), "Ptr", DllStructGetPtr($SI), "Ptr", 0)
    If @error Then
        DllClose($GDIPDll)
        Return SetError(1, 0, False)
    EndIf
    Local $GDIPToken = DllStructGetData($Token, "Data")
    Local $RECT = DllStructCreate("Long; Long; Long Right;Long Bottom")
    DllCall("User32.dll", "Bool", "GetClientRect", "Hwnd", $hWnd, _
            "Ptr", DllStructGetPtr($RECT))
    Local $W = DllStructGetData($RECT, "Right")
    Local $H = DllStructGetData($RECT, "Bottom")
    Switch $D
        Case 0, 1, 2, 3
        Case Else
            $D = 0
    EndSwitch
    Switch $3D
        Case 1, 2, 3
        Case Else
            $3D = 1
    EndSwitch
    Switch $GC
        Case 0, 1
        Case Else
            $GC = 0
    EndSwitch
    If $BW = 0 Then $BW = $W
    If $BH = 0 Then $BH = $H
    Local $pBITMAP = DllStructCreate("Ptr")
    DllCall($GDIPDll, "Int", "GdipCreateBitmapFromScan0", _
            "Int", $W, "Int", $H, "Int", 0, "Int", 0x26200A, "Ptr", 0, _
            "Ptr", DllStructGetPtr($pBITMAP))
    $pBITMAP = DllStructGetData($pBITMAP, 1)
    Local $pGRAPHICS = DllStructCreate("Ptr")
    DllCall($GDIPDll, "Int", "GdipGetImageGraphicsContext", _
            "Ptr", $pBITMAP, "Ptr", DllStructGetPtr($pGRAPHICS))
    $pGRAPHICS = DllStructGetData($pGRAPHICS, 1)
    DllCall($GDIPDll, "Int", "GdipSetSmoothingMode", "Ptr", $pGRAPHICS, "Int", 0)
    Local $RECTF = DllStructCreate("Float L;Float T;Float R;Float B")
    DllStructSetData($RECTF, "R", $BW)
    DllStructSetData($RECTF, "B", $BH)
    Local $Color1 = "0xFF" & $C1
    Local $Color2 = "0xFF" & $C2
    Local $pBRUSH = DllStructCreate("Ptr")
    DllCall($GDIPDll, "Int", "GdipCreateLineBrushFromRect", _
            "Ptr", DllStructGetPtr($RECTF), "Int", $Color1, "Int", $Color2, _
            "Int", $D, "Int", 0, "Ptr", DllStructGetPtr($pBRUSH))
    $pBRUSH = DllStructGetData($pBRUSH, 1)
    DllCall($GDIPDll, "Int", "GdipSetLineGammaCorrection", "Ptr", $pBRUSH, _
            "Int", $GC)
    Local $RELINT = DllStructCreate("Float[5]")
    Switch $3D
        Case 1
            DllStructSetData($RELINT, 1, 0.00, 1)
            DllStructSetData($RELINT, 1, 0.25, 2)
            DllStructSetData($RELINT, 1, 0.50, 3)
            DllStructSetData($RELINT, 1, 0.75, 4)
            DllStructSetData($RELINT, 1, 1.00, 5)
        Case 2
            DllStructSetData($RELINT, 1, 0.0, 1)
            DllStructSetData($RELINT, 1, 0.5, 2)
            DllStructSetData($RELINT, 1, 1.0, 3)
            DllStructSetData($RELINT, 1, 0.5, 4)
            DllStructSetData($RELINT, 1, 0.0, 5)
        Case Else
            DllStructSetData($RELINT, 1, 0.0, 1)
            DllStructSetData($RELINT, 1, 1.0, 2)
            DllStructSetData($RELINT, 1, 1.0, 3)
            DllStructSetData($RELINT, 1, 1.0, 4)
            DllStructSetData($RELINT, 1, 0.0, 5)
    EndSwitch
    Local $RELPOS = DllStructCreate("Float[5]")
    DllStructSetData($RELPOS, 1, 0.0, 1)
    If $3D <> 3 Then
        DllStructSetData($RELPOS, 1, 0.25, 2)
    Else
        DllStructSetData($RELPOS, 1, 0.15, 2)
    EndIf
    DllStructSetData($RELPOS, 1, 0.5, 3)
    If $3D <> 3 Then
        DllStructSetData($RELPOS, 1, 0.75, 4)
    Else
        DllStructSetData($RELPOS, 1, 0.85, 4)
    EndIf
    DllStructSetData($RELPOS, 1, 1.0, 5)
    DllCall($GDIPDll, "Int", "GdipSetLineBlend", _
            "Ptr", $pBRUSH, "Ptr", DllStructGetPtr($RELINT), _
            "Ptr", DllStructGetPtr($RELPOS), "Int", 5)
    DllCall($GDIPDll, "Int", "GdipFillRectangle", "Ptr", $pGRAPHICS, _
            "Ptr", $pBRUSH, "Float", 0, "Float", 0, "Float", $W, "Float", $H)
    Local $hBitmap = DllStructCreate("Ptr")
    DllCall($GDIPDll, "Int", "GdipCreateHBITMAPFromBitmap", _
            "Ptr", $pBITMAP, "Ptr", DllStructGetPtr($hBitmap), "Int", 0XFFFFFFFF)
    $hBitmap = DllStructGetData($hBitmap, 1)
    DllCall($GDIPDll, "Int", "GdipDeleteBrush", "Ptr", $pBRUSH)
    DllCall($GDIPDll, "Int", "GdipDisposeImage", "Ptr", $pBITMAP)
    DllCall($GDIPDll, "Int", "GdipDeleteGraphics", "Ptr", $pGRAPHICS)
    DllCall($GDIPDll, "None", "GdiplusShutdown", "Ptr", $GDIPToken)
    DllClose($GDIPDll)
    GUICtrlSendMsg($idCTRL, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    Return $hBitmap
EndFunc   ;==>_GUICtrlPic_GradientFill
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Invert
; Description ...: Farben eines Pic-Controls invertieren.
; Syntax.........: _GUICtrlPic_LoadImage($sPicPath)
; Parameters ....: $idPic         - ControlID aus GUICtrlCreatePic()
; Return values .: Keine
; Author ........: Großvater (www.autoit.de)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_Invert($idPic)
    Local Const $IMAGE_BITMAP = 0x0000, $STM_SETIMAGE = 0x0172, $STM_GETIMAGE = 0x0173, $DSTINVERT = 0x00550009
    Local $aResult
    Local $hBitmap = GUICtrlSendMsg($idPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0)
    Local $aSize = WinGetClientSize(GUICtrlGetHandle($idPic))
    Local $iWidth = $aSize[0], $iHeight = $aSize[1]
    Local $hGDI32 = DllOpen("Gdi32.dll")
    $aResult = DllCall($hGDI32, "Handle", "CreateCompatibleDC", "Handle", 0)
    Local $hDC = $aResult[0]
    $aResult = DllCall($hGDI32, "Handle", "SelectObject", "Handle", $hDC, "Handle", $hBitmap)
    $aResult = DllCall($hGDI32, "BOOL", "BitBlt", "Handle", $hDC, "INT", 0, "INT", 0, "INT", $iWidth, "INT", $iHeight, _
            "Handle", $hDC, "INT", 0, "INT", 0, "DWORD", $DSTINVERT)
    $aResult = DllCall($hGDI32, "BOOL", "DeleteDC", "Handle", $hDC)
    DllClose($hGDI32)
    GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
EndFunc   ;==>_GUICtrlPic_Invert
; ===============================================================================================================================

and png-images, just named as in the demo-script

greetings from germany

autobert

Edited by AutoBert
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...