Sign in to follow this  
Followers 0
picea892

Custom Button shapes and effects

17 posts in this topic

#1 ·  Posted (edited)

Last updated: January 2, 2009

Made fixes to memory usage and demonstration of other buttons and a gui background.

This script will allow you to make custom shape, size and text guictrl buttons easily. I attempted to make it as straightforward as possible. Since it is buttons I am working with I made an example using Mr. Creator's hover udf. Please download the two UDFs and try the example below.

Enjoy

Picea892

Instructions: One line changes are all that are needed. To minimize complexity (there is a long line of parameters I could add) I attempted to keep the parameters short and each style specializes in a specific task:

Any one of these styles can be expanded as a background to a GUI or a background to Text. I have demonstrated both of these as well.

DEMONSTRATION 1

#include <GUIConstantsEx.au3>
#include <GUICtrlSetOnHover_UDF.au3>
#include <shapedcontrols_udf.au3>

Global $gradient1[4],$gradient2[4],$gradient1b[4],$tabs1[4],$iconbutton_1[5],$iconavg[4],$round[4], $letters[5],$topbar[4],$topbar2[4],$topbar3[4],$2ndbckground

Global $PlayIsClicked   = False

$Gui = GUICreate("Buttons All Shapes and Sizes", 560,600)
  Global $bckpic= GUICtrlCreatePic("",0,0,560, 600)
     GuiCtrlSetState(-1,$GUI_DISABLE)
    createbutton_3(-1,"0xDDDDDD","0x555555","")
$2ndbckground= GUICtrlCreatePic("", 2, 540,556, 60)
        topbar2(-1,1,0,"0x220000","0xAA0000","0x000000","")
        GuiCtrlSetState(-1,$GUI_DISABLE)
$goingleft=50
for $i=0 to 3
        $tabs1[$i] = GUICtrlCreatePic("", $goingleft-25, 15,100, 40)
        createtab_1(-1,"0x999999","0x000000","0x222222","Tab"&$i,"","","","",2)
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

        $goingleft=$goingleft+100
    Next
    
            $topbar[0] = GUICtrlCreatePic("", 21, 65,80, 40)
        topbar2(-1,1,1,"0x66FF66","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        
        $topbar2[0] = GUICtrlCreatePic("", 21, 115,80, 40)
        topbar2(-1,0,1,"0x33BB33","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $topbar3[0] = GUICtrlCreatePic("", 21, 165,80, 40)
        topbar3(-1,1,1,"0x33BB33","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
$goingleft=99
for $i=1 to 2       
        $topbar[$i] = GUICtrlCreatePic("", $goingleft, 65,80, 40)
        topbar2(-1,1,0,"0x001100","0x66FF66","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $topbar2[$i] = GUICtrlCreatePic("", $goingleft, 115,80, 40)
        topbar2(-1,0,0,"0x001100","0x33BB33","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $topbar3[$i] = GUICtrlCreatePic("", $goingleft, 165,80, 40)
        topbar3(-1,1,0,"0x001100","0x33BB33","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $goingleft=$goingleft+78
Next
        $topbar[3] = GUICtrlCreatePic("", 255, 65,80, 40)
        topbar2(-1,1,2,"0x66FF66","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
                $topbar2[3] = GUICtrlCreatePic("", 255, 115,80, 40)
        topbar2(-1,0,2,"0x33BB33","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
                $topbar3[3] = GUICtrlCreatePic("", 255, 165,80, 40)
        topbar3(-1,1,2,"0x33BB33","0x001100","0x002200","Style #2b")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
$goingdownorleft=180
for $i=0 to 3
    $gradient1[$i] = GUICtrlCreatePic("", 470, $goingdownorleft+105,75, 40)
    createbutton_3c(-1,"0xFFFFFF","0x111111","0x555555","Grad1", "Arial","12","0","0x8984CD")
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
    $gradient1b[$i] = GUICtrlCreatePic("", 320, $goingdownorleft+105,125, 40)
    createbutton_3c(-1,"0xA9C9A4","0x484D46","0x9BCD9B","Gradient1b", "Arial","12","0","0xC1CDC1",0,"C:\WINDOWS\system32\shell32.dll",215+$i)
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

    $gradient2[$i] = GUICtrlCreatePic("", 470, $goingdownorleft-115,80, 40)
    createbutton_3(-1,"0x0000DD","0x000022","0x000000","Grad2", "Arial","12","0","0x1874CD")
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

            $round[$i] = GUICtrlCreatePic("", $goingdownorleft+150, 490,32, 32)
        createbutton_3(-1,"0x999999","0x000000","0x222222","")
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $goingdownorleft=$goingdownorleft+50
Next

    $iconavg[0] = GUICtrlCreatePic("", 350, 65,100, 40)
    iconavg(-1,"Style #3", "C:\WINDOWS\system32\shell32.dll",215,0)
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
    $iconavg[1] = GUICtrlCreatePic("", 350, 115,100, 40)
    iconavg(-1,"Style #3", "C:\Program Files\Internet Explorer\iexplore.exe",0,0)
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")   
    $iconavg[2] = GUICtrlCreatePic("", 350, 165,100, 40)
    iconavg(-1,"Style #3", "C:\WINDOWS\system32\shell32.dll",87,0)
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")



;;;;;;;;;letters;;;;;;;;;;;;
$goleft=10
    for $i=0 to 4
        $iconbutton_1[$i] = GUICtrlCreatePic("", $goleft, 410,34,34)
        _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        iconbutton_1($iconbutton_1[$i],"C:\WINDOWS\system32\shell32.dll",215,0)
            
    $letters[$i] = GUICtrlCreatePic("", $goleft, 470,80,80)
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
    $goleft=$goleft+60
    Next
    letterbutton_1($letters[0],"@", "Webdings","40","0","0x000000")
    letterbutton_1($letters[1],"r", "Webdings","40","0","0x000000")
    letterbutton_1($letters[2],"+", "Wingdings","40","0","0x000000")
    letterbutton_1($letters[3],"!", "Wingdings","40","0","0x000000")
    letterbutton_1($letters[4],"[", "Wingdings 3","40","0","0x000000")
    
    iconbutton_1($iconbutton_1[0],"C:\WINDOWS\system32\shell32.dll",215,0)
    iconbutton_1($iconbutton_1[1],"C:\WINDOWS\system32\shell32.dll",200,0)
    iconbutton_1($iconbutton_1[2],"C:\WINDOWS\system32\shell32.dll",3,0)
    iconbutton_1($iconbutton_1[3],"C:\WINDOWS\system32\shell32.dll",1,0)
    iconbutton_1($iconbutton_1[4],"C:\WINDOWS\system32\shell32.dll",197,0)

GUISetState()

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

WEnd

Func _Hover_Proc($iCtrlID)
    for $i=0 to 3
        if $iCtrlID=$gradient2[$i] then createbutton_3($gradient2[$i],"0xFFFFFF","0x111111","0x550000","Gradient #1")
        if $iCtrlID=$gradient1[$i] then createbutton_3c($gradient1[$i],"0x111111","0xFFFFFF","0x555555","Style #3", "Arial","12","0","0x1874CD")
        if $iCtrlID=$gradient1b[$i] then createbutton_3c($gradient1b[$i],"0x484D46","0xA9C9A4","0x9BCD9B","Gradient1b", "Arial","12","0","0x596C56",0,"C:\WINDOWS\system32\shell32.dll",215+$i)
        if $iCtrlID=$round[$i] then createbutton_3($round[$i],"0x33CC33","0x003300","0x555555","")
        if $iCtrlID=$tabs1[$i] then createtab_1($tabs1[$i],"0x444444","0x999999","0xAAAAAA","Tab"&$i,"","","","",2)
        if $iCtrlID=$gradient2[$i] then createbutton_3($gradient2[$i],"0x1B3F8B","000033","0x000000","Style #3", "Arial","13","1","0xA9ACB6")
    Next
        if $iCtrlID=$letters[0] then letterbutton_1($letters[0],"@", "Webdings","40","0","0x880000")
        if $iCtrlID=$letters[1] then letterbutton_1($letters[1],"r", "Webdings","40","0","0x880000")
        if $iCtrlID=$letters[2] then letterbutton_1($letters[2],"+", "Wingdings","40","0","0x880000")
        if $iCtrlID=$letters[3] then letterbutton_1($letters[3],"!", "Wingdings","40","0","0x880000")
        if $iCtrlID=$letters[4] then letterbutton_1($letters[4],"[", "Wingdings 3","40","0","0x880000") 
        
        
    if $iCtrlID=$iconbutton_1[0] then iconbutton_1($iconbutton_1[0],"C:\WINDOWS\system32\shell32.dll",215,1)
    if $iCtrlID=$iconbutton_1[1] then iconbutton_1($iconbutton_1[1],"C:\WINDOWS\system32\shell32.dll",200,1)
    if $iCtrlID=$iconbutton_1[2] then iconbutton_1($iconbutton_1[2],"C:\WINDOWS\system32\shell32.dll",3,1)
    if $iCtrlID=$iconbutton_1[3] then iconbutton_1($iconbutton_1[3],"C:\WINDOWS\system32\shell32.dll",1,1)
    if $iCtrlID=$iconbutton_1[4] then iconbutton_1($iconbutton_1[4],"C:\WINDOWS\system32\shell32.dll",197,1)
        
            if $iCtrlID=$iconavg[0] then iconavg($iconavg[0],"Style #3", "C:\WINDOWS\system32\shell32.dll",215,1)
        if $iCtrlID=$iconavg[1] then iconavg($iconavg[1],"Style #3", "C:\Program Files\Internet Explorer\iexplore.exe",0,1)
        if $iCtrlID=$iconavg[2] then iconavg($iconavg[2],"Style #3", "C:\WINDOWS\system32\shell32.dll",87,1)
        
    if $iCtrlID=$topbar[0] then topbar2($topbar[0],1,1,"0x77FF77","0x004400","0x002200","Style #2b")
    if $iCtrlID=$topbar[1] then topbar2($topbar[1],1,0,"0x004400","0x77FF77","0x002200","Style #2b")
    if $iCtrlID=$topbar[2] then topbar2($topbar[2],1,0,"0x004400","0x77FF77","0x002200","Style #2b")
    if $iCtrlID=$topbar[3] then topbar2($topbar[3],1,2,"0x77FF77","0x004400","0x002200","Style #2b")
        
    if $iCtrlID=$topbar2[0] then topbar2($topbar2[0],1,1,"0x001100","0x33BB33","0x002200","Style #2b")
    if $iCtrlID=$topbar2[1] then topbar2($topbar2[1],1,0,"0x001100","0x33BB33","0x002200","Style #2b")
    if $iCtrlID=$topbar2[2] then topbar2($topbar2[2],1,0,"0x33BB33","0x001100","0x002200","Style #2b")
    if $iCtrlID=$topbar2[3] then topbar2($topbar2[3],1,2,"0x33BB33","0x001100","0x002200","Style #2b")
    
            if $iCtrlID=$topbar3[0] then topbar3($topbar3[0],1,1,"0x006600","0x66BB66","0x002200","Style #2b")
        if $iCtrlID=$topbar3[1] then topbar3($topbar3[1],1,0,"0x66BB66","0x006600","0x002200","Style #2b")
        if $iCtrlID=$topbar3[2] then topbar3($topbar3[2],1,0,"0x66BB66","0x006600","0x002200","Style #2b")
        if $iCtrlID=$topbar3[3] then topbar3($topbar3[3],1,2,"0x006600","0x66BB66","0x002200","Style #2b")
            
            ; this section provides the text description on bottom
        if $iCtrlID=$tabs1[0] or $iCtrlID=$tabs1[1] or $iCtrlID=$tabs1[2] or $iCtrlID=$tabs1[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","An example of tabs, centered text, rounded top corners")
        if $iCtrlID=$topbar[0] or $iCtrlID=$topbar[1] or $iCtrlID=$topbar[2] or $iCtrlID=$topbar[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Centered text, rounded corners only on sides of series")
        if $iCtrlID=$topbar2[0] or $iCtrlID=$topbar2[1] or $iCtrlID=$topbar2[2] or $iCtrlID=$topbar2[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Centered text, Another topbar style")
        if $iCtrlID=$topbar3[0] or $iCtrlID=$topbar3[1] or $iCtrlID=$topbar3[2] or $iCtrlID=$topbar3[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Centered text, And yet another topbar style")
        if $iCtrlID=$iconavg[0] or $iCtrlID=$iconavg[1] or $iCtrlID=$iconavg[2] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","The average icon colour is used for background and inverse for font colour")
        if $iCtrlID=$gradient2[0] or $iCtrlID=$gradient2[1] or $iCtrlID=$gradient2[2] or $iCtrlID=$gradient2[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Standard gradient, rounded corners")
        if $iCtrlID=$gradient1[0] or $iCtrlID=$gradient1[1] or $iCtrlID=$gradient1[2] or $iCtrlID=$gradient1[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","2 side by side standard gradients, rounded corners")
        if $iCtrlID=$gradient1b[0] or $iCtrlID=$gradient1b[1] or $iCtrlID=$gradient1b[2] or $iCtrlID=$gradient1b[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","2 side by side standard gradients, rounded corners, with icon")
if $iCtrlID=$iconbutton_1[0] or $iCtrlID=$iconbutton_1[1] or $iCtrlID=$iconbutton_1[2] or $iCtrlID=$iconbutton_1[3]or $iCtrlID=$iconbutton_1[4] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","This is a guictrl, it is not a seperate gui or drawn on background")
        if $iCtrlID=$letters[0] or $iCtrlID=$letters[1] or $iCtrlID=$letters[2] or $iCtrlID=$letters[3] or $iCtrlID=$letters[4] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Wingding or Webding font clickable guictrls even where see-through")   
        if $iCtrlID=$round[0] or $iCtrlID=$round[1] or $iCtrlID=$round[2] or $iCtrlID=$round[3] then topbar2($2ndbckground,1,0,"0x220000","0xAA0000","0x000000","Round buttons")    
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
    for $i=0 to 3
        if $iCtrlID=$gradient2[$i] then createbutton_3($gradient2[$i],"0xFFFFFF","0x111111","0x555555","Style #1")
                if $iCtrlID=$gradient1[$i] then createbutton_3c($gradient1[$i],"0xFFFFFF","0x111111","0x555555","Style #3", "Arial","12","0","0x1874CD")
                if $iCtrlID=$gradient1b[$i] then createbutton_3c($gradient1b[$i],"0xA9C9A4","0x484D46","0x9BCD9B","Gradient1b", "Arial","12","0","0xC1CDC1",0,"C:\WINDOWS\system32\shell32.dll",215+$i)
        if $iCtrlID=$round[$i] then createbutton_3($round[$i],"0x999999","0x000000","0x222222","")
        
        if $iCtrlID=$tabs1[$i] then createtab_1($tabs1[$i],"0x999999","0x000000","0x222222","Tab"&$i,"","","","",2)
        if $iCtrlID=$gradient2[$i] then createbutton_3($gradient2[$i],"0x0000DD","0x000022","0x000000","Style #3", "Arial","12","0","0x1874CD") 
            

        Next
        
        if $iCtrlID=$letters[0] then letterbutton_1($letters[0],"@", "Webdings","40","0","0x000000")
        if $iCtrlID=$letters[1] then letterbutton_1($letters[1],"r", "Webdings","40","0","0x000000")
        if $iCtrlID=$letters[2] then letterbutton_1($letters[2],"+", "Wingdings","40","0","0x000000")
        if $iCtrlID=$letters[3] then letterbutton_1($letters[3],"!", "Wingdings","40","0","0x000000")
        if $iCtrlID=$letters[4] then letterbutton_1($letters[4],"[", "Wingdings 3","40","0","0x000000")
    if $iCtrlID=$iconbutton_1[0] then iconbutton_1($iconbutton_1[0],"C:\WINDOWS\system32\shell32.dll",215,0)
    if $iCtrlID=$iconbutton_1[1] then iconbutton_1($iconbutton_1[1],"C:\WINDOWS\system32\shell32.dll",200,0)
    if $iCtrlID=$iconbutton_1[2] then iconbutton_1($iconbutton_1[2],"C:\WINDOWS\system32\shell32.dll",3,0)
    if $iCtrlID=$iconbutton_1[3] then iconbutton_1($iconbutton_1[3],"C:\WINDOWS\system32\shell32.dll",1,0)
    if $iCtrlID=$iconbutton_1[4] then iconbutton_1($iconbutton_1[4],"C:\WINDOWS\system32\shell32.dll",197,0)
    
        if $iCtrlID=$iconavg[0] then iconavg($iconavg[0],"Style #3", "C:\WINDOWS\system32\shell32.dll",215,0)
        if $iCtrlID=$iconavg[1] then iconavg($iconavg[1],"Style #3", "C:\Program Files\Internet Explorer\iexplore.exe",0,0)
        if $iCtrlID=$iconavg[2] then iconavg($iconavg[2],"Style #3", "C:\WINDOWS\system32\shell32.dll",87,0)

        
        if $iCtrlID=$topbar[0] then topbar2($topbar[0],1,1,"0x66FF66","0x001100","0x002200","Style #2b")
        if $iCtrlID=$topbar[1] then topbar2($topbar[1],1,0,"0x001100","0x66FF66","0x002200","Style #2b")
        if $iCtrlID=$topbar[2] then topbar2($topbar[2],1,0,"0x001100","0x66FF66","0x002200","Style #2b")
        if $iCtrlID=$topbar[3] then topbar2($topbar[3],1,2,"0x66FF66","0x001100","0x002200","Style #2b")
        
    if $iCtrlID=$topbar2[0] then topbar2($topbar2[0],0,1,"0x33BB33","0x001100","0x002200","Style #2b")
    if $iCtrlID=$topbar2[1] then topbar2($topbar2[1],0,0,"0x33BB33","0x001100","0x002200","Style #2b")
    if $iCtrlID=$topbar2[2] then topbar2($topbar2[2],0,0,"0x33BB33","0x001100","0x002200","Style #2b")
    if $iCtrlID=$topbar2[3] then topbar2($topbar2[3],0,2,"0x33BB33","0x001100","0x002200","Style #2b")
        
        if $iCtrlID=$topbar3[0] then topbar3($topbar3[0],1,1,"0x33BB33","0x001100","0x002200","Style #2b")
        if $iCtrlID=$topbar3[1] then topbar3($topbar3[1],1,0,"0x001100","0x33BB33","0x002200","Style #2b")
        if $iCtrlID=$topbar3[2] then topbar3($topbar3[2],1,0,"0x001100","0x33BB33","0x002200","Style #2b")
        if $iCtrlID=$topbar3[3] then topbar3($topbar3[3],1,2,"0x33BB33","0x001100","0x002200","Style #2b")
EndFunc

Func PrimaryDown_Proc($iCtrlID)
EndFunc

Func PrimaryUp_Proc($iCtrlID)
EndFunc
;createtab_1($tabbed,"0x444444","0x999999","0xBBBBBB")

DEMONSTRATION 2

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <StaticConstants.au3>
#Include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUICtrlSetOnHover_UDF.au3>
#include <shapedcontrols_udf.au3>
Opt("GUIOnEventMode",1)
Global $gradient1, $exited=0,$tabs1[4], $title,$Gui,$bckpic,$2ndbckground,$iCtrlID,$DummyStart,$DummyEnd,$closebut
Global $PlayIsClicked   = False
Global $bckpiccal
commonbck()

import()

Func commonbck()
    $Gui = GUICreate("FMP Calendar", 460,400,-1,-1, BitOR($WS_CLIPSIBLINGS,$WS_POPUP))
    GUISetBkColor("0xABCDEF")
    $bckpic= GUICtrlCreatePic("",0,25,460, 265)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1,"0xCCCCCC","0x222222","0x111111")
    
            $bckpiccal= GUICtrlCreatePic("",0,300,460, 100)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1,"0xCCCCCC","0x222222","0x111111")
    
    GUISetControlsVisible($Gui)
    $2ndbckground= GUICtrlCreatePic("", 3, 60,230, 4)
        topbar2(-1,1,0,"0x220000","0xAA0000","0x000000","")
        GuiCtrlSetState(-1,$GUI_DISABLE)
    $closebut = GUICtrlCreatePic("", 425, 30,38, 38)
    closebutton(-1,"0x550000")
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
        $title=GUICtrlCreateLabel("Schedules",10,30,400,30)
    GUICtrlSetFont(-1,20,400,1,"Verdana")
    GUICtrlSetColor(-1,"0x000022")
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $gradient1 = GUICtrlCreatePic("", 395, 250,52, 30)
    createbutton_3c(-1,"0x84BE6A","0x002200","0x333333","Next", "Arial","12","0","0xBCED91")
    _GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")
    
EndFunc


GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
    
GUISetState()

While 1
sleep(100)
if $exited=1 then Exit 0
WEnd

Func _Hover_Proc($iCtrlID)
        if $iCtrlID=$gradient1 then createbutton_3c($gradient1,"0x005500","0x84BE6A","0x333333","Next", "Arial","12","0","0x000000")
        if $iCtrlID=$closebut then  closebutton($closebut,"0xCC0000")
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
        if $iCtrlID=$gradient1 then createbutton_3c($gradient1,"0x84BE6A","0x002200","0x333333","Next", "Arial","12","0","0xBCED91")
        if $iCtrlID=$closebut then  closebutton($closebut,"0x550000")
EndFunc

Func PrimaryDown_Proc($iCtrlID)
    if $iCtrlID=$closebut then $exited=1
EndFunc

Func PrimaryUp_Proc($iCtrlID)
    if $iCtrlID=$tabs1[0] then
    ;   GUIDelete($Gui)
    ;   commonbck()
    _Clear()
        import()

        GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
    elseif $iCtrlID=$tabs1[1] then
    ;   GUIDelete($Gui)
    ;   commonbck()
    _Clear()
        export()

        GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
    EndIf
EndFunc
;createtab_1($tabbed,"0x444444","0x999999","0xBBBBBB")

func leftmouse()
    $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 _Clear()
    Local $iCtl
    For $iCtl = $DummyStart To $DummyEnd
        GUICtrlDelete($iCtl)
    Next
EndFunc   ;==>_Clear

func export()
    $DummyStart = GUICtrlCreateDummy()


        $DummyEnd = GUICtrlCreateDummy()
EndFunc
    
func import()
    $DummyStart = GUICtrlCreateDummy()


    $DummyEnd = GUICtrlCreateDummy()
EndFunc

Func uNMask ($hWnd)
    Local $cp = WinGetPos($hWnd)
    Local $rgn = _WinAPI_CreateRectRgn (0, 0, $cp[2], $cp[3])
    _WinAPI_SetWindowRgn ($hWnd, $rgn)
EndFunc   ;==>uNMask

; $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)

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", "CreateRoundRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2]+1, _
            "long", $aCtrlPos[1] + $aCtrlPos[3]+1, "long", 25, "long", 25)
        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

Demonstration 3 (Self contained does not require any udfs)

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <StaticConstants.au3>
#Include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WINAPI.au3>

#include <GDIPlus.au3>
Opt("GUIOnEventMode",1)
Global $gradient1, $exited=0,$tabs1[4], $title,$Gui,$bckpic,$closebut
Global $setflag=0
Global $bckpiccal
commonbck()

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
GUISetState()

Func commonbck()
    $Gui = GUICreate("Options", 400,300,-1,-1, BitOR($WS_CLIPSIBLINGS,$WS_POPUP),$WS_EX_LAYERED)
    GUISetBkColor(0xABCDEF)
    $bckpic= GUICtrlCreatePic("",0,0,400, 160)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1)
    $closebut = GUICtrlCreatePic("", 361,6,38, 38)
    closebutton(-1,"0x550000")
        $title=GUICtrlCreateLabel("Options",18,4,100,30)
    GUICtrlSetFont(-1,20,400,1,"Verdana")
    GUICtrlSetColor(-1,"0x000022")
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
       _WinAPI_SetLayeredWindowAttributes($Gui, 0xABCDEF)
    GUISetState()
EndFunc

While 1
sleep(100)
hover()
WEnd

func hover()
    $hov=GUIGetCursorInfo($Gui)
    if $hov[4]<>$bckpic and $hov[4]<>0 then 
        if $hov[4]= $closebut and $setflag<>1 then
            closebutton($closebut,"0xCC0000")
            $setflag=1
        EndIf
    Else
        if $setflag=1 then
            closebutton($closebut,"0x550000")
            $setflag=0
        EndIf
    EndIf
EndFunc

func leftmouse()
    $hov=GUIGetCursorInfo($Gui)
    if $hov[4]<>$bckpic and $hov[4]<>0 then 
        if $hov[4]= $closebut then Exit 0
    Return
    EndIf
    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 background($control)
    _GDIPlus_Startup ()
    $hwd=GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width=_WinAPI_GetClientWidth($hwd)
    $height=_WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic)
    $hBitmap1=_drawborder($hBitmap1,"9","20",3)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
     _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_ImageDispose ($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
EndFunc 

;handler, to draw background and createbutton3
Func _drawborder($hBitmap, $depth, $corner, $slanty = 3) ;this is for normal buttons
    $gwt = _GDIPlus_ImageGetWidth($hBitmap)
    $ght = _GDIPlus_ImageGetHeight($hBitmap)
    $iC1 = "0xFF000000"
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $bGammaCorrection = False
         Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, $corner, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
Local $f = StringSplit('0x111111|0x222222|0x333333|0x444444|0x555555|0x666666|0x777777|0x888888|0x999999', '|')
;Local $f = StringSplit('0xEEEEEE|0xDDDDDD|0xCCCCCC|0xBBBBBB|0xAAAAAA|0x999999|0x888888|0x777777|0x666666|0x555555', '|')
For $i=0 To $depth
    $iC1 = StringReplace($f[$i], "0x", "0xFF")
     Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
     GDIPlus_SetLineGammaCorrection($hBrush, $bGammaCorrection)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $i, $i, $gwt-($i*2), $ght-($i*2), $corner, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
Next
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder

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 ;==>_GDIPlus_GraphicsDrawRoundRect

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

func closebutton($control,$col1)
    _GDIPlus_Startup ()
    $hwd=GUICtrlGetHandle($control)
    $width=_WinAPI_GetClientWidth($hwd)
    $height=_WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic)
            $iC1 = StringReplace($col1, "0x", "0xFF")
            $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
            Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
            _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
            _GDIPlus_GraphicsDrawclose($hGraphics, 0, 0, $width,$height, $hBrush)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_GraphicsDispose($hGraphics)
            ;;;;;;;;;;;
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
     _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_ImageDispose ($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_GraphicsDispose ($hGraphics)
    _GDIPlus_Shutdown ()
EndFunc

Func _GDIPlus_GraphicsDrawclose($hGraphics, $iX, $iY, $iWidth, $iHeight, $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)
    Return $hGraphics
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 ;==>_GDIPlus_GraphicsPathCreate
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 ;==>_GDIPlus_GraphicsPathAddLine
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 ;==>_GDIPlus_GraphicsPathAddArc
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 ;==>_GDIPlus_GraphicsPathCloseFigure
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 ;==>_GDIPlus_GraphicsPathDispose
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 ;==>_GDIPlus_GraphicsDrawPath
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 ;==>_GDIPlus_GraphicsFillPath

GUICtrlSetOnHover_UDF.au3

post-45064-12614278092999_thumb.jpg

shapedcontrols_udf.au3

post-45064-12624352569361_thumb.jpg

post-45064-0-64610100-1290804479_thumb.j

Edited by picea892

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nice. I love the look and the smoothness.

Your script seems to be more of an example of what can be done to make differently shaped buttons. A description of what is happening and what variables can be changed to get different effects would help new people adapt your code to fit their needs.

Great job.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks Dantay9

Yes it is more or a demonstration than anything else. I should look into writing a bit more of a description, maybe tomorrow.

I just moved over to a different computer and noticed that my GUI showed up but Mr. Creator's UDF does not seem to be registering button activity. Not sure if it's a xp/vista or Autoit version difference. Anyways...these should be 3 state buttons ;)

Edited by picea892

Share this post


Link to post
Share on other sites

Looks fine, but it's leaking everywhere.

You need to get rid of used gdi objects and bitmaps. Or it would explode eventually.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you Trancexx. Took another look through and found I was consistently not disposing of one object and also the icon. It's probably a bit of the hobbyist in me coming out. Anyways dealt with the $hIcon and $hBMP1 appropriately. Should be clean now, but I really do appreciate a second set of eyes for that kind of thing.

Blow-up.....boy that would be cool. Would I need sunglasses?

Picea892

Edited by picea892

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

Thanks Playlet

I was inspired partially by your launcher and by Funkey's own tabs. I think for me this is what the forum is all about. Showing of examples of what can be done which in turn inspires others to create. Over the next few months I plan to design other buttons and will include here. I'm hoping others will think this is a valuable project and contribute some of their own buttons. It's not too hard really but as Trancexx indicated, have to be careful to dispose of resources properly.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi everyone.

Well I think I'm officially tired of making buttons.....at least for now.

Many more examples included.

Various topbar series of buttons.

I figured out a way to shape the button when an icon is included and also demonstrated some extreme shaping using icons, wingdings, webdings etc.

Also, experimented with setting the background gradient using the average icon colour and the inverse colour for the font. This idea was based off a Melba23 example and many many Malkey examples too numerous to list here.

Suggestions welcome...but I'm on a much needed vacation, so may not be prompt in my response.

Picea892

Edited by picea892

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

It still seems to be sucking up memory. There is still a leak somewhere. Other than that, everything is working fine.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

The memory leak hasn't been completely patched, but the hole has gotten much smaller. I can't see where the rest of the memory is being lost so I will just post what I have.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <Color.au3>
;style is icon; text size, style and colour
;border is corners; border width; gradient

Func iconavg($control, $text = "", $sIcon = "", $iIndex = "", $hstate = 0, $font = "Arial", $size = 12, $style = 0)
    If Not $sIcon = "" Then
        _GDIPlus_Startup()
        If $font = "" Then $font = "Arial"
        If $size = "" Then $size = "12"
        If $style = "" Then $style = 0
        If $hstate = "" Then $hstate = 0
        $hwd = GUICtrlGetHandle($control)
        $width = _WinAPI_GetClientWidth($hwd)
        $height = _WinAPI_GetClientHeight($hwd)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
        $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
        $hBitmap1 = _drawicon2($hBitmap1, $width, $height, $sIcon, $iIndex, $hstate)
        If $hstate = 0 Then $fontcol = _InvertColor("0x" & $avgcol)
        If $hstate = 1 Or $hstate = 2 Then $fontcol = "0xDDDDDD"
        $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        ;this is needed because adding an icon results in the background turning black
        $hBitmap1 = _ImageColorRegExpReplace($hBitmap1, "(000000FF)", "FFFFFF00"); Change black to transparent
        If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, 0, 1)
        _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
        $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)

        _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))

        _GDIPlus_GraphicsDispose($hImage1)
        _WinAPI_DeleteObject($hBMP1)
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
    EndIf
EndFunc ;==>iconavg

Func iconbutton_1($control, $sIcon = "", $iIndex = "", $hstate = 0)
    If Not $sIcon = "" Then
        _GDIPlus_Startup()
        If $hstate = "" Then $hstate = 0
        $hwd = GUICtrlGetHandle($control)
        $width = _WinAPI_GetClientWidth($hwd)
        $height = _WinAPI_GetClientHeight($hwd)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
        $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        If $hstate = 1 Or $hstate = 2 Then $fontcol = "0xDDDDDD"
        $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        ;this is needed because adding an icon results in the background turning black
        $hBitmap1 = _ImageColorRegExpReplace($hBitmap1, "(000000FF)", "FFFFFF00"); Change black to transparent
        ;Swap red and blue channels on half the image. Image is 400x300 = 120,000 pixels. Number of pixels to replace is 60,000.
        If $hstate = 1 Then $hBitmap1 = _ImageColorRegExpReplace($hBitmap1, "([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})(FF)", "${3}${2}${1}${4}", $width * $height)
        _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
        $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
        _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
        _GDIPlus_GraphicsDispose($hImage1)
        _WinAPI_DeleteObject($hBMP1)
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
    EndIf
EndFunc ;==>iconbutton_1

Func createbutton_3($control, $col1, $col2, $col3, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0x222222", $halign = 0, $sIcon = "", $iIndex = "")
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBitmap1 = _drawborder($hBitmap1, $col1, $col2, $col3, "2", "14")
    If Not $sIcon = "" Then
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        $textleft = 1
    Else
        $textleft = 0
    EndIf
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, $halign, $textleft)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>createbutton_3

Func createbutton_3c($control, $col1, $col2, $col3, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0x222222", $halign = 0, $sIcon = "", $iIndex = "")
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBitmap1 = _drawborder1($hBitmap1, $col1, $col2, $col3, "2", "14")
    If Not $sIcon = "" Then
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        $hBitmap1 = _ImageColorRegExpReplace($hBitmap1, "(000000FF)", "FFFFFF00"); Change black to transparent
        $textleft = 1
    Else

        $textleft = 0
    EndIf
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, $halign, $textleft)

    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>createbutton_3c

Func letterbutton_1($control, $text = "", $font = "Arial", $size = 12, $style = 2, $fontcol = "0x000000")
    _GDIPlus_Startup()
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    ;$hBitmap1=_drawborder($hBitmap1,$col1,$col2,$col3,"2","14")
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, 2)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>letterbutton_1

Func topbar2($control, $slant, $pos, $col1, $col2, $col3, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0xFFFFFF", $halign = 0, $sIcon = "", $iIndex = "")
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBitmap1 = _drawborder3b($hBitmap1, $col1, $col2, $col3, 1, 0, $slant, $pos)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $sIcon = "" Then
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        $textleft = 1
    Else
        $textleft = 0
    EndIf
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, $halign, $textleft)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>topbar2

Func topbar3($control, $slant, $pos, $col1, $col2, $col3, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0xFFFFFF", $halign = 0, $sIcon = "", $iIndex = "")
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBitmap1 = _drawborder3($hBitmap1, $col1, $col2, $col3, 1, 0, $slant, $pos)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $sIcon = "" Then
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        $textleft = 1
    Else
        $textleft = 0
    EndIf
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, $halign, $textleft)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>topbar3

Func createtab_1($control, $col1, $col2, $col3, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0x222222", $halign = 0, $sIcon = "", $iIndex = "")
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBitmap1 = _drawborder2($hBitmap1, $col1, $col2, $col3, "1", "14")
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $sIcon = "" Then
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex)
        $textleft = 1
    Else
        $textleft = 0
    EndIf
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, $halign, $textleft)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>createtab_1

Func _drawtext($hBitmap1, $leftpos, $toppos, $text, $font, $size, $style, $fontcol, $align = 2, $lpadding = 0) ; left justify $align=0; right justify $align=1 ;center $align=2
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    $fcol = StringReplace($fontcol, "0x", "0xFF")
    $hBrushed = _GDIPlus_BrushCreateSolid($fcol)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($font)
    $hFont = _GDIPlus_FontCreate($hFamily, $size, $style)
    $tLayout = _GDIPlus_RectFCreate($leftpos, $toppos, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    If $align = 1 Or $align = 2 Then $lpos = ($leftpos / $align) - ($iWidth / $align)
    If $align = 0 And $lpadding = 0 Then $lpos = 5
    If $align = 0 And $lpadding = 1 Then $lpos = 34
    $tLayout = _GDIPlus_RectFCreate($lpos, ($toppos / 2) - ($iHeight / 2), 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hImage1, $text, $hFont, $aInfo[0], $hFormat, $hBrushed)
    _GDIPlus_GraphicsDispose($hImage1)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrushed)
    Return $hBitmap1
EndFunc ;==>_drawtext

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGUI = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc ;==>_GetTextSize

Func _drawicon($bitmap, $width, $height, $ico, $ind)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 32, 32)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, 3, $height / 2 - 15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon
Func _drawicon2($bitmap, $width, $height, $ico, $ind, $hstate)
    $avgcol = ""
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 32, 32) ; extract the icon
    ;create an extra bitmap to extract the icon to
    $hbmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hDC2 = _WinAPI_GetDC(0)
    $hBackDC2 = _WinAPI_CreateCompatibleDC($hDC2)
    $hBackSv2 = _WinAPI_SelectObject($hBackDC2, $hbmp2)

    If $hIcon <> 0 Then
        _WinAPI_DrawIconEx($hBackDC2, 3, $height / 2 - 15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
        $bitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hbmp2)

        ;get average colour from newly extracted icon, draw background with colour and place icon in new bmp.
        Global $avgcol = _Area_Average_Colour($bitmap2, 10, 3, $height / 2 - 15, 32, 32)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
        $hbmp = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)

        If $hstate = 0 Then
            $bitmap = _drawborder($hbmp, "0xFFFFFF", "0x" & $avgcol, "0x555555", "2", "14")
        Else
            $bitmap = _drawborder($hbmp, "0x000000", "0x" & $avgcol, "0x555555", "2", "14")
        EndIf
        $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
        $hDC = _WinAPI_GetDC(0)
        $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
        $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
        _WinAPI_DrawIconEx($hBackDC, 3, $height / 2 - 15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
        $bitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    EndIf
    ;dispose of all resources except for $bitmap2
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($bitmap)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)

    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp2)
    _WinAPI_SelectObject($hBackDC2, $hBackSv2)
    _WinAPI_DeleteDC($hBackDC2)
    _WinAPI_ReleaseDC(0, $hDC2)

    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap2
    Return
EndFunc ;==>_drawicon2

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 _drawborder2($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1) ;this one is for tabs i.e. only top corners are curved
    Local $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    Local $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    Local $iC1 = StringReplace($colour1, "0x", "0xFF")
    Local $iC2 = StringReplace($colour2, "0x", "0xFF")
    Local $iC3 = StringReplace($colour3, "0x", "0xFF")
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Local $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    Local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0]
    Local $bGammaCorrection = False
    Local $hBrush1 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght, $aFactors, $aPositions, $iC1, $iC2, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Local $hBrush3 = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    _GDIPlus_GraphicsDrawtab($hGraphics, 0, 0, $gwt, $ght, $corner, $hBrush3)
    _GDIPlus_GraphicsDrawtab($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), $corner - 2, $hBrush1)

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder2

Func _drawborder3($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1, $pos = 0) ;this is for normal buttons
    Local $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    Local $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    Local $iC1 = StringReplace($colour1, "0x", "0xFF")
    Local $iC2 = StringReplace($colour2, "0x", "0xFF")
    Local $iC3 = StringReplace($colour3, "0x", "0xFF")
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Local $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    Local $aFactors[4] = [0.1, 0.3, 0.7, 0.9], $aPositions[4] = [0.1, 0.3, 0.7, 0.9]
    Local $bGammaCorrection = False
    Local $hBrush1 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght, $aFactors, $aPositions, $iC1, $iC2, $slanty)
    Local $hBrush3 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght, $aFactors, $aPositions, $iC2, $iC1, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    If $pos = 0 Then
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, 0, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght, 0, $hBrush1)
        ; _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $ght/2, $gwt-($depth*2), ($ght-($depth*2))/2, 0,$hBrush3)
    ElseIf $pos = 1 Then
        _GDIPlus_leftend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght, 20, $hBrush3, 0, 0)
        ;   _GDIPlus_leftend($hGraphics, $depth, $ght/2, $gwt-($depth*2), ($ght-($depth*2))/2, 20,$hBrush1,0,2)
        ;   _GDIPlus_leftend($hGraphics, 0, 0, $gwt,$ght, 22, $hBrush)
        ;   _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt-($depth*2), $ght-($depth*2), 20,$hBrush1)
    ElseIf $pos = 2 Then
        _GDIPlus_rightend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_rightend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght, 20, $hBrush3, 0, 0)
        ;   _GDIPlus_rightend($hGraphics, $depth, $ght/2, $gwt-($depth*2), ($ght-($depth*2))/2, 20,$hBrush1,0,2)
    EndIf
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder3
Func _drawborder3b($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1, $pos = 0) ;this is for normal buttons
    $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $iC3 = StringReplace($colour3, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    Local $aFactors[4] = [0.1, 0.3, 0.7, 0.9], $aPositions[4] = [0.1, 0.3, 0.7, 0.9]
    Local $bGammaCorrection = False
    $hBrush1 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght / 2, $aFactors, $aPositions, $iC1, $iC2, $slanty)
    $hBrush3 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght / 2, $aFactors, $aPositions, $iC2, $iC1, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    If $pos = 0 Then
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, 0, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, 0, $hBrush1)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, 0, $hBrush3)
    ElseIf $pos = 1 Then
        _GDIPlus_leftend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, 20, $hBrush3, 0, 1)
        _GDIPlus_leftend($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, 20, $hBrush1, 0, 2)
        ;   _GDIPlus_leftend($hGraphics, 0, 0, $gwt,$ght, 22, $hBrush)
        ;   _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt-($depth*2), $ght-($depth*2), 20,$hBrush1)
    ElseIf $pos = 2 Then
        _GDIPlus_rightend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_rightend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, 20, $hBrush3, 0, 1)
        _GDIPlus_rightend($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, 20, $hBrush1, 0, 2)
    EndIf
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder3b
Func _drawborder($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1, $pos = 0) ;this is for normal buttons
    $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $iC3 = StringReplace($colour3, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    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, $iC1, $iC2, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    If $pos = 0 Then
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), $corner - 2, $hBrush1)
    ElseIf $pos = 1 Then
        _GDIPlus_leftend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), 20, $hBrush1)
    ElseIf $pos = 2 Then
        _GDIPlus_rightend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_rightend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), 20, $hBrush1)
    EndIf
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder


Func _drawborder1($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1, $pos = 0) ;this is for normal buttons
    $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $iC3 = StringReplace($colour3, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    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 / 2, $aFactors, $aPositions, $iC1, $iC2, $slanty)
    $hBrush3 = _GDIPlus_CreateLineBrushFromRect(0, 0, $gwt, $ght / 2, $aFactors, $aPositions, $iC2, $iC1, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    If $pos = 0 Then
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawtab($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, $corner, $hBrush1)
        _GDIPlus_GraphicsDrawtab2($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, $corner, $hBrush3)
    ElseIf $pos = 1 Then
        _GDIPlus_leftend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, $corner, $hBrush3, 0, 1)
        _GDIPlus_leftend($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, 20, $hBrush1, 0, 2)
    ElseIf $pos = 2 Then
        _GDIPlus_rightend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_rightend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght / 2, $corner, $hBrush3, 0, 1)
        _GDIPlus_rightend($hGraphics, $depth, $ght / 2, $gwt - ($depth * 2), ($ght - ($depth * 2)) / 2, 20, $hBrush1, 0, 2)
    EndIf
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder1


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 ;==>_GDIPlus_GraphicsDrawRoundRect

Func _GDIPlus_rightend($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0, $1corner = 0)

    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY, $iX + $iWidth, $iY)
    If $1corner <> 2 Then _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))
    If $1corner <> 1 Then _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $iY + $iHeight)
    _GDIPlus_GraphicsPathCloseFigure($hPath)
    If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)
    _GDIPlus_GraphicsPathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
EndFunc ;==>_GDIPlus_rightend

Func _GDIPlus_leftend($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0, $1corner = 0)

    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY, $iX + $iWidth, $iY)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $iY + $iHeight)
    If $1corner <> 1 Then
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
    Else
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight, $iRadius * 2, $iY, 90, 90)
    EndIf

    If $1corner <> 2 Then
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight, $iX, $iY)
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)
    EndIf
    ;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 ;==>_GDIPlus_leftend

;rounded on bottom half only
Func _GDIPlus_GraphicsDrawtab2($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, $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY, $iX + $iWidth + 2, $iY + $iHeight / 2)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight / 2, $iX, $iY)
    ; _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 ;==>_GDIPlus_GraphicsDrawtab2

;rounded on top half only
Func _GDIPlus_GraphicsDrawtab($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)
    ; _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $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 ;==>_GDIPlus_GraphicsDrawtab

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 ;==>_GDIPlus_GraphicsPathCreate
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 ;==>_GDIPlus_GraphicsPathAddLine
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 ;==>_GDIPlus_GraphicsPathAddArc
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 ;==>_GDIPlus_GraphicsPathCloseFigure
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 ;==>_GDIPlus_GraphicsPathDispose
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 ;==>_GDIPlus_GraphicsDrawPath
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 ;==>_GDIPlus_GraphicsFillPath

;==== 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

; ====== Examples calling _ImageColorRegExpReplace() =========================
; Note colour format hex 0xBBGGRRAA - Blue, Green, Red, Alpha (transparency)

;$hImage2 = _ImageColorRegExpReplace($hImage, "(000000FF)" , "FFFFFFFF" ); Change black to white
;$hImage2 = _ImageColorRegExpReplace($hImage, "(FFFFFFFF)" , "FFFFFF00" ); Change white to transparent
; $hImage2 = _ImageColorRegExpReplace($hImage, "(([0-1][0-9A-F]){3})(FF)" , "${1}00" ); Change near to white to transparent
;$hImage2 = _ImageColorRegExpReplace($hImage, "(FF0000FF|0000AAFF|FFFFFFFF)", "000000FF"); Change blue, off red, white to black

;Swap red and blue channels on half the image. Image is 400x300 = 120,000 pixels. Number of pixels to replace is 60,000.
;$hImage2 = _ImageColorRegExpReplace($hImage, "([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})(FF)", "${3}${2}${1}${4}", 60000)

;$hImage2 = _ImageColorRegExpReplace($hImage, "(([0-9E-F]){6})(FF)", "0000FFFF"); Change near to white to red

; $hImage2 = _ImageColorRegExpReplace($hImage, "av", "FF0000FF"); Change Average colour to blue in BBGGRRAA hex colour format.
;==============================================================================================
Func _ImageColorRegExpReplace($hImage, $iColSrch, $iColNew, $iCount = 0)
    Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH, $hBitmap1
    Local $v_BufferA, $AllPixels, $sREResult1, $sResult

    $iIW = _GDIPlus_ImageGetWidth($hImage)
    $iIH = _GDIPlus_ImageGetHeight($hImage)

    $hBitmap1 = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iIW, $iIH, $GDIP_PXF32ARGB)

    ; Locks a portion of a bitmap for reading or writing
    $Reslt = _GDIPlus_BitmapLockBits($hBitmap1, 0, 0, $iIW, $iIH, 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")

    $v_BufferA = DllStructCreate("byte[" & $height * $width * 4 & "]", $Scan0) ; Create DLL structure for all pixels
    $AllPixels = DllStructGetData($v_BufferA, 1)
    ;ConsoleWrite("$AllPixels, raw data, first 9 colours = " & StringRegExpReplace($AllPixels, "(.{98})(.*)", "\1") & @CRLF)

    ; Searches on this string - $sREResult1 whch has the prefix "0x" removed and a space put between pixels 8 characters long.
    $sREResult1 = StringRegExpReplace(StringTrimLeft($AllPixels, 2), "(.{8})", "\1 ")
    ;ConsoleWrite("$sREResult1 first 9 colours = " & StringRegExpReplace($sREResult1, "(.{81})(.*)", "\1") & @CRLF)

    ;====================== Average colour ===============================
    If StringInStr($iColSrch, "av") > 0 Then
        Local $iBlue, $iGreen, $iRed, $iAlpha, $avBlue, $avGreen, $avRed, $aviAlpha
        For $x = 1 To StringLen($sREResult1) Step 9
            $iBlue += Dec(Hex("0x" & StringMid($sREResult1, $x, 2)))
            $iGreen += Dec(Hex("0x" & StringMid($sREResult1, $x + 2, 2)))
            $iRed += Dec(Hex("0x" & StringMid($sREResult1, $x + 4, 2)))
            $iAlpha += Dec(Hex("0x" & StringMid($sREResult1, $x + 6, 2)))
            ;MsgBox(0,"","0x" & Hex($iAlpha,2) & Hex($iRed,2) & Hex($iGreen,2) & Hex($iBlue,2) )
        Next
        $avBlue = Hex(Round($iBlue / ($height * $width), 0), 2)
        $avGreen = Hex(Round($iGreen / ($height * $width), 0), 2)
        $avRed = Hex(Round($iRed / ($height * $width), 0), 2)
        $aviAlpha = Hex(Round($iAlpha / ($height * $width), 0), 2)

        MsgBox(0, "", "$width = " & $width & @CRLF & _
                "$height = " & $height & @CRLF & _
                "Blue = " & $avBlue & @CRLF & _
                "$iGreen = " & $avGreen & @CRLF & _
                "$iRed = " & $avRed & @CRLF & _
                "$iAlpha = " & $aviAlpha & @CRLF & _
                "Av.Col ARGB = " & "0x" & $aviAlpha & $avRed & $avGreen & $avBlue)

        Local $iRnge = 30 ; Range 30 is plus or minus 15 for each colour channel, max 0xFF and min 0x00.
    EndIf
    ;=================> End of Average colour ===============================

    If StringInStr($iColNew, "0x") > 0 Then $iColNew = StringReplace($iColNew, "0x", ""); Remove "0x" not needed

    ; StringRegExpReplace performed and white spaces removed
    $sResult = StringStripWS(StringRegExpReplace($sREResult1, $iColSrch, $iColNew, $iCount), 8)

    ; Replace "0x" prefix and set modified data back to DLL structure, $v_BufferA
    DllStructSetData($v_BufferA, 1, "0x" & $sResult)
    _GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt) ; releases the locked region

    Return $hBitmap1
EndFunc ;==>_ImageColorRegExpReplace


; #FUNCTION# =========================================================================================================
; Name...........: _Area_Average_Colour
; Description ...: Returns average colour within a defined are of the display
; Syntax ........: _Area_Average_Colour([$iStep [, $iLeft [, $iTop [, $iWidth [, $iHeight ]]]]])
; Parameters ....: $iStep - Pixel resolution value. Lower values give better resolution but take longer. (Default = 10)
;   $iLeft - X coordinate of top-left corner of area (Default = 0 - left edge of screen)
;   $iTop   - Y coordinate of top-left corner of area (Default = 0 - top edge of screen)
;   $iWidth - Width of the area (Default = @DesktopWidth)
;   $iHeight - Height of the area (Default = @DesktopHeight)
; Requirement(s) : v3.3.0.0 or higher
; Return values .: Success - Returns six character string containing RGB hex values
;   Failure - Returns 0 and sets @error:
;   1 - Screen Capture failure
;   2 - GDI function failure
; Author ........: Melba23. Credit to Malkey for the basic GDI code
; Modified ......: Minor change by Picea892 pass bmp instead of using screenshot
; Remarks .......:
; Example .......: Yes
;=====================================================================================================================
Func _Area_Average_Colour($hImage, $iStep = 10, $iLeft = 0, $iTop = 0, $iWidth = 32, $iHeight = 32)

    Local $iBlue = 0, $iGreen = 0, $iRed = 0, $iInterim_Blue = 0, $iInterim_Green = 0, $iInterim_Red = 0, $iInner_Count = 0, $iOuter_Count = 0
    Local $tRes = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
    If @error Then
        _GDIPlus_GraphicsDispose($hImage)
        Return SetError(2, 0, 0)
    EndIf

    ;Get the returned values of _GDIPlus_BitmapLockBits()
    Local $iLock_Width = DllStructGetData($tRes, "width")
    Local $iLock_Height = DllStructGetData($tRes, "height")
    Local $iLock_Stride = DllStructGetData($tRes, "stride")
    Local $iLock_Scan0 = DllStructGetData($tRes, "Scan0")

    ; Run through the BitMap testing pixels at the step distance
    For $i = 0 To $iWidth - 1 Step $iStep
        For $j = 0 To $iHeight - 1 Step $iStep
            Local $v_Buffer = DllStructCreate("dword", $iLock_Scan0 + ($j * $iLock_Stride) + ($i * 4))
            ; Get colour value of pixel
            Local $v_Value = DllStructGetData($v_Buffer, 1)
            ; Add components
            $iBlue += _ColorGetBlue($v_Value)
            $iGreen += _ColorGetGreen($v_Value)
            $iRed += _ColorGetRed($v_Value)
            ; Adjust counter
            $iInner_Count += 1
        Next
        ; Determine average value so far - this prevents value becoming too large
        $iInterim_Blue += $iBlue / $iInner_Count
        $iBlue = 0
        $iInterim_Green += $iGreen / $iInner_Count
        $iGreen = 0
        $iInterim_Red += $iRed / $iInner_Count
        $iRed = 0
        ; Adjust counters
        $iInner_Count = 0
        $iOuter_Count += 1
    Next
    ; Determine final average
    Local $avBlue = Hex(Round($iInterim_Blue / $iOuter_Count, 0), 2)
    Local $avGreen = Hex(Round($iInterim_Green / $iOuter_Count, 0), 2)
    Local $avRed = Hex(Round($iInterim_Red / $iOuter_Count, 0), 2)

    ; Clear up
    _GDIPlus_BitmapUnlockBits($hImage, $tRes)
    _GDIPlus_GraphicsDispose($hImage)

    Return ($avRed & $avGreen & $avBlue)

EndFunc ;==>_Area_Average_Colour

Func _InvertColor($iColor, $mode = 1)
    Switch $mode
        Case 0
            Return "0x" & Hex(0xFFFFFF - $iColor, 6)
        Case 1
            Return "0x" & StringRegExpReplace(Hex($iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
        Case 2
            Return "0x" & StringRegExpReplace(Hex(0xFFFFFF - $iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
    EndSwitch
EndFunc ;==>_InvertColor

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Thanks Dantay9! Checking in control panel, seems very very good,a great improvement when you look at the memory usage. I used winmerge to try and find the changes. The one that struck me most was

_WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))

I did not know that was the way to write that code. I believe this must be a significant place where I was increasing memory usage. Anyways, I can't tell how much I appreciate you cleaning up the script. I think this is a piece of code I will be referencing regularly and owe you. I hope to pay you back someday.

I'm still visiting family so probably won't change the first post until I get back to my home computer.

Cheers and have a good New Years.

Picea

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Arrgh! I've been locking horns with that bloody RAM leak for over a year now. This thread may or may not help the cause, good luck gents!

Edited by Dolemite50

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

StringRERange function is missing in shapecontrols_udf.au3.

(Plus the hover udf needs updating to use OnAutoItExitRegister.)

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Dolemite50, glad I'm not the only one, misery loves company. Anyways seems Dantay9 fixed if for me. ;)

"StringRERange function is missing in shapecontrols_udf.au3."

Went through the original Malkey functions and realized you are right. I made the change...though I doubt anyone will notice because no differences are visual differences apparent.

(Plus the hover udf needs updating to use OnAutoItExitRegister.)

Got to take this one up with Mr Creator, not me. I think others have already posted on his thread about that.

Thanks for all the interest and help.

I updated the original post with Dantay9 and Martin's fixes. Also added a custom made close button and guibackground to the UDF. I added a second example to demonstrate use.

Picea

Edited by picea892

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

_WinAPI_DeleteObject(GUICtrlSendMsg($Control, 0x0172, 0, $hBMP1))
I can not take credit for this piece of code. I believe it came from Yashied here. I narrowed down the places that were using up the memory and came to that line. A quick search on the forum turned up this post with a master piece of code. Before reading Yashied's post, I didn't know that either. Yet another great example from Yashied. Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

ok, clearly, i am a retard :idea:

i can not understand the examples to save my own life.

can i have a little demonstration for idiots thing?

Share this post


Link to post
Share on other sites

Hi.

Simple self contained version for your use.

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <StaticConstants.au3>
#Include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Opt("GUIOnEventMode",1)
Global $gradient1, $exited=0,$tabs1[4], $title,$Gui,$bckpic,$closebut
Global $setflag=0
Global $bckpiccal
commonbck()

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "leftmouse")
GUISetState()

Func commonbck()
    $Gui = GUICreate("FMP Calendar", 460,400,-1,-1, BitOR($WS_CLIPSIBLINGS,$WS_POPUP))
    GUISetBkColor("0xABCDEF")
    $bckpic= GUICtrlCreatePic("",0,25,460, 265)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1,"0xCCCCCC","0x222222","0x111111")
    GUISetControlsVisible($Gui)

    $closebut = GUICtrlCreatePic("", 425, 30,38, 38)
    closebutton(-1,"0x550000")
        $title=GUICtrlCreateLabel("Schedules",10,30,400,30)
    GUICtrlSetFont(-1,20,400,1,"Verdana")
    GUICtrlSetColor(-1,"0x000022")
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
EndFunc

While 1
sleep(100)
hover()
WEnd

func hover()
    $hov=GUIGetCursorInfo($Gui)
    if $hov[4]<>$bckpic then 
        if $hov[4]= $closebut and $setflag<>1 then
            closebutton($closebut,"0xCC0000")
            $setflag=1
        EndIf
    Else
        if $setflag=1 then
            closebutton($closebut,"0x550000")
            $setflag=0
        EndIf
    EndIf
EndFunc

func leftmouse()
    $hov=GUIGetCursorInfo($Gui)
    if $hov[4]<>$bckpic then 
        if $hov[4]= $closebut then Exit 0
    Return
    EndIf
    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 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", "CreateRoundRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2]+1, _
            "long", $aCtrlPos[1] + $aCtrlPos[3]+1, "long", 25, "long", 25)
        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

func background($control,$col1,$col2,$col3)
    _GDIPlus_Startup ()
    $hwd=GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width=_WinAPI_GetClientWidth($hwd)
    $height=_WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic)
    $hBitmap1=_drawborder($hBitmap1,$col1,$col2,$col3,"4","14",3)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
     _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_ImageDispose ($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
EndFunc 

;handler, to draw background and createbutton3
Func _drawborder($hBitmap, $colour1, $colour2, $colour3, $depth, $corner, $slanty = 1, $pos = 0) ;this is for normal buttons
    $gwt = _GDIPlus_ImageGetWidth($hBitmap) - 1
    $ght = _GDIPlus_ImageGetHeight($hBitmap) - 1
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    $iC3 = StringReplace($colour3, "0x", "0xFF")
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid($iC2)

    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, $iC1, $iC2, $slanty)
    GDIPlus_SetLineGammaCorrection($hBrush1, $bGammaCorrection)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    If $pos = 0 Then
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt, $ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), $corner - 2, $hBrush1)
    ElseIf $pos = 1 Then
        _GDIPlus_leftend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_leftend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), 20, $hBrush1)
    ElseIf $pos = 2 Then
        _GDIPlus_rightend($hGraphics, 0, 0, $gwt, $ght, 22, $hBrush)
        _GDIPlus_rightend($hGraphics, $depth, $depth, $gwt - ($depth * 2), $ght - ($depth * 2), 20, $hBrush1)
    EndIf
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc ;==>_drawborder

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 ;==>_GDIPlus_GraphicsDrawRoundRect

;==== 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

;flat left side
Func _GDIPlus_rightend($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0, $1corner = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY, $iX + $iWidth, $iY)
    If $1corner <> 2 Then _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))
    If $1corner <> 1 Then _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $iY + $iHeight)
    _GDIPlus_GraphicsPathCloseFigure($hPath)
    If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)
    _GDIPlus_GraphicsPathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
EndFunc ;==>_GDIPlus_rightend
;flat right side
Func _GDIPlus_leftend($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0, $1corner = 0)

    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY, $iX + $iWidth, $iY)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iHeight, $iX, $iY + $iHeight)
    If $1corner <> 1 Then
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
    Else
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight, $iRadius * 2, $iY, 90, 90)
    EndIf

    If $1corner <> 2 Then
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight, $iX, $iY)
        _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)
    EndIf
    ;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 ;==>_GDIPlus_leftend

func closebutton($control,$col1)
    _GDIPlus_Startup ()
    $hwd=GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width=_WinAPI_GetClientWidth($hwd)
    $height=_WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic)
;   $hBitmap1=_drawborderclosed($hBitmap1,$col1,"4","14",3)
        ; Instead of calling a seperate function, include right in first function
            $iC1 = StringReplace($col1, "0x", "0xFF")
            $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
            Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
            _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
            _GDIPlus_GraphicsDrawclose($hGraphics, 0, 0, $width,$height, 44, $hBrush)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_GraphicsDispose($hGraphics)
            ;;;;;;;;;;;
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
     _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_ImageDispose ($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_GraphicsDispose ($hGraphics)
    _GDIPlus_Shutdown ()
EndFunc

Func _GDIPlus_GraphicsDrawclose($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)
    Return $hGraphics
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 ;==>_GDIPlus_GraphicsPathCreate
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 ;==>_GDIPlus_GraphicsPathAddLine
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 ;==>_GDIPlus_GraphicsPathAddArc
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 ;==>_GDIPlus_GraphicsPathCloseFigure
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 ;==>_GDIPlus_GraphicsPathDispose
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 ;==>_GDIPlus_GraphicsDrawPath
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 ;==>_GDIPlus_GraphicsFillPath

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