Jump to content

Recommended Posts

Posted (edited)

Hi

Attached is a template for creating a widget. Using a png as a background requires you to stretch it when you resize, this adds a significant amount of tweaking and correcting of controls. I have successfully done this with my Outlook widget. I however wanted to create a png-like effect using just gdi and think I have done it.

I also wanted to make tweaking the widget simple. All you need to do is add controls. The script takes care of the rest. No other tweaks required. I think it would thus be very easy to udf this script and I will do it if there is interest.

Make sure you are using the latest au3 version.

#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#Include <Misc.au3>

Opt("TrayAutoPause", 0)
opt("GUIOnEventMode",1)
TraySetClick(8)
Global $a_Factors[4] = [0.0, 0.4, 0.8, 1.0] ;Background gradient
Global $a_Positions[4] = [0.0, 0.3, 0.6, 1.0] ; Background Gradient
Global $nth=5 ; how many inputboxes
Global $stopit
Global Const $VK_RETURN = 0x0D ;Enter key
global $dll = DllOpen("user32.dll")
_settrayicon(32, 32); <-- Set date as traybar icon
Global $gwidth=500, $gheight=355,$initialpsx=200,$initialpsy=200, $rndclo

Global $But[6],$But2[6], $bX = 200, $Last,$daystate=1, $timestart, $timeend, $infocal=1
Global $transcolour="0XABCDEF", $togontop=0, $picnames[2][4]
; change GUI name to change widget name
Global $Gui = GUICreate("Outlook Calendar Updater", $gwidth, $gheight,$initialpsx,$initialpsy ,$WS_POPUP,$WS_EX_TOOLWINDOW)
Global $ctrlhwd[2][3], $hOldFunc[2], $focusnumber=1, $input[$nth],$onoff=0, $focussed=0, $actthebut=0

;;;;;;;;;;;;;;;;;register messages for background gui;;;;;;;;;;;;;;;;;;;;;;;;
    GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" ) ;sets up drag move on background and x button close
    GUIRegisterMsg(0x0100,"bckkeypress")
    GUIRegisterMsg($VK_RETURN,"bckkeypress")
;   GUIRegisterMsg(0x0216, "MY_PAINT")
    GUIRegisterMsg(0x000F, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
    GUIRegisterMsg(0x0085 , "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
;END;;;;;;;;;;;;;;;;register messages for background gui;;;;;;;;;;;;;;;;;;;;;;;;

$guicontrols=GUICreate("Outlook",$gwidth, $gheight,$initialpsx,$initialpsy,$WS_POPUP,$WS_EX_LAYERED,$Gui) ;gui holding the controls
;;;;;;;;;;;below is a DLLcall register for the foreground child window;;;;;;;;;;;;;;;;

GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "clickbuttons")
Global $hFunc = DllCallbackRegister('InputHandler', 'lparam', 'hwnd;uint;wparam;lparam') ; required so input box backgrounds can be changed on tabbing, to receive enter keys and other control events

;;;;;;;;;;;;;;;;;;;;;;;set controls here as onevent;;;;;;;;;;;;;;;;;;;;;
$goingdown=20
for $j= 1 to $nth-1
    $Input[$j] = GUICtrlCreateInput('', 20, $goingdown, 260, 25)
    focushandler($Input[$j],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
    $goingdown=$goingdown+30
Next
        Global $pic = GUICtrlCreatePic("", 100, $goingdown, 50, 25,$WS_TABSTOP)
        SetIcon($pic ,64, 25, 1,1, "Finish",0)
        focushandler($pic,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
        ;if you want to have control have event on mouseclick, add function as a 3rd variable
        Global $pic2 = GUICtrlCreatePic("", 100, $goingdown+40, 50, 25,$WS_TABSTOP)
        SetIcon($pic2 ,64, 25, 1,1, "Again",0)
        focushandler($pic2,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
;END;;;;;;;;;;;;;;;;;;;;;;set controls here as onevent;;;;;;;;;;;;;;;;;;;;END;

GUISetControlsVisible($guicontrols) ;sets controls visible
GUISetBkColor(0x000000,$Gui)
        WinSetTrans($GUI,"",200)
        WinSetTrans($guicontrols,"",255)
GUISetState(@SW_SHOW, $Gui)
GUISetState(@SW_SHOW, $guicontrols)
_drawborder($Gui,$gwidth,$gheight,"4","0x000000","0x333333","15") ;sets up the border on background
_GuiRoundCorners($Gui,0, 0, 30, 30) ; makes the background have round corners

GUISwitch($guicontrols)

While 1
    Sleep(40)
    $msg = TrayGetMsg()
    if $msg=$TRAY_EVENT_PRIMARYDOWN and WinActive($guicontrols)=0 then WinActivate($guicontrols)

    hovered($guicontrols) ;sets the hover effects
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Background GUI Registered Message Handlers;;;;;;;;;;;;;
Func bckkeypress($hWnd, $msg, $wParam, $lParam)
    WinActivate($guicontrols)
EndFunc

Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($Gui,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
    ;_WinAPI_RedrawWindow($Gui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN

 Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT

;END;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Background GUI Registered Message Handlers;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;Tray events;;;;;;;;;;
func onautoitexit()
    if FileExists(@scriptDir & "\Trayicon.ico") then FileDelete(@scriptDir & "\Trayicon.ico")
    ;GUIDelete()
    DllCallbackFree($hFunc)
EndFunc

func exited()
    if FileExists(@scriptDir & "\Trayicon.ico") then FileDelete(@scriptDir & "\Trayicon.ico")
    GUIDelete()
    DllCallbackFree($hFunc)
    DllClose($hFunc)
    GUIDelete($guicontrols)
    GUIDelete($Gui)
    exit 0
EndFunc

func togontop()
    if $togontop=1 then
        WinSetOnTop($Gui,"",0)
        $togontop=0
    Else
        WinSetOnTop($Gui,"",1)
        $togontop=1
    EndIf
EndFunc

;END;;;;;;;;;;;;;;;;;Tray events;;;;;;;;;;

Func Drag() ;allows dragging of widget and click to exit
$t=clickexit()
if $t=1 then Exit
Local $PosDiff[2]
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ($Gui,"")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        While _IsPressed ("01", $dll)
            $MousePos = MouseGetPos ()
            WinMove ($Gui, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            WinMove ($guicontrols, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            $WinPos = WinGetPos ("","")
            Sleep (10)
        WEnd
        ExitLoop
        Sleep (10)
    WEnd
    ;_WinAPI_RedrawWindow($Gui,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
    _WinAPI_RedrawWindow($guicontrols,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW))
EndFunc

Func clickbuttons()
    Local $PosDiff[2]
    $MousePos = MouseGetPos ()
    $WinPos = WinGetPos ($guicontrols,"")
    $hovered=GUIGetCursorInfo($guicontrols)
 ;   ToolTip($hovered[4])
    for  $i = 1 to UBound($ctrlhwd)-1
        if IsString($ctrlhwd[$i][2]) and  GUICtrlGetHandle($hovered[4])= $ctrlhwd[$i][0] then
            Execute($ctrlhwd[$i][2]&"("&$ctrlhwd[$i][0] &")")
            return 1
        EndIf
    Next

    return 0
EndFunc

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

func hovered($gcon) ;anything that needs a hover effect has to be enacted here
$hov=GUIGetCursorInfo($gcon)
$amousepos=MouseGetPos()
$aguipos=WinGetPos($Gui)

    for $i =1 to UBound($ctrlhwd)-1
            if $onoff=0 and $hov[4]<>0 and IsString($ctrlhwd[$i][2]) and GUICtrlGetHandle($hov[4]) = $ctrlhwd[$i][0]Then
                $onoff=$hov[4]
                whichpic($hov[4],2)
            Elseif $hov[4]<>$onoff and $onoff<>0 and GUICtrlGetHandle($hov[4])<> $ctrlhwd[$i][0] then
                whichpic($onoff,0)
                $onoff=0
            EndIf
    next

if $infocal=0 and $amousepos[0]>=$aguipos[0] and $amousepos[1]>=$aguipos[1] and $amousepos[0]<=$aguipos[0]+$aguipos[2] and $amousepos[1]<=$aguipos[1]+$aguipos[3] then
        WinSetTrans($GUI,"",200)
        WinSetTrans($gcon,"",255)
        $infocal=1
        return
elseif $infocal=0 and WinActive($gcon)=1 then
        WinSetTrans($GUI,"",200)
        WinSetTrans($gcon,"",255)
        $infocal=1
        return

;   EndIf
elseif $amousepos[0]<$aguipos[0] or $amousepos[1]<$aguipos[1] or $amousepos[0]>$aguipos[0]+$aguipos[2] or $amousepos[1]>$aguipos[1]+$aguipos[3] then
    if $infocal=1 and not WinActive($gcon) and not WinActive($Gui) then
        WinSetTrans($GUI,"",100)
        WinSetTrans($gcon,"",100)
        $infocal=0
        Return

    EndIf
EndIf
EndFunc

func no_tab() ;after control is created call this function to remove the tabstop if needed
    _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, _
    BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP)))
EndFunc

func whichpic($dlgctrl,$pressstate)

    for $h= 1 to UBound($picnames)-1

        if $picnames[$h][0]=$dlgctrl Then

            SetIcon($dlgctrl ,$picnames[$h][2], $picnames[$h][3], 1,1, $picnames[$h][1],$pressstate,1)
            return
        endif
    Next

EndFunc

Func InputHandler($hWnd, $iMsg, $wParam, $lParam)

    for $i =1 to UBound($ctrlhwd)-1
        If $hWnd = $ctrlhwd[$i][0] Then
            $hOldF = $hOldFunc[$i]
            $include=$ctrlhwd[$i][1]
            $testit=$ctrlhwd[$i][2]

        EndIf
    next
    If $iMsg = $WM_SETFOCUS Then

            if IsString($testit) and $actthebut=0 then
                    whichpic(_WinAPI_GetDlgCtrlID($hWnd) ,2) ; Selected
                    $actthebut=1
            ElseIf not IsString($testit) and $actthebut=1 then
                whichpic(_WinAPI_GetDlgCtrlID($wParam),0) ;back to normal
                $actthebut=0
            elseif IsString($testit) then
                    whichpic(_WinAPI_GetDlgCtrlID($hWnd),2) ; Selected
                    whichpic(_WinAPI_GetDlgCtrlID($wParam),0) ;back to normal
                    $actthebut=1
            EndIf
    elseIf $iMsg = 0x0008 Then
            if WinActive($Gui) Then
                    $t=clickexit()
                    if $t=1 then
                        $actthebut=0
                        exited()
                    EndIf
            EndIf
    elseIf $wParam = $VK_RETURN then
        if _IsPressed("0D", $dll) and IsString($testit) then Execute($testit&"("&$hWnd&")")
    EndIf
    Return _WinAPI_CallWindowProc($hOldF, $hWnd, $iMsg, $wParam, $lParam)
EndFunc

func focushandler($Inpx,$inout, $funcname=0) ;Every control which has a tabstop must be sent to this function
    ; $Inpx = name of control, $inout = background gray when active, $executable on button press
    GUICtrlSetFont($Inpx,"",11,400,"Arial")
    $ctrlhwd[$focusnumber][0] = GUICtrlGetHandle($Inpx)
    $ctrlhwd[$focusnumber][1] = $inout
    $ctrlhwd[$focusnumber][2] = $funcname
    $hOldFunc[$focusnumber] = _WinAPI_GetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC)
    _WinAPI_SetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC, DllCallbackGetPtr($hFunc))

    $focusnumber=$focusnumber+1
    ReDim $ctrlhwd[ubound($ctrlhwd)+1][3]
    ReDim $hOldFunc[ubound($hOldFunc)+1]
EndFunc

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

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

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

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

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

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

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

Func GUISetControlsVisible($hWnd)
    Local $aM_Mask, $aCtrlPos, $aMask
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))
    For $i = 3 To $aLastID[0]
        $aCtrlPos = ControlGetPos($hWnd, '', $i)
        If Not IsArray($aCtrlPos) Then ContinueLoop

        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description::    Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                  $hwnd - Handle of GUI to work on
;                  $i_transcolor - Transparent color
;                  $Transparency - Set Transparancy of GUI
;                  $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                  Error: 0
;                   @error: 1 to 3 - Error from DllCall
;                   @error: 4 - Function did not succeed - use
;                               _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency, $isColorRef = False)

Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local Const $LWA_ALPHA = 0x2
Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error,0,0)
        Case $ret[0] = 0
            Return SetError(4,0,0)
        Case Else
            Return 1
    EndSelect
EndFunc;==>_API_SetLayeredWindowAttributes

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

func _drawborder($guiname,$gwt,$ght,$depth,$colour1,$colour2,$corner)
    _GDIPlus_Startup()
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    Global $hDC = _WinAPI_GetDC($guiname)
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush1 = _GDIPlus_BrushCreateSolid($iC2)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt,$ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $depth, $depth, $gwt-($depth*2)-2, $ght-($depth*2)-2, $corner,$hBrush1)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_BrushDispose($hBrush1)
        _WinAPI_ReleaseDC($guiname, $hDC)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
EndFunc
Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - ($iRadius * 2), $iY)
     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)

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

Func _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth-33, 3, 23,23,0, 360) ; this is the circle around the X
    _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)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X
        _GDIPlus_GraphicsPathAddLine($hPath,  $iX + $iWidth - ($iRadius * 2), $iY, $iX + $iWidth-29, 5)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -28, 7,$iX + $iWidth -22,13)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -16, 7,$iX + $iWidth -14,8)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -21,14,$iX + $iWidth -14,21)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -15,22,$iX + $iWidth -22,16)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -28, 22,$iX + $iWidth-29 ,21)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -23, 15,$iX + $iWidth-29 ,8)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth-29 ,8,$iX + $iWidth - ($iRadius * 2), $iY)
        ;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X ends
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _settrayicon($iW, $iH)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
    _GDIPlus_Startup()
    ;Buffer
    $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xFFFFFF, $iW, $iH)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    ;Gradient Background - At the top Maroon 50% transparency to fully opaque black at bottom
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect( 0, 0, $iW, $iH, $a_Factors, $a_Positions, 0x80800040, 0xFF000000,1,0)
    GDIPlus_SetLineGammaCorrection($hBrushLin);, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin)
    ; Draw text
    $sText = @MDAY
    $hBrush1 = _GDIPlus_BrushCreateSolid(0xFFBBBBBB)
    $hFormat = _GDIPlus_StringFormatCreate(0)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 16, 1, 3)
    $tLayout = _GDIPlus_RectFCreate(0, 4, 32,32) ; increase 300 to 380 for one line of text
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
   _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush1)

$hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hImage)
; Create an ico file from the image
_CreateIconFileFromHICON($hIcon, @scriptDir & "\trayicon.ico")
; Destroy the HICON now I've finished with it.
_WinAPI_DestroyIcon($hIcon)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TraySetIcon(@scriptDir & "\Trayicon.ico")
    _GDIPlus_ImageDispose($hImage)

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
     _GDIPlus_BrushDispose($hBrushLin)

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>PicSetGraphics

Func _CreateIconFileFromHICON($hIcon, $sOutIcon)
    Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO
    $sIco = "0x000001000100"
    $sBmp = "28000000"
    $aInfo = _WinAPI_GetIconInfo($hIcon)
    $hCDC = _WinAPI_CreateCompatibleDC(0)
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))
    _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0)
    $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4))
    $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"))) & _RB(Hex(DllStructGetData($tBI, "Height") * 2)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000"
    $iSz = DllStructGetData($tBI, "SizeImage")
     $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits))
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
        $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next
    $tBits = 0
    $tBI = 0
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))
    _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0)
    _WinAPI_DeleteDC($hCDC)
    $iSz += DllStructGetData($tBI, "SizeImage")
    $sBmp &= _RB(Hex($iSz)) & "00000000000000000000000000000000"
    $sIco &= _RB(Hex($iSz + 40)) & _RB(Hex("22")) & $sBmp & $sBD
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits))
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
        $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next
    ; Write the icon to a file.
    $FO = FileOpen($sOutIcon, 18)
    FileWrite($sOutIcon, Binary($sIco))
    FileClose($FO)
    ; Clear the structs
    $tBits = 0
    $tBI = 0
EndFunc   ;==>_CreateIconFileFromHICON

; Reverse Byte String
Func _RB($sByte)
    Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
    For $i = UBound($aX) - 1 To 0 Step -1
        $sX &= $aX[$i]
    Next
    Return $sX
EndFunc   ;==>_RB

Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    Local $hIcon
    $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($hIcon[0], 0, $hIcon[2])
EndFunc   ;==>_GDIPlus_BitmapCreateHICONFromBitmap


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;guictrl onevent handlers

Func picactions($control)
ToolTip("picturepressed")
whichpic(_WinAPI_GetDlgCtrlID($control),1)
sleep(500)
    whichpic(_WinAPI_GetDlgCtrlID($control) ,2)
    ToolTip("")
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Edited by picea892
Posted (edited)

Lines 42 to 56 are the key.

;;;;;;;;;;;;;;;;;;;;;;;set controls here as onevent;;;;;;;;;;;;;;;;;;;;;
$goingdown=20
for $j= 1 to $nth-1
    $Input[$j] = GUICtrlCreateInput('', 20, $goingdown, 260, 25)
    focushandler($Input[$j],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
    $goingdown=$goingdown+30
Next
        Global $pic = GUICtrlCreatePic("", 100, $goingdown, 50, 25,$WS_TABSTOP)
        SetIcon($pic ,64, 25, 1,1, "Finish",0)
        focushandler($pic,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
        ;if you want to have control have event on mouseclick, add function as a 3rd variable
        Global $pic2 = GUICtrlCreatePic("", 100, $goingdown+40, 50, 25,$WS_TABSTOP)
        SetIcon($pic2 ,64, 25, 1,1, "Again",0)
        focushandler($pic2,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
;END;;;;;;;;;;;;;;;;;;;;;;set controls here as onevent;;;;;;;;;;;;;;;;;;;;END;

For guictrls that don't need onevents you add them in as follows:

$Input[$j] = GUICtrlCreateInput('', 20, $goingdown, 260, 25)
    focushandler($Input[$j],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab

I really can't see a reason to set one of these guictrl to excluded from the focushandler. but the option is there.

For the guictrlpics which are to act like buttons there is a bit more work.

Global $pic2 = GUICtrlCreatePic("", 100, $goingdown+40, 50, 25,$WS_TABSTOP)
SetIcon($pic2 ,64, 25, 1,1, "Again",0)
focushandler($pic2,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab

You have to add a tabstop when it is a guictrlcreatepic that is being used as a button. The next line creates the image on the picture. Everything stays the same except the controlname, width, height and text. This is because this code gets called multiple times in the script to simulate button actions, if you change them here, need to change everywhere.

SetIcon({controlname ,{width}, {height}, {direction_of_gradient},{2blacklines}, {text},{pressedstate})

the focushandler line is the complexity. this essentially is setting an onevent for the guictrlpic when it is pressed. So you would change "picactions" to whatever function you would like to be executed when that button is pressed. The function picactions is the last function in the script so it is easy to find.

This widget is completely keyboard friendly. The guictrlpics can be tabbed to and will react when they get the focus and when enter is pressed.

Let me know if it is still confusing, Goodluck

[Edit] updated the first post to fix a minor error involving a guictrlpic having keyboard focus when the x button is pressed.

Picea892

Edited by picea892
Posted

Thanks, picea!

I'm looking forward to taking it for another spin with the new info, and I appreciate you "dumbing it down" a bit for me.

I've been working on something similar but after reviewing my code I've deemed it the "Idjut Template".

Thanks, I'll try to get back at you with some feedback soon.

Posted (edited)

Made another minor fix on the first post.

Below is a more complete example of how to use demonstrating most of the common guictrls one would use and the changing of the widget size on the fly. This is a much better example, but I won't put in the first post because of the detailed instructions associated with it....Can't hurt to have two different examples anyways.

[Edit:] Actually just noticed that the labels with semi-transparent bckgrd doesn't show properly on my Vista....interesting. Oh well, it is what it is.

#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#Include <Misc.au3>
Global $daystate=1
Opt("TrayAutoPause", 0)
opt("GUIOnEventMode",1)
TraySetClick(8)
Global $hFunc, $guicontrols, $Gui, $start, $end, $allday, $timestart, $timeend, $pic, $bX = 43
Global $vehicals[3]=["Truck","Car","Van"]
Global $rooms[3]=["Office #1","Project room","Boardroom"]
Global $a_Factors[4] = [0.0, 0.4, 0.8, 1.0] ;Background gradient
Global $a_Positions[4] = [0.0, 0.3, 0.6, 1.0] ; Background Gradient
Global $nth=5 ; how many inputboxes
Global $stopit
Global Const $VK_RETURN = 0x0D ;Enter key
global $dll = DllOpen("user32.dll")
_settrayicon(32, 32); <-- Set date as traybar icon
Global $gwidth=440, $gheight=120,$initialpsx=200,$initialpsy=200, $rndclo

Global $But[6],$But2[6], $Last,$daystate=1, $timestart, $timeend, $infocal=1
Global $transcolour="0XABCDEF", $togontop=0, $picnames[2][4]
; change GUI name to change widget name

Global $ctrlhwd[2][3], $hOldFunc[2], $focusnumber=1, $input[$nth],$onoff=0, $focussed=0, $actthebut=0

bckwin()
window1()
finalizewin()

func bckwin()
    $Gui = GUICreate("Outlook Calendar Updater", $gwidth, $gheight,$initialpsx,$initialpsy ,$WS_POPUP,$WS_EX_TOOLWINDOW)
    ;;;;;;;;;;;;;;;;;register messages for background gui;;;;;;;;;;;;;;;;;;;;;;;;
    GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" ) ;sets up drag move on background and x button close
    GUIRegisterMsg(0x0100,"bckkeypress")
    GUIRegisterMsg($VK_RETURN,"bckkeypress")
    ;   GUIRegisterMsg(0x0216, "MY_PAINT")
    GUIRegisterMsg(0x000F, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
    GUIRegisterMsg(0x0085 , "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
    ;END;;;;;;;;;;;;;;;;register messages for background gui;;;;;;;;;;;;;;;;;;;;;;;;
        WinSetTrans($GUI,"",230)
    $guicontrols=GUICreate("Outlook",$gwidth, $gheight,$initialpsx,$initialpsy,$WS_POPUP,$WS_EX_LAYERED,$Gui) ;gui holding the controls
    ;;;;;;;;;;;below is a DLLcall register for the foreground child window;;;;;;;;;;;;;;;;
    GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "clickbuttons")
    $hFunc = DllCallbackRegister('InputHandler', 'lparam', 'hwnd;uint;wparam;lparam') ; required so input box backgrounds can be changed on tabbing, to receive enter keys and other control events
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;set controls here as onevent;;;;;;;;;;;;;;;;;;;;;

func window1()
                GUISwitch($Gui)
                        GUICtrlCreateLabel("Start",25,12,60,17)
                        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                        GUICtrlSetFont(-1,11,400)
                        GUICtrlCreateLabel("Finish",190,12,60,17)
                        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                        GUICtrlSetFont(-1,11,400)
                        GUICtrlCreateLabel("All Day",370,34,60,17)
                        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                        GUICtrlSetFont(-1,11,400)

                GUISwitch($guicontrols)

        $start = GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY, 20, 35, 160, 25)
            focushandler($start,1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
            GUICtrlSetFont(-1,11,400)
        $end = GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY,185, 35, 160, 25)
            focushandler($end,1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
            GUICtrlSetFont(-1,11,400)

            $allday = GUICtrlCreateCheckbox("", 352, 42, 12, 12)
            focushandler($allday,1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
            GUICtrlSetState($allday,$GUI_CHECKED)
            GUICtrlSetOnEvent($allday,"allday")
            $timestart=GUICtrlCreateCombo("", 20, 75, 100, 30)
            focushandler($timestart,1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
            GUICtrlSetData(-1, "8:00 AM|8:30 AM|9:00 AM|9:30 AM|10:00 AM|10:30 AM|11:00 AM|11:30 AM|12:00 PM|12:30 PM|1:00 PM|1:30 PM|2:00 PM|2:30 PM|3:00 PM|3:30 PM|4:00 PM|4:30 PM|5:00 PM|5:30 PM|6:00 PM|6:30 PM|7:00 PM", "8:30 AM")
            GUICtrlSetState(-1, $GUI_DISABLE)
            $timeend=GUICtrlCreateCombo("", 185, 75, 100, 30)
            focushandler($timeend,1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
            GUICtrlSetData(-1, "8:00 AM|8:30 AM|9:00 AM|9:30 AM|10:00 AM|10:30 AM|11:00 AM|11:30 AM|12:00 PM|12:30 PM|1:00 PM|1:30 PM|2:00 PM|2:30 PM|3:00 PM|3:30 PM|4:00 PM|4:30 PM|5:00 PM|5:30 PM|6:00 PM|6:30 PM|7:00 PM", "4:30 PM")
            GUICtrlSetState(-1, $GUI_DISABLE)

        $pic = GUICtrlCreatePic("", 355, 75, 50, 25,$WS_TABSTOP)
        SetIcon($pic ,52, 25, 1,1, "Next",0)
        focushandler($pic,0,"clseguictrlwin") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab

endfunc

func allday()
    if GUICtrlRead($allday)="4" and $daystate=1 then
        $daystate=4
        GUICtrlSetState($timestart, $GUI_enABLE)
        GUICtrlSetState($timeend, $GUI_enABLE)
    elseif GUICtrlRead($allday)="1" and $daystate=4 then
        $daystate=1
        GUICtrlSetState($timestart, $GUI_DISABLE)
        GUICtrlSetState($timeend, $GUI_DISABLE)
    EndIf
EndFunc
func window2()
                    GUISwitch($Gui)
                        GUICtrlCreateLabel("Rooms",20,10,70,24)
                        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                        GUICtrlSetFont(-1,14,500)
                        GUICtrlCreateLabel("Vehicals",170,10,70,24)
                        GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                        GUICtrlSetFont(-1,14,500)
                    For $i = 0 To 2
                        $But[$i] = GUICtrlCreateLabel($vehicals[$i], 35, $bX, 100, 16)
                            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                            GUICtrlSetFont(-1,11,400)
                        $But2[$i] = GUICtrlCreateLabel($rooms[$i], 185, $bX, 100, 16)
                            GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
                            GUICtrlSetFont(-1,11,400)
                    $bX += 25
                    Next
                GUISwitch($guicontrols)
        $bX = 45
    For $i = 0 To 2
        $But[$i] = GUICtrlCreateCheckbox("", 15, $bX, 12, 12)
        focushandler($But[$i],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
        $But2[$i] = GUICtrlCreateCheckbox("", 165, $bX, 12, 12)
        focushandler($But2[$i],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab
        $bX += 25
    Next
        $pic = GUICtrlCreatePic("",100, $bX, 50, 25,$WS_TABSTOP)
        SetIcon($pic ,75, 25, 1,1, "Search",0)
        focushandler($pic,0,"picactions") ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab

EndFunc

func finalizewin()
    GUISetState(@SW_SHOW, $Gui)
    _drawborder($Gui,$gwidth,$gheight,"4","0x222222","0x444444","15") ;sets up the border on background
    _GuiRoundCorners($Gui,0, 0, 30, 30) ; makes the background have round corners
    GUISetControlsVisible($guicontrols) ;sets controls visible
    WinSetTrans($guicontrols,"",255)
    GUISetState(@SW_SHOW, $guicontrols)
    GUISwitch($guicontrols)
    _WinAPI_RedrawWindow($guicontrols,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
EndFunc
While 1
    Sleep(40)
    $msg = TrayGetMsg()
    if $msg=$TRAY_EVENT_PRIMARYDOWN and WinActive($guicontrols)=0 then WinActivate($guicontrols)

    hovered($guicontrols) ;sets the hover effects
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Background GUI Registered Message Handlers;;;;;;;;;;;;;
Func bckkeypress($hWnd, $msg, $wParam, $lParam)
    WinActivate($guicontrols)
EndFunc

Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($Gui,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
    ;_WinAPI_RedrawWindow($Gui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN

 Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT

;END;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Background GUI Registered Message Handlers;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;Tray events;;;;;;;;;;
func onautoitexit()
    if FileExists(@scriptDir & "\Trayicon.ico") then FileDelete(@scriptDir & "\Trayicon.ico")
    ;GUIDelete()
    DllCallbackFree($hFunc)
EndFunc

func exited()
    if FileExists(@scriptDir & "\Trayicon.ico") then FileDelete(@scriptDir & "\Trayicon.ico")
    GUIDelete()
    DllCallbackFree($hFunc)
    DllClose($hFunc)
    GUIDelete($guicontrols)
    GUIDelete($Gui)
    exit 0
EndFunc

func togontop()
    if $togontop=1 then
        WinSetOnTop($Gui,"",0)
        $togontop=0
    Else
        WinSetOnTop($Gui,"",1)
        $togontop=1
    EndIf
EndFunc

;END;;;;;;;;;;;;;;;;;Tray events;;;;;;;;;;

Func Drag() ;allows dragging of widget and click to exit
$t=clickexit()
if $t=1 then Exit
Local $PosDiff[2]
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ($Gui,"")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        While _IsPressed ("01", $dll)
            $MousePos = MouseGetPos ()
            WinMove ($Gui, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            WinMove ($guicontrols, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            $WinPos = WinGetPos ("","")
            Sleep (10)
        WEnd
        ExitLoop
        Sleep (10)
    WEnd
    ;_WinAPI_RedrawWindow($Gui,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
    _WinAPI_RedrawWindow($guicontrols,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW))
EndFunc

Func clickbuttons()
    Local $PosDiff[2]
    $MousePos = MouseGetPos ()
    $WinPos = WinGetPos ($guicontrols,"")
    $hovered=GUIGetCursorInfo($guicontrols)
 ;   ToolTip($hovered[4])
    for  $i = 1 to UBound($ctrlhwd)-1
        if IsString($ctrlhwd[$i][2]) and  GUICtrlGetHandle($hovered[4])= $ctrlhwd[$i][0] then
            Execute($ctrlhwd[$i][2]&"("&$ctrlhwd[$i][0] &")")
            return 1
        EndIf
    Next

    return 0
EndFunc

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

func hovered($gcon) ;anything that needs a hover effect has to be enacted here
if WinExists($guicontrols) then
$hov=GUIGetCursorInfo($gcon)
$amousepos=MouseGetPos()
$aguipos=WinGetPos($Gui)

    for $i =1 to UBound($ctrlhwd)-1
            if $onoff=0 and $hov[4]<>0 and IsString($ctrlhwd[$i][2]) and GUICtrlGetHandle($hov[4]) = $ctrlhwd[$i][0]Then
                $onoff=$hov[4]
                whichpic($hov[4],2)
            Elseif $hov[4]<>$onoff and $onoff<>0 and GUICtrlGetHandle($hov[4])<> $ctrlhwd[$i][0] then
                whichpic($onoff,0)
                $onoff=0
            EndIf
    next

if $infocal=0 and $amousepos[0]>=$aguipos[0] and $amousepos[1]>=$aguipos[1] and $amousepos[0]<=$aguipos[0]+$aguipos[2] and $amousepos[1]<=$aguipos[1]+$aguipos[3] then
        WinSetTrans($GUI,"",200)
        WinSetTrans($gcon,"",255)
        $infocal=1
        return
elseif $infocal=0 and WinActive($gcon)=1 then
        WinSetTrans($GUI,"",200)
        WinSetTrans($gcon,"",255)
        $infocal=1
        return

;   EndIf

elseif $amousepos[0]<$aguipos[0] or $amousepos[1]<$aguipos[1] or $amousepos[0]>$aguipos[0]+$aguipos[2] or $amousepos[1]>$aguipos[1]+$aguipos[3] then
    if $infocal=1 and not WinActive($gcon) and not WinActive($Gui) then
        WinSetTrans($GUI,"",100)
        WinSetTrans($gcon,"",100)
        $infocal=0
        Return

    EndIf
EndIf
EndIf
EndFunc

func no_tab() ;after control is created call this function to remove the tabstop if needed
    _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, _
    BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP)))
EndFunc

func whichpic($dlgctrl,$pressstate)

    for $h= 1 to UBound($picnames)-1

        if $picnames[$h][0]=$dlgctrl Then

            SetIcon($dlgctrl ,$picnames[$h][2], $picnames[$h][3], 1,1, $picnames[$h][1],$pressstate,1)
            return
        endif
    Next

EndFunc

Func InputHandler($hWnd, $iMsg, $wParam, $lParam)

    for $i =1 to UBound($ctrlhwd)-1
        If $hWnd = $ctrlhwd[$i][0] Then
            $hOldF = $hOldFunc[$i]
            $include=$ctrlhwd[$i][1]
            $testit=$ctrlhwd[$i][2]

        EndIf
    next
    If $iMsg = $WM_SETFOCUS Then
            _WinAPI_RedrawWindow($guicontrols,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW))
            if IsString($testit) and $actthebut=0 then
                    whichpic(_WinAPI_GetDlgCtrlID($hWnd) ,2) ; Selected
                    $actthebut=1
            ElseIf not IsString($testit) and $actthebut=1 then
                whichpic(_WinAPI_GetDlgCtrlID($wParam),0) ;back to normal
                $actthebut=0
            elseif IsString($testit) then
                    whichpic(_WinAPI_GetDlgCtrlID($hWnd),2) ; Selected
                    whichpic(_WinAPI_GetDlgCtrlID($wParam),0) ;back to normal
                    $actthebut=1
            EndIf
    elseIf $iMsg = 0x0008 Then
            if WinActive($Gui) Then
                    $t=clickexit()
                    if $t=1 then
                        $actthebut=0
                        exit
                    EndIf
            EndIf
    elseIf $wParam = $VK_RETURN then
        if _IsPressed("0D", $dll) and IsString($testit) then Execute($testit&"("&$hWnd&")")
    EndIf
    Return _WinAPI_CallWindowProc($hOldF, $hWnd, $iMsg, $wParam, $lParam)
EndFunc

func focushandler($Inpx,$inout, $funcname=0) ;Every control which has a tabstop must be sent to this function
    ; $Inpx = name of control, $inout = background gray when active, $executable on button press
    GUICtrlSetFont($Inpx,"",11,400,"Arial")
    $ctrlhwd[$focusnumber][0] = GUICtrlGetHandle($Inpx)
    $ctrlhwd[$focusnumber][1] = $inout
    $ctrlhwd[$focusnumber][2] = $funcname
    $hOldFunc[$focusnumber] = _WinAPI_GetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC)
    _WinAPI_SetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC, DllCallbackGetPtr($hFunc))

    $focusnumber=$focusnumber+1
    ReDim $ctrlhwd[ubound($ctrlhwd)+1][3]
    ReDim $hOldFunc[ubound($hOldFunc)+1]
EndFunc

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

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

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

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

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

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

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

Func GUISetControlsVisible($hWnd)
    Local $aM_Mask, $aCtrlPos, $aMask
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))
    For $i = 3 To $aLastID[0]
        $aCtrlPos = ControlGetPos($hWnd, '', $i)
        If Not IsArray($aCtrlPos) Then ContinueLoop

        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description::    Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                  $hwnd - Handle of GUI to work on
;                  $i_transcolor - Transparent color
;                  $Transparency - Set Transparancy of GUI
;                  $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                  Error: 0
;                   @error: 1 to 3 - Error from DllCall
;                   @error: 4 - Function did not succeed - use
;                               _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency, $isColorRef = False)

Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local Const $LWA_ALPHA = 0x2
Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error,0,0)
        Case $ret[0] = 0
            Return SetError(4,0,0)
        Case Else
            Return 1
    EndSelect
EndFunc;==>_API_SetLayeredWindowAttributes

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

func _drawborder($guiname,$gwt,$ght,$depth,$colour1,$colour2,$corner)
    _GDIPlus_Startup()
    $iC1 = StringReplace($colour1, "0x", "0xFF")
    $iC2 = StringReplace($colour2, "0x", "0xFF")
    Global $hDC = _WinAPI_GetDC($guiname)
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
    Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
    Global $hBrush1 = _GDIPlus_BrushCreateSolid($iC2)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
        _GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $gwt,$ght, $corner, $hBrush)
        _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $depth, $depth, $gwt-($depth*2)-2, $ght-($depth*2)-2, $corner,$hBrush1)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_BrushDispose($hBrush1)
        _WinAPI_ReleaseDC($guiname, $hDC)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
EndFunc
Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - ($iRadius * 2), $iY)
     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)

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

Func _GDIPlus_GraphicsDrawRoundRect2($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
    _GDIPlus_PenCreate($hPen)
    Local $hPath = _GDIPlus_GraphicsPathCreate()
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth-33, 3, 23,23,0, 360) ; this is the circle around the X
    _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)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X
        _GDIPlus_GraphicsPathAddLine($hPath,  $iX + $iWidth - ($iRadius * 2), $iY, $iX + $iWidth-29, 5)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -28, 7,$iX + $iWidth -22,13)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -16, 7,$iX + $iWidth -14,8)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -21,14,$iX + $iWidth -14,21)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -15,22,$iX + $iWidth -22,16)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -28, 22,$iX + $iWidth-29 ,21)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth -23, 15,$iX + $iWidth-29 ,8)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth-29 ,8,$iX + $iWidth - ($iRadius * 2), $iY)
        ;;;;;;;;;;;;;;;;;;;;;;;;;Script for the X ends
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))
    _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
        _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)
    _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _settrayicon($iW, $iH)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
    _GDIPlus_Startup()
    ;Buffer
    $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xFFFFFF, $iW, $iH)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    ;Gradient Background - At the top Maroon 50% transparency to fully opaque black at bottom
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect( 0, 0, $iW, $iH, $a_Factors, $a_Positions, 0x80800040, 0xFF000000,1,0)
    GDIPlus_SetLineGammaCorrection($hBrushLin);, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin)
    ; Draw text
    $sText = @MDAY
    $hBrush1 = _GDIPlus_BrushCreateSolid(0xFFBBBBBB)
    $hFormat = _GDIPlus_StringFormatCreate(0)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 16, 1, 3)
    $tLayout = _GDIPlus_RectFCreate(0, 4, 32,32) ; increase 300 to 380 for one line of text
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
   _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush1)

$hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hImage)
; Create an ico file from the image
_CreateIconFileFromHICON($hIcon, @scriptDir & "\trayicon.ico")
; Destroy the HICON now I've finished with it.
_WinAPI_DestroyIcon($hIcon)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TraySetIcon(@scriptDir & "\Trayicon.ico")
    _GDIPlus_ImageDispose($hImage)

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
     _GDIPlus_BrushDispose($hBrushLin)

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>PicSetGraphics

Func _CreateIconFileFromHICON($hIcon, $sOutIcon)
    Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO
    $sIco = "0x000001000100"
    $sBmp = "28000000"
    $aInfo = _WinAPI_GetIconInfo($hIcon)
    $hCDC = _WinAPI_CreateCompatibleDC(0)
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))
    _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0)
    $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4))
    $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"))) & _RB(Hex(DllStructGetData($tBI, "Height") * 2)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000"
    $iSz = DllStructGetData($tBI, "SizeImage")
     $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits))
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
        $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next
    $tBits = 0
    $tBI = 0
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))
    _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0)
    _WinAPI_DeleteDC($hCDC)
    $iSz += DllStructGetData($tBI, "SizeImage")
    $sBmp &= _RB(Hex($iSz)) & "00000000000000000000000000000000"
    $sIco &= _RB(Hex($iSz + 40)) & _RB(Hex("22")) & $sBmp & $sBD
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits))
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
        $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next
    ; Write the icon to a file.
    $FO = FileOpen($sOutIcon, 18)
    FileWrite($sOutIcon, Binary($sIco))
    FileClose($FO)
    ; Clear the structs
    $tBits = 0
    $tBI = 0
EndFunc   ;==>_CreateIconFileFromHICON

; Reverse Byte String
Func _RB($sByte)
    Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
    For $i = UBound($aX) - 1 To 0 Step -1
        $sX &= $aX[$i]
    Next
    Return $sX
EndFunc   ;==>_RB

Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    Local $hIcon
    $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($hIcon[0], 0, $hIcon[2])
EndFunc   ;==>_GDIPlus_BitmapCreateHICONFromBitmap


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;guictrl onevent handlers
func clseguictrlwin($control)
    GUIDelete($guicontrols)
    guidelete($Gui)
    $gwidth=300
    $gheight=160
    bckwin()
    window2()
    finalizewin()
EndFunc

Func picactions($control)
whichpic(_WinAPI_GetDlgCtrlID($control),1)
sleep(200)
    whichpic(_WinAPI_GetDlgCtrlID($control) ,2)
    ToolTip("")
    exit 0
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Edited by picea892
  • 1 month later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...