Sign in to follow this  
Followers 0
picea892

re-painting a shaped control (solved)

1 post in this topic

#1 ·  Posted (edited)

(I took a different approach and was able to create this UDF

I'm hoping someone can help me figure out what the My_Paint function should look like. I can't figure out how to reshape the control after minimizing or moving off the screen. Thanks in advance for the help

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>
#include <StaticConstants.au3>
#Include <Constants.au3>
#include <ButtonConstants.au3>
Opt("GUIOnEventMode",1)
global $guiwidth=420,$guiheight=190, $bckpic,$GUI
Global $hFunc, $guicontrols, $Gui, $start, $end, $allday, $timestart, $timeend, $pic, $bX = 43, $picnames[2][4]

Global $But[6],$But2[6], $Last,$daystate=1, $timestart, $timeend, $infocal=1

    Global $GUI = GUICreate("Outlook", $guiwidth, $guiheight, -1,200, $WS_POPUP)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
    ;GUISetBkColor(0xABCDEF)
        _GDIPlus_Startup()
    Global $bckpic= GUICtrlCreatePic("",0,0,0,0)
     GuiCtrlSetState(-1,$GUI_DISABLE)
    $guibitmap=startbmp($guiwidth, $guiheight)
    $guibitmap= _drawborder($guibitmap,$guiwidth,$guiheight,"4","0x444444","0x666666","15") ;sets up the border on background
    $guibitmap=_addlabel($guibitmap, "Next",$guiwidth-53, $guiheight-28, $guiwidth,"0xAAAAAA", "Verdana",9)
    $guibitmap=_addlabel($guibitmap, "Shaped Controls Example",40, 6, $guiwidth,"0xAAAAAA", "Arial",20)
;   $guibitmap=Seticon($guibitmap,$bckpic, "10","10","32", "32")
    finalizectrl($bckpic,$guibitmap)
    
    Global $a=GUICtrlCreatePic("",35,35,180,40)
    $guibitmap=startbmp(180, 40)
    $guibitmap=_createbutton($guibitmap,180, 40,10,"0xAAAAAA","0x000011" ,"0x110000", 1,"Just Some Text","C:\Program Files\Internet Explorer\iexplore.exe", 0 )
    finalizectrl($a,$guibitmap)

    _GDIPlus_Shutdown()

  GUISetState()
    ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", " ", "wstr", " ")
    _GuiRoundCorners($GUI,0, 0, 30, 30) ; makes the background have round corners
_ControlToRoundedRectangle($a,1,1,182,42,24)
GUIRegisterMsg(0xF, "MY_PAINT")
While 1
    sleep(100)
    $amouse=MouseGetPos()
    $agui=WinGetPos($GUI)

WEnd
Func MY_PAINT($hwnd, $Msg, $wParam, $lParam)
    ; Check, if the GUI with the Graphic should be repainted
    If $hwnd = WinGetHandle($GUI) Then
_ControlToRoundedRectangle($a,1,1,102,42,24)
ConsoleWrite("Here"&@crlf)
;   _WinAPI_RedrawWindow($GUI,0,0,BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN)) ; works, but redraws entire screen.
;_WinAPI_RedrawWindow($GUI, "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    EndIf
EndFunc   ;==>MY_PAINT

Func _ControlToRoundedRectangle($aControl,$X1,$Y1,$X2,$Y2,$X3)
    Local $l
    Local $handle = GUICtrlGetHandle($aControl)
    $l = DllCall("gdi32.dll","int","CreateRoundRectRgn","int",$X1,"int",$Y1,"int",$X2,"int",$Y2,"int",$X3,"int",$X3)
    DllCall("user32.dll","int","SetWindowRgn","hwnd",$handle,"int",$l[0],"int",True)
EndFunc
Func startbmp($iWidth, $iHeight)
    ;Create a new bitmap, this way the original opened png is left unchanged
     $hBitmap = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle($GUI))
    $hImage =  _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hBitmap)
    _WinAPI_DeleteObject($hBitmap)
    Return $hImage
EndFunc

func _addlabel($hBitmap, $string,$posedw, $posedh, $iWidth,$colour1, $font="Arial", $size="13",$style=0)
    ;$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $fcolour=StringReplace($colour1, "0x", "0xFF")
    $hBrush = _GDIPlus_BrushCreateSolid ($fcolour)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ($font)
    $hFont = _GDIPlus_FontCreate ($hFamily, $size, $style)
    $tLayout = _GDIPlus_RectFCreate ($posedw, $posedh, $iWidth, 40)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $string, $hFont, $tLayout, $hFormat)
    if not $string="" then _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string, $hFont, $aInfo[0], $hFormat, $hBrush)
        _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    return $hBitmap
endfunc; SetIcon


Func _createbutton($bitmap,$picwidth,$picheight,$corner,$iClr1, $iClr2, $iClr3, $iDirection,$text="",$sIcon="", $iIndex="")
    local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0]
    $picwidth=$picwidth-2
    $picheight=$picheight-2
    local $bGammaCorrection = False
        $iC1 = StringReplace($iClr1, "0x", "0xFF")
    $iC2 = StringReplace($iClr2, "0x", "0xFF")
    $iC3 = StringReplace($iClr3, "0x", "0xFF")

$hGraphics = _GDIPlus_ImageGetGraphicsContext($bitmap)

_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
 Global $hBrush1 = _GDIPlus_BrushCreateSolid($iC3)
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $picwidth, $picheight, $aFactors, $aPositions, $iC1, $iC2, $iDirection)
    GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $picwidth+2, $picheight+2, $corner, $hBrush1)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 2, 2, $picwidth-2, $picheight-2, $corner,$hBrushLin)
$lef=5
    if not $sIcon="" Then
        $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
        $hIcon = _WinAPI_SHExtractIcons($sIcon, $iIndex, 32, 32)

        $hDC = _WinAPI_GetDC(0)
        $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
        ;$hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight)
        $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
        If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, 10, $picheight/2-15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
             $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
             $hGraphics = _GDIPlus_ImageGetGraphicsContext($bitmap)
             $lef=40
    EndIf
_GDIPlus_GraphicsDrawImageRect($hGraphics, $bitmap, 0, 0, $picwidth, $picheight)
if not $text="" then _GDIPlus_GraphicsDrawString($hGraphics,$text,$lef, $picheight/2-8,"Arial","11")

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BrushDispose($hBrushLin)

        _GDIPlus_BrushDispose($hBrush1)

    if $sIcon="" Then Return $bitmap
 _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    return $bitmap
EndFunc
Func _WinAPI_SHExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc   ;==>_WinAPI_SHExtractIcons
func _drawborder($hBitmap,$gwt,$ght,$depth,$colour1,$colour2,$corner)
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid(0xFF993333)

    Local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0]
    Local $bGammaCorrection = False
    $hBrush1 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt,$ght, $aFactors, $aPositions, "0xFF999999", "0xFF111111", 3)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush1 = _GDIPlus_BrushCreateSolid($iC2)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt,$ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt-($depth*2)-2, $ght-($depth*2)-2, $corner,$hBrush1)
        _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $depth, $depth, $gwt,$ght, $corner,$hBrush2)
        _GDIPlus_GraphicsDrawRoundRect3($hGraphics, $depth, $depth, $gwt,$ght, $corner,$hBrush)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_BrushDispose($hBrush1)
        _GDIPlus_BrushDispose($hBrush2)
         _GDIPlus_GraphicsDispose($hGraphics)
return $hBitmap
EndFunc

func _drawborder2($hBitmap,$gwt,$ght,$depth,$colour1,$colour2,$corner)
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid(0xFF993333)

    Local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0]
    Local $bGammaCorrection = False
    $hBrush1 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt,$ght, $aFactors, $aPositions, "0xFFFFFFFF", "0xFFBBBBBB", 3)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush1 = _GDIPlus_BrushCreateSolid($iC2)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt,$ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt-($depth*2)-2, $ght-($depth*2)-2, $corner,$hBrush1)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_BrushDispose($hBrush1)
        _GDIPlus_BrushDispose($hBrush2)
         _GDIPlus_GraphicsDispose($hGraphics)
return $hBitmap
EndFunc

Func finalizectrl($controlID,$hImage)
    $hWnd = GUICtrlGetHandle($controlID)
            $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
     $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", 0x0172, "int", 0, "int", $hbmp)
    If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0])
    _WinAPI_DeleteObject($hbmp)
EndFunc


func leftmouse() ;decide whether button being pressed or gui being dragged
    if clickexit()=1 then Exit 0
    if clicknext()=1 then
        window2()
        Return
    EndIf
    $hov=GUIGetCursorInfo($GUI)
    if $hov[4]<>$bckpic then Return
    If BitAND(WinGetState($GUI), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $GUI, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
EndFunc

Func clickexit()
    Local $PosDiff[2]
    $MousePos = MouseGetPos ()
    $WinPos = WinGetPos ($Gui,"")
    $PosDiff[0] = $WinPos[0] + $WinPos[2]
    $PosDiff[1] = $WinPos[1] + $WinPos[3]
if $mousePos[0]>$PosDiff[0]-37 and $mousePos[0]<$PosDiff[0]-7 and $mousePos[1]<$WinPos[1]+30 and $mousePos[1]>$WinPos[1]+2 Then return 1
     return 0
 EndFunc

Func clicknext()
    Local $PosDiff[2]
    $MousePos = MouseGetPos ()
    $WinPos = WinGetPos ($Gui,"")
    $PosDiff[0] = $WinPos[0] + $WinPos[2]
    $PosDiff[1] = $WinPos[1] + $WinPos[3]
;   ConsoleWrite($mousePos[0]&" "&$PosDiff[0]&" "&$mousePos[1]&" "&$PosDiff[1]&@CRLF)
if $mousePos[0]>$PosDiff[0]-62 and $mousePos[0]<$PosDiff[0]-16 and $mousePos[1]<$PosDiff[1]-12 and $mousePos[1]>$PosDiff[1]-34 Then return 1
     return 0
 EndFunc

;==== GDIPlus_CreateLineBrushFromRect === Malkey's function
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

    If $iArgb1 = Default Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = Default Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Or $LinearGradientMode = Default Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Or $LinearGradientMode = Default Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]
    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next
    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>_GDIPlus_CreateLineBrushFromRect

Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection)
    Return $aResult[0]
EndFunc   ;==>GDIPlus_SetLineGammaCorrection

Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - ($iRadius * 2), $iY)
     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)

    ;Draw the font onto the new bitmap
    _GDIPlus_GraphicsPathCloseFigure($hPath)
    If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)
    _GDIPlus_GraphicsPathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
EndFunc

Func _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    $leftit=$iWidth-31
    $downit=5
    _GDIPlus_GraphicsPathAddArc($hPath, $leftit-3, $downit-3, 22,22,0, 360) ; this is the circle around the X
    ;;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X
        _GDIPlus_GraphicsPathAddLine($hPath,  $leftit+2, $downit, $leftit+2,$downit)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit+8, $downit+6,$leftit+14,$downit)
        _GDIPlus_GraphicsPathAddLine($hPath,$leftit+16, $downit+2,$leftit+10,$downit+8)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit+16,$downit+14,$leftit+14,$downit+16)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit+8,$downit+10,$leftit+2,$downit+16)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit, $downit+14,$leftit+6 ,$downit+8)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit, $downit+2,$leftit, $downit+2)
      ;  _GDIPlus_GraphicsPathAddLine($hPath, $leftit ,$downit,$iWidth - ($iRadius * 2), $iY)
        ;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X ends
    ;Draw the font onto the new bitmap
    _GDIPlus_GraphicsPathCloseFigure($hPath)
    If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)
    _GDIPlus_GraphicsPathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
EndFunc
Func _GDIPlus_GraphicsDrawRoundRect3($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    $leftit=$iWidth-52
    $downit=$iHeight-33
    ;;;;;;;;;;;;;;;;;;;;;;;;;;Script for the arrow
        _GDIPlus_GraphicsPathAddLine($hPath,  $leftit+42, $downit+12, $leftit+29,$downit+23)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit+29, $downit+19,$leftit,$downit+19)
        _GDIPlus_GraphicsPathAddLine($hPath,$leftit, $downit+6,$leftit+29,$downit+6)
        _GDIPlus_GraphicsPathAddLine($hPath, $leftit+29,$downit+2,$leftit+29,$downit+2)

      ;  _GDIPlus_GraphicsPathAddLine($hPath, $leftit ,$downit,$iWidth - ($iRadius * 2), $iY)
        ;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X ends
    ;Draw the font onto the new bitmap
    _GDIPlus_GraphicsPathCloseFigure($hPath)
    If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)
    _GDIPlus_GraphicsPathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
EndFunc

Func _GDIPlus_GraphicsPathCreate($iFillMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", $iFillMode, "int*", 0);
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[2])
EndFunc
Func _GDIPlus_GraphicsPathAddLine($hGraphicsPath, $iX1, $iY1, $iX2, $iY2)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathLine", "hwnd", $hGraphicsPath, "float", $iX1, "float", $iY1, _
                                "float", $iX2, "float", $iY2)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc
Func _GDIPlus_GraphicsPathAddArc($hGraphicsPath, $iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathArc", "hwnd", $hGraphicsPath, "float", $iX, "float", $iY, _
                                "float", $iWidth, "float", $iHeight, "float", $iStartAngle, "float", $iSweepAngle)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc
Func _GDIPlus_GraphicsPathCloseFigure($hGraphicsPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "hwnd", $hGraphicsPath)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc
Func _GDIPlus_GraphicsPathDispose($hGraphicsPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipDeletePath", "hwnd", $hGraphicsPath)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc
Func _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hGraphicsPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawPath", "hwnd", $hGraphics, "hwnd", $hPen, "hwnd", $hGraphicsPath)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc
Func _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hGraphicsPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "hwnd", $hGraphics, "hwnd", $hBrush, "hwnd", $hGraphicsPath)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, 0)
EndFunc

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long",  $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3,  "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc ;==>_GuiRoundCorners

;$iColor - Colour to be made transparent. Hex colour format 0xRRGGBB. If Default used then top left pixel colour of image
; is used as the transparent colour.
Func ImageColorToTransparent($hImage2, $iStartPosX = 0, $iStartPosY = 0, $GuiSizeX = Default, $GuiSizeY = Default, $iColor = Default)
    Local $hBitmap1, $Reslt, $width, $height, $stride, $format, $Scan0, $v_Buffer, $v_Value, $iIW, $iIH
    $iIW = _GDIPlus_ImageGetWidth($hImage2)
    $iIH = _GDIPlus_ImageGetHeight($hImage2)
    If $GuiSizeX = Default Or $GuiSizeX > $iIW - $iStartPosX Then $GuiSizeX = $iIW - $iStartPosX
    If $GuiSizeY = Default Or $GuiSizeY > $iIH - $iStartPosY Then $GuiSizeY = $iIH - $iStartPosY
    $hBitmap1 = _GDIPlus_BitmapCloneArea($hImage2, $iStartPosX, $iStartPosY, $GuiSizeX, $GuiSizeY, $GDIP_PXF32ARGB)
    If $iColor = Default Then $iColor = GDIPlus_BitmapGetPixel($hBitmap1, 1, 1); Transparent color
    $Reslt = _GDIPlus_BitmapLockBits($hBitmap1, 0, 0, $GuiSizeX, $GuiSizeY, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
;Get the returned values of _GDIPlus_BitmapLockBits ()
    $width = DllStructGetData($Reslt, "width")
    $height = DllStructGetData($Reslt, "height")
    $stride = DllStructGetData($Reslt, "stride")
    $format = DllStructGetData($Reslt, "format")
    $Scan0 = DllStructGetData($Reslt, "Scan0")
    For $i = 0 To $GuiSizeX - 1
        For $j = 0 To $GuiSizeY - 1
            $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4))
            $v_Value = DllStructGetData($v_Buffer, 1)
            If Hex($v_Value, 6) = Hex($iColor, 6) Then
                DllStructSetData($v_Buffer, 1, Hex($iColor, 6)); Sets Transparency here. Alpha Channel = 00, not written to.
            EndIf
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt)
    Return $hBitmap1
EndFunc  ;==>ImageColorToTransparent

;The GetPixel method gets the color of a specified pixel in this bitmap.
Func GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return "0x" & Hex(DllStructGetData($tArgb, "Argb"))
EndFunc  ;==>GDIPlus_BitmapGetPixel



func Setbutton($controlID, $iWidth, $iHeight,$string="", $hovered=0,$leavealone=0)
    Local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0]
    Local $bGammaCorrection = False, $iDirection=1, $pressed=1
   const $STM_SETIMAGE = 0x0172
    $tIcon = DllStructCreate('hwnd')
    $tID = DllStructCreate('hwnd')
if $leavealone=0 then
    $picnames[0][0]=$picnames[0][0]+1
    $picnames[$picnames[0][0]][0]=$controlID
    $picnames[$picnames[0][0]][1]=$string
    $picnames[$picnames[0][0]][2]=$iWidth
    $picnames[$picnames[0][0]][3]=$iHeight
    redim $picnames[UBound($picnames)+1][4]
EndIf
if $hovered=0 then
    Local $fname="Arial", $fsize=14,$fstyle=0, $fcolour=0xFFCECDB4
    local $iClr1="0xAA8866", $iClr2="0x441100"
    local $posedh=0,$posedw=0
Elseif  $hovered=1 then
    Local $fname="Verdana", $fsize=14,$fstyle=0, $fcolour=0xFFCECDB4
    local $iClr1="0x331111", $iClr2="0x662200"
    local $posedh=1,$posedw=1

Elseif  $hovered=2 then
    Local $fname="Arial", $fsize=14,$fstyle=0, $fcolour=0xFFFFFFFF
    local $posedh=1,$posedw=1
    local $iClr1="0xAA8866", $iClr2="0x441100"
EndIf
     _GDIPlus_Startup()
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $iC1, $iC2, $hBitmap, $hImage, $hGraphic, $hBrushLin, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($controlID)
    $iC1 = StringReplace($iClr1, "0x", "0xFF")
    $iC2 = StringReplace($iClr2, "0x", "0xFF")
    $hBitmap = _WinAPI_CreateBitmap($iWidth, $iHeight, 1, 32)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $iWidth, $iHeight, $aFactors, $aPositions, $iC1, $iC2, $iDirection)
    GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0+$pressed, 0+$pressed, $iWidth-$pressed*2, $iHeight-$pressed*2, $hBrushLin)
        $hBrush = _GDIPlus_BrushCreateSolid ($fcolour)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ($fname)
    $hFont = _GDIPlus_FontCreate ($hFamily, $fsize, $fstyle)
    $tLayout = _GDIPlus_RectFCreate ($posedw, $posedh, $iWidth, $iHeight)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $string, $hFont, $tLayout, $hFormat)
    if not $string="" then _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string, $hFont, $aInfo[0], $hFormat, $hBrush)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

     $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrushLin)
        _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
;   _WinAPI_DeleteObject($hbmp)
    _GDIPlus_Shutdown()
_WinAPI_DeleteObject($hBitmap)
    return SetError(0, 0, 1)
endfunc; SetIcon

;---------------------------
; FUNCTIONS
;---------------------------
Func _SetClipCircle($hGraphics, $x, $y, $width, $height)
   
    ;Create struct to hold pointer to Path object
    $Path = DllStructCreate("dword")
   
    ;Create Path object, store pointer to it
    DllCall($ghGDIPDll, "none", "GdipCreatePath", "int", 0, "int", DllStructGetPtr($Path))
   
    ;Retrieve pointer from struct
    $pointer = DllStructGetData($Path,1)
   
    DllCall($ghGDIPDll, "none", "GdipAddPathEllipseI","int", $pointer,"int",$x,"int",$y,"int",$width,"int",$height)
   
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetClipPath", "hwnd", $hGraphics, "ptr", $pointer,"int",0)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Func _AntiAlias($hGraphics)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", 2)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Func _SetRoundedRectClip($g,$x,$y,$w,$h,$r)
   $Path = DllStructCreate("dword")
   DllCall($ghGDIPDll, "none", "GdipCreatePath", "int", 0, "int", DllStructGetPtr($Path))
   $pointer = DllStructGetData($Path,1)
   DllCall($ghGDIPDll, "none", "GdipAddPathArc","int", $pointer,"float",$x,"float",$y,"float",$r,"float",$r,"float",180,"float",90)
   DllCall($ghGDIPDll, "none", "GdipAddPathArc","int", $pointer,"float",$x+($w - $r - 1),"float",$y,"float",$r,"float",$r,"float",270,"float",90)
   DllCall($ghGDIPDll, "none", "GdipAddPathArc","int", $pointer,"float",$x+($w - $r - 1),"float",$y+($h - $r - 1),"float",$r,"float",$r,"float",0,"float",90)
   DllCall($ghGDIPDll, "none", "GdipAddPathArc","int", $pointer,"float",$x,"float",$y+($h - $r - 1),"float",$r,"float",$r,"float",90,"float",90)
   $aResult = DllCall($ghGDIPDll, "int", "GdipSetClipPath", "hwnd", $g, "ptr", $pointer,"int",0)
EndFunc
Edited by picea892

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