#include <WinAPI.au3>
#include <WinAPIShellEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <Misc.au3>

Local $_Ribbon[0][14]
Local $_RibbonTabs[1][14]
Local $_RibbonTabsItem[0][14]
Local $_RibbonGrandButtons[1][14]
Local $_RibbonSmallButtons[1][14]
Local $_RibbonCtrlIndex[0][12]
Local $_BarIconDll = @ScriptDir & "\bar.Dll"
Local $SmallIcons_DLL = @ScriptDir & '\SmallIcons.dll'
Local $GrandIcons_DLL = @ScriptDir & '\grandIcons.dll'
Local $VisTabId = ""

Local $Bar_BG_Color_Silver = 0xD0D4DD
Local $Bar_Bottom_Line_Color_Silver = 0xA9A9A9
Local $Bar_TabItem_Label_Color_Silver = 0x4C535C
Local $Bar_Tab_Label_Color_Silver = 0x4C535C
Local $Bar_Tab_Label_HoverColor_Silver = 0x4C535C
Local $Bar_BG_Color_Black = 0x535353
Local $Bar_Bottom_Line_Color_Black = 0x767676
Local $Bar_TabItem_Label_Color_Black = 0x000000
Local $Bar_Tab_Label_Color_Black = 0xffffff
Local $Bar_Tab_Label_HoverColor_Black = 0x000000
Local $Bar_BG_Color_Blue = 0xBFDBFF
Local $Bar_Bottom_Line_Color_Blue = 0x5585BA
Local $Bar_TabItem_Label_Color_Blue = 0x15428B
Local $Bar_Tab_Label_Color_Blue = 0x15428B
Local $Bar_Tab_Label_HoverColor_Blue = 0x15428B
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_GetMsg
; Description ...: The Same As GUIGetMsg() but enables ribbon hover and Ribbon Handles
; Syntax ........: _GUICtrlRibbon_GetMsg()
; Parameters ....: None
; Return values .: None
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_GetMsg()
	$GUIGetMsg = GUIGetMsg()
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $GUIGetMsg = $_RibbonCtrlIndex[$i][9] Then $GUIGetMsg = 0
		$cMsg = MouseGetPos()
		$cPos = ControlGetPos($_RibbonCtrlIndex[$i][1], "", GUICtrlGetHandle($_RibbonCtrlIndex[$i][0]))
		If @error Then Return $GUIGetMsg
		$tp = DllStructCreate("int X;int Y")
		DllStructSetData($tp, "X", $cPos[0])
		DllStructSetData($tp, "Y", $cPos[1])
		$fPos = _WinAPI_ClientToScreen($_RibbonCtrlIndex[$i][1], $tp)
		$cPos[0] = DllStructGetData($tp, "X")
		$cPos[1] = DllStructGetData($tp, "Y")
		If Not IsArray($cMsg) Then Return $GUIGetMsg
		If $cMsg[0] > ($cPos[0]) And _
				$cMsg[0] < ($cPos[0] + $cPos[2]) And _
				$cMsg[1] > ($cPos[1]) And _
				$cMsg[1] < ($cPos[1] + $cPos[3]) Then
			If $_RibbonCtrlIndex[$i][7] Then
				__GUICtrlRibbon_ShowCtrl($_RibbonCtrlIndex[$i][2])
				__GUICtrlRibbon_ShowCtrl($_RibbonCtrlIndex[$i][3])
				__GUICtrlRibbon_ShowCtrl($_RibbonCtrlIndex[$i][4])
				$_RibbonCtrlIndex[$i][6] = True
				If _IsPressed(01) Then
					If WinGetHandle("[active]") = $_RibbonCtrlIndex[$i][1] Or WinGetHandle("[active]") = _WinAPI_GetParent($_RibbonCtrlIndex[$i][1]) Then
						$GUIGetMsg = "R" & $_RibbonCtrlIndex[$i][5]
					EndIf
				EndIf
			EndIf
			If _IsPressed(02) Then
				If WinGetHandle("[active]") = $_RibbonCtrlIndex[$i][1] Or WinGetHandle("[active]") = _WinAPI_GetParent($_RibbonCtrlIndex[$i][1]) Then
					$GUIGetMsg = $_RibbonCtrlIndex[$i][10]
				EndIf
			EndIf
		ElseIf $_RibbonCtrlIndex[$i][6] Then
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][2])
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][3])
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][4])
			$_RibbonCtrlIndex[$i][6] = False
		EndIf
	Next
	Return String($GUIGetMsg)
EndFunc   ;==>_GUICtrlRibbon_GetMsg
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_Create
; Description ...: Creates Ribbbon BackGround and sets up Info
; Syntax ........: _GUICtrlRibbon_Create($hWnd [, $Style = 'blue' [, $Width = -1 [, $Bar_Offset_X = 5 [, $Bar_Offset_Y = 5]]]])
; Parameters ....: $hWnd                - handle to the gui to create a ribbon on.
;                  $Style               - [optional] The Style of the the ribbon. styles include black blue and silver. Default is 'blue'.
;                  $Width               - [optional] Width of the ribbon . Default is the size of the window.
;                  $Bar_Offset_X        - [optional] How far the offset should be going left. Default is 5.
;                  $Bar_Offset_Y        - [optional] How far the offset should be going down. Default is 5.
; Return values .: Success              - A Ribbon Handle usually with the prefix R
;                  Failure              - Returns 0 sets @error
;                                       - @error
;                                         |0 = No Error
;                                         |1 $hWnd is not valid
;                                         |2 $Style is not valid
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_Create($hWnd, $Style = 'blue', $Width = -1, $Bar_Offset_X = 5, $Bar_Offset_Y = 5)
	Local $hWndPos = WinGetClientSize($hWnd)
	If @error Then Return SetError(1, 0, 0)
	If $Width <> -1 Then $hWndPos[0] = $Width
	GUIStartGroup($hWnd)
	;GUIStartGroup($hWnd)
	Local $ICO1, $ICO2, $ICO3, $BARBK, $BARL
	Switch $Style
		Case 'blue'
			$BARBK = $Bar_BG_Color_Blue
			$BARL = $Bar_Bottom_Line_Color_Blue
			$BTLC = $Bar_Tab_Label_Color_Blue
			$BTLHC = $Bar_TabItem_Label_Color_Blue
		Case 'black'
			$BARBK = $Bar_BG_Color_Black
			$BARL = $Bar_Bottom_Line_Color_Black
			$BTLC = $Bar_Tab_Label_Color_Black
			$BTLHC = $Bar_TabItem_Label_Color_Black
		Case 'silver'
			$BARBK = $Bar_BG_Color_Silver
			$BARL = $Bar_Bottom_Line_Color_Silver
			$BTLC = $Bar_Tab_Label_Color_Silver
			$BTLHC = $Bar_TabItem_Label_Color_Silver
		Case Else
			Return SetError(2, 0, 0)
	EndSwitch
	Local $i = UBound($_Ribbon)
	ReDim $_Ribbon[$i + 1][14]
	$_Ribbon[$i][0] = $hWnd
	$_Ribbon[$i][1] = $Style
	$_Ribbon[$i][2] = GUICtrlCreateLabel('', 0, 0, $hWndPos[0], 130 + $Bar_Offset_Y)
	GUICtrlSetBkColor(-1, $BARBK)
	$_Ribbon[$i][3] = GUICtrlCreateLabel('', 0, 130 + $Bar_Offset_Y, $hWndPos[0], 1)
	GUICtrlSetBkColor(-1, $BARL)
	$_Ribbon[$i][4] = $BTLC
	$_Ribbon[$i][5] = $BTLHC
	$_Ribbon[$i][7] = $Bar_Offset_X
	$_Ribbon[$i][8] = $Bar_Offset_Y
	$_Ribbon[$i][9] = $Bar_Offset_X
	$_Ribbon[$i][10] = $Bar_Offset_Y + 30
	$_Ribbon[$i][11] = False
	$_Ribbon[$i][12] = $hWndPos[0]
	Return $i
EndFunc   ;==>_GUICtrlRibbon_Create
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_CreateTab
; Description ...: Creates A Tab On the ribbon
; Syntax ........: _GUICtrlRibbon_CreateTab($hRibbon, $name)
; Parameters ....: $hRibbon             - The handle of the ribbon to make the tab.
;                  $name                - name of the tab.
; Return values .: Success              - Returns a Tab handle (usually with the prefix R
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |0 = No error
;                                         |1 = Invalid ribbon handle
;                                         |2 = ???
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_CreateTab($hRibbon, $name)
	If UBound($_Ribbon) < $hRibbon Then Return SetError(1, 0, 0)
	$hWndPos = WinGetClientSize($_Ribbon[$hRibbon][0])
	If @error Then SetError(2, 0, 0)
	Switch $_Ribbon[$hRibbon][1]
		Case 'blue'
			$ICO1 = $_Ribbon[$hRibbon][1] & "01"
			$ICO2 = $_Ribbon[$hRibbon][1] & "07"
			$ICO3 = $_Ribbon[$hRibbon][1] & "05"
			$ICO4 = $_Ribbon[$hRibbon][1] & "08"
			$ICO5 = $_Ribbon[$hRibbon][1] & "06"
			$ICO6 = $_Ribbon[$hRibbon][1] & "09"
			$ICO7 = $_Ribbon[$hRibbon][1] & "03-1"
		Case 'black'
			$ICO1 = $_Ribbon[$hRibbon][1] & "01"
			$ICO2 = $_Ribbon[$hRibbon][1] & "07"
			$ICO3 = $_Ribbon[$hRibbon][1] & "05"
			$ICO4 = $_Ribbon[$hRibbon][1] & "08"
			$ICO5 = $_Ribbon[$hRibbon][1] & "06"
			$ICO6 = $_Ribbon[$hRibbon][1] & "09"
			$ICO7 = $_Ribbon[$hRibbon][1] & "03-1"
		Case 'silver'
			$ICO1 = $_Ribbon[$hRibbon][1] & "01"
			$ICO2 = $_Ribbon[$hRibbon][1] & "07"
			$ICO3 = $_Ribbon[$hRibbon][1] & "05"
			$ICO4 = $_Ribbon[$hRibbon][1] & "08"
			$ICO5 = $_Ribbon[$hRibbon][1] & "06"
			$ICO6 = $_Ribbon[$hRibbon][1] & "09"
			$ICO7 = $_Ribbon[$hRibbon][1] & "03-1"
		Case Else
			Return SetError(3, 0, 0)
	EndSwitch
	$i = UBound($_RibbonTabs)
	__GUICtrlRibbon_Bump($i)
	ReDim $_RibbonTabs[$i + 1][14]
	$_RibbonTabs[$i][0] = $hRibbon
	$wid = StringLen($name)*5+20
	$_RibbonTabs[$i][1] = GUICreate("", $hWndPos[0] - ($_Ribbon[$hRibbon][7] * 2), 92, -1, -1, $WS_POPUP)
	__GUICtrlRibbon_DrawRibbon($hRibbon)
	GUICtrlCreateIcon($_BarIconDll, $ICO7, $_Ribbon[$hRibbon][9] + 2, 0, $wid + 8, 92)
	_WinAPI_SetParent($_RibbonTabs[$i][1], $_Ribbon[$hRibbon][0])
	GUIStartGroup($_Ribbon[$hRibbon][0])
	$_RibbonTabs[$i][3] = GUICtrlCreateIcon($_BarIconDll, $ICO1, $_Ribbon[$hRibbon][9] + 5, $_Ribbon[$hRibbon][8] + 8, 6, 23)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][4] = GUICtrlCreateIcon($_BarIconDll, $ICO2, $_Ribbon[$hRibbon][9] + 5, $_Ribbon[$hRibbon][8] + 8, 6, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][5] = GUICtrlCreateIcon($_BarIconDll, $ICO3, $_Ribbon[$hRibbon][9] + 11, $_Ribbon[$hRibbon][8] + 8, $wid, 23)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][6] = GUICtrlCreateIcon($_BarIconDll, $ICO4, $_Ribbon[$hRibbon][9] + 11, $_Ribbon[$hRibbon][8] + 8, $wid, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][7] = GUICtrlCreateIcon($_BarIconDll, $ICO5, $_Ribbon[$hRibbon][9] + 11 + $wid, $_Ribbon[$hRibbon][8] + 8, 6, 23)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][8] = GUICtrlCreateIcon($_BarIconDll, $ICO6, $_Ribbon[$hRibbon][9] + 11 + $wid, $_Ribbon[$hRibbon][8] + 8, 6, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonTabs[$i][9] = GUICtrlCreateLabel($name, $_Ribbon[$hRibbon][9] +4, $_Ribbon[$hRibbon][8] + 7, $wid + 16, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE))
	$_RibbonTabs[$i][10] = 5
	GUICtrlSetBkColor(-1, -2)
	GUICtrlSetColor(-1, $_Ribbon[$hRibbon][4])
	__GUICtrlRibbon_RegHover($_RibbonTabs[$i][9], $_Ribbon[$hRibbon][0], $_RibbonTabs[$i][4], $_RibbonTabs[$i][6], $_RibbonTabs[$i][8], $i, $hRibbon)
	$_Ribbon[$hRibbon][9] += 17 + $wid
	WinMove($_RibbonTabs[$i][1], '', $_Ribbon[$hRibbon][8], $_Ribbon[$hRibbon][10])
	_WinAPI_RedrawWindow($_RibbonTabs[$i][1])
	Return String("R" & $i)
EndFunc   ;==>_GUICtrlRibbon_CreateTab
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_CreateTabItem
; Description ...: Creates a Ribbon Tab Item
; Syntax ........: _GUICtrlRibbon_CreateTabItem($hRibbonTab, $Name, $Width)
; Parameters ....: $hRibbonTab          - Handle to the tab to draw the item on.
;                  $Name                - Name of the item group.
;                  $Width               - Width of tab item.
; Return values .: Success              - Returns a tab item handle
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid  tab handle
;                                         |2 = ???
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_CreateTabItem($hRibbonTab, $Name, $Width)
	$hRibbonTab = StringReplace($hRibbonTab, "R", "")
	If UBound($_RibbonTabs) < $hRibbonTab Then Return SetError(1, 0, 0)
	GUIStartGroup($_RibbonTabs[$hRibbonTab][1])
	Switch $_Ribbon[$_RibbonTabs[$hRibbonTab][0]][1]
		Case 'blue'
			$ICO1 = "BLUE10"
			$ICO2 = "BLUE11"
			$ICO3 = "BLUE12"
		Case 'black'
			$ICO1 = "BLACK10"
			$ICO2 = "BLACK11"
			$ICO3 = "BLACK12"
		Case 'silver'
			$ICO1 = "SILVER10"
			$ICO2 = "SILVER11"
			$ICO3 = "SILVER12"
		Case Else
			Return SetError(2, 0, 0)
	EndSwitch
	$i = UBound($_RibbonTabsItem)
	ReDim $_RibbonTabsItem[$i + 1][14]
	$_RibbonTabsItem[$i][0] = $hRibbonTab
	$_RibbonTabsItem[$i][1] = $name
	$_RibbonTabsItem[$i][2] = GUICtrlCreateIcon($_BarIconDll, $ICO1, $_RibbonTabs[$hRibbonTab][10], 3, 3, 85)
	$_RibbonTabsItem[$i][3] = GUICtrlCreateIcon($_BarIconDll, $ICO2, $_RibbonTabs[$hRibbonTab][10] + 3, 3, $Width, 85)
	$_RibbonTabsItem[$i][4] = GUICtrlCreateIcon($_BarIconDll, $ICO3, $_RibbonTabs[$hRibbonTab][10] + 3 + $Width, 3, 3, 85)
	$_RibbonTabsItem[$i][5] = GUICtrlCreateLabel($name, $_RibbonTabs[$hRibbonTab][10] + 3, 66, $Width, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
	$_RibbonTabsItem[$i][6] = $_RibbonTabs[$hRibbonTab][10] + 5
	$_RibbonTabsItem[$i][7] = $_RibbonTabs[$hRibbonTab][10] + 5
	$_RibbonTabsItem[$i][8] = False
	$_RibbonTabsItem[$i][9] = False
	$_RibbonTabsItem[$i][10] = False
	GUICtrlSetBkColor(-1, -2)
	GUICtrlSetColor(-1, $_Ribbon[$_RibbonTabs[$hRibbonTab][0]][4])
	$_RibbonTabs[$hRibbonTab][10] += $Width + 11
	GUIStartGroup($_Ribbon[$_RibbonTabs[$hRibbonTab][0]][0])
	Return $i
EndFunc   ;==>_GUICtrlRibbon_CreateTabItem
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_CreateGrandButton
; Description ...: Creates a Grand Button (Large Ribbon Button on a ribbon
; Syntax ........: _GUICtrlRibbon_CreateGrandButton($hRibbonTabItem, $IcoDll, $IconName [, $Text = '' [, $GB_Width = 52 [, $GB_DropDown = False]]])
; Parameters ....: $hRibbonTabItem      - The handle to the tab item value.
;                  $IcoDll              - Icon or Dll containing icon. if is invalid it will use grandicons.dll
;                  $IconName            - icon number.
;                  $Text                - [optional] Button text. Default is ''.
;                  $GB_Width            - [optional] Width of button. Default is 52.
;                  $GB_DropDown         - [optional] Specifies wheather icon has a little arrow. Default is False.
; Return values .: Success              - Returns a grand button handle usually has prefix of R
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid Tab item handle
;                                         |2 = ???
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_CreateGrandButton($hRibbonTabItem, $IcoDll, $IconName, $Text = '', $GB_Width = 52, $GB_DropDown = False)
	If UBound($_RibbonTabsItem) < $hRibbonTabItem Then Return SetError(1, 0, 0)
	If Not FileExists($IcoDll) Then $IcoDll = $GrandIcons_DLL
	If $GB_Width = "" Or StringInStr($GB_Width, "-") Or IsNumber($GB_Width) Then $GB_Width = 52
	Switch $_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][1]
		Case 'blue'
			$ICO1 = "BLUE13"
			$ICO2 = "BLUE14"
			$ICO3 = "BLUE15"
		Case 'black'
			$ICO1 = "BLACK13"
			$ICO2 = "BLACK14"
			$ICO3 = "BLACK15"
		Case 'silver'
			$ICO1 = "SILVER13"
			$ICO2 = "SILVER14"
			$ICO3 = "SILVER15"
		Case Else
			Return SetError(2, 0, 0)
	EndSwitch
	GUIStartGroup($_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][1])
	$i = UBound($_RibbonGrandButtons)
	__GUICtrlRibbon_Bump($i)
	ReDim $_RibbonGrandButtons[$i + 1][14]
	$_RibbonGrandButtons[$i][0] = $hRibbonTabItem
	$_RibbonGrandButtons[$i][1] = $Text
	$_RibbonGrandButtons[$i][2] = $IconName
	$_RibbonGrandButtons[$i][3] = $IcoDll
	;ConsoleWrite(@CR&"Drawing icon on "&$hRibbonTabItem&"   at : "& $_RibbonTabsItem[$hRibbonTabItem][6]&","& 5&" With Width and height of : "& $GB_Width &","& 65)
	$_RibbonGrandButtons[$i][4] = GUICtrlCreateIcon($_BarIconDll, $ICO1, $_RibbonTabsItem[$hRibbonTabItem][6], 5, 3, 65)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonGrandButtons[$i][5] = GUICtrlCreateIcon($_BarIconDll, $ICO2, $_RibbonTabsItem[$hRibbonTabItem][6] + 3, 5, $GB_Width - 6, 65)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonGrandButtons[$i][6] = GUICtrlCreateIcon($_BarIconDll, $ICO3, $_RibbonTabsItem[$hRibbonTabItem][6] + $GB_Width - 3, 5, 3, 65)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonGrandButtons[$i][7] = GUICtrlCreateLabel($Text, $_RibbonTabsItem[$hRibbonTabItem][6] + 3, 41, $GB_Width - 6, 27, $SS_CENTER)
	GUICtrlSetBkColor(-1, -2)
	GUICtrlSetColor(-1, $_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][5])
	GUICtrlSetFont(-1, 8.5)
	$_RibbonGrandButtons[$i][8] = GUICtrlCreatePic('', $_RibbonTabsItem[$hRibbonTabItem][6] + ($GB_Width / 2) - 16, 7, 32, 32)
	__GUICtrlRibbon_SetIconAlpha($_RibbonGrandButtons[$i][8], $IcoDll, $IconName - 1, 32, 32)
	If $GB_DropDown Then
		$_RibbonGrandButtons[$i][9] = GUICtrlCreateLabel('q', $_RibbonTabsItem[$hRibbonTabItem][6] + 3, 60, $GB_Width - 6, 27, $SS_CENTER)
		GUICtrlSetBkColor(-1, -2)
		GUICtrlSetColor(-1, $_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][5])
		GUICtrlSetFont(-1, 5, 400, 0, 'Wingdings 3')
	EndIf
	$_RibbonGrandButtons[$i][10] = GUICtrlCreateLabel('', $_RibbonTabsItem[$hRibbonTabItem][6], 5, $GB_Width, 65)
	GUICtrlSetBkColor(-1, -2)
	__GUICtrlRibbon_RegHover($_RibbonGrandButtons[$i][10], $_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][1], $_RibbonGrandButtons[$i][4], $_RibbonGrandButtons[$i][5], $_RibbonGrandButtons[$i][6], $i,$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0])
	$_RibbonTabsItem[$hRibbonTabItem][6] += $GB_Width
	$_RibbonTabsItem[$hRibbonTabItem][7] = $_RibbonTabsItem[$hRibbonTabItem][6]
	$_RibbonTabsItem[$hRibbonTabItem][8] = False
	$_RibbonTabsItem[$hRibbonTabItem][9] = False
	$_RibbonTabsItem[$hRibbonTabItem][10] = False
	GUIStartGroup($_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][0])
	Return String("R" & $i)
EndFunc   ;==>_GUICtrlRibbon_CreateGrandButton
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_CreateSmallButton
; Description ...: Creates a SmallButton
; Syntax ........: _GUICtrlRibbon_CreateSmallButton($hRibbonTabItem, $IcoDll, $IconName [, $level = 1 [, $Text = '' [, $SB_Width = 25]]])
; Parameters ....: $hRibbonTabItem      - The handle of the tab item.
;                  $IcoDll              - Icon or Dll containing icon. if is invalid it will use smallicons.dll
;                  $IconName            - icon number.
;                  $level               - [optional] Level to make small button on. range of 1-3 . Default is 1.
;                  $Text                - [optional] Button text. Default is ''.
;                  $SB_Width            - [optional] Width of button. Default is 25.
; Return values .: Success              - Returns a small button handle usually has prefix of R
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid Tab item handle
;                                         |2 = ???
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_CreateSmallButton($hRibbonTabItem, $IcoDll, $IconName, $level = 1, $Text = '', $SB_Width = 25)
	If Not FileExists($IcoDll) Then $IcoDll = $SmallIcons_DLL
	If UBound($_RibbonTabsItem) < $hRibbonTabItem Then Return SetError(1, 0, 0)
	If $level < 0 Or $level > 3 Then Return SetError(3, 0, 0)
	If Not IsNumber($level) Then $level = 1
	Switch $_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][1]
		Case 'blue'
			$ICO1 = "BLUE16"
			$ICO2 = "BLUE17"
			$ICO3 = "BLUE18"
		Case 'black'
			$ICO1 = "BLACK16"
			$ICO2 = "BLACK17"
			$ICO3 = "BLACK18"
		Case 'silver'
			$ICO1 = "SILVER16"
			$ICO2 = "SILVER17"
			$ICO3 = "SILVER18"
		Case Else
			Return SetError(2, 0, 0)
	EndSwitch
	$i = UBound($_RibbonSmallButtons)
	__GUICtrlRibbon_Bump($i)
	$y = 8 + (($level - 1) * 22)
	Switch $level
		Case 1
			If $_RibbonTabsItem[$hRibbonTabItem][8] Then
				$_RibbonTabsItem[$hRibbonTabItem][8] = False
				$_RibbonTabsItem[$hRibbonTabItem][9] = False
				$_RibbonTabsItem[$hRibbonTabItem][10] = False
				$_RibbonTabsItem[$hRibbonTabItem][7] = $_RibbonTabsItem[$hRibbonTabItem][6]
			Else
				$_RibbonTabsItem[$hRibbonTabItem][8] = True
			EndIf
		Case 2
			If $_RibbonTabsItem[$hRibbonTabItem][9] Then
				$_RibbonTabsItem[$hRibbonTabItem][8] = False
				$_RibbonTabsItem[$hRibbonTabItem][9] = False
				$_RibbonTabsItem[$hRibbonTabItem][10] = False
				$_RibbonTabsItem[$hRibbonTabItem][7] = $_RibbonTabsItem[$hRibbonTabItem][6]
			Else
				$_RibbonTabsItem[$hRibbonTabItem][9] = True
			EndIf
		Case 3
			$_RibbonTabsItem[$hRibbonTabItem][8] = False
			$_RibbonTabsItem[$hRibbonTabItem][9] = False
			$_RibbonTabsItem[$hRibbonTabItem][10] = False
	EndSwitch
	GUIStartGroup($_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][1])
	ReDim $_RibbonSmallButtons[$i + 1][14]
	$_RibbonSmallButtons[$i][0] = $hRibbonTabItem
	$_RibbonSmallButtons[$i][1] = GUICtrlCreateIcon($_BarIconDll, $ICO1, $_RibbonTabsItem[$hRibbonTabItem][7], $y - 3, 3, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonSmallButtons[$i][2] = GUICtrlCreateIcon($_BarIconDll, $ICO2, $_RibbonTabsItem[$hRibbonTabItem][7] + 3, $y - 3, $SB_Width - 3, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonSmallButtons[$i][3] = GUICtrlCreateIcon($_BarIconDll, $ICO3, $_RibbonTabsItem[$hRibbonTabItem][7] + $SB_Width - 3, $y - 3, 3, 22)
	GUICtrlSetState(-1, $GUI_HIDE)
	$_RibbonSmallButtons[$i][4] = GUICtrlCreatePic('', $_RibbonTabsItem[$hRibbonTabItem][7] + 3, $y, 16, 16)
	__GUICtrlRibbon_SetIconAlpha($_RibbonSmallButtons[$i][4], $IcoDll, $IconName - 1, 16, 16)
	$_RibbonSmallButtons[$i][5] = GUICtrlCreateLabel($Text, $_RibbonTabsItem[$hRibbonTabItem][7] + 23, $y + 1, $SB_Width - 23, 14)
	GUICtrlSetBkColor(-1, -2)
	GUICtrlSetColor(-1, $_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][5])
	GUICtrlSetFont(-1, 8.5)
	$_RibbonSmallButtons[$i][6] = GUICtrlCreateLabel('', $_RibbonTabsItem[$hRibbonTabItem][7], $y - 3, $SB_Width, 22)
	GUICtrlSetBkColor(-1, -2)
	__GUICtrlRibbon_RegHover($_RibbonSmallButtons[$i][6], $_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][1], $_RibbonSmallButtons[$i][1], $_RibbonSmallButtons[$i][2], $_RibbonSmallButtons[$i][3], $i,$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0])
	If $level = 3 Then $_RibbonTabsItem[$hRibbonTabItem][7] = $_RibbonTabsItem[$hRibbonTabItem][6]
	If $_RibbonTabsItem[$hRibbonTabItem][7] + $SB_Width + 2 > $_RibbonTabsItem[$hRibbonTabItem][6] Then
		$_RibbonTabsItem[$hRibbonTabItem][6] = $_RibbonTabsItem[$hRibbonTabItem][7] + $SB_Width + 2
	EndIf
	GUIStartGroup($_Ribbon[$_RibbonTabs[$_RibbonTabsItem[$hRibbonTabItem][0]][0]][0])
	Return String("R" & $i)
EndFunc   ;==>_GUICtrlRibbon_CreateSmallButton
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_CreateContextMenu
; Description ...: Creates a context menu on a button or tab name
; Syntax ........: _GUICtrlRibbon_CreateContextMenu($hRibbonButton)
; Parameters ....: $hRibbonButton       - A handle of ribbon tab or button.
; Return values .: Success              - Returns a contextmenu handle
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid item handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_CreateContextMenu($hRibbonButton)
	$hRibbonButton = StringReplace($hRibbonButton, "R", "")
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][5] = $hRibbonButton Then
			$_RibbonCtrlIndex[$i][9] = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
			Return $_RibbonCtrlIndex[$i][9]
		EndIf
	Next
	Return SetError(1,0,0)
EndFunc   ;==>_GUICtrlRibbon_CreateContextMenu
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_GetLeftClkCtrlHandle
; Description ...: gets the handle of a buttons or tabs leftclick event
; Syntax ........: _GUICtrlRibbon_GetLeftClkCtrlHandle($hRibbonButton)
; Parameters ....: $hRibbonButton       - Thr item handle.
; Return values .: Success              - Returns a grand button handle usually has prefix of R
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid Tab item handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_GetLeftClkCtrlHandle($hRibbonButton)
	$hRibbonButton = StringReplace($hRibbonButton, "R", "")
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][5] = $hRibbonButton Then Return $_RibbonCtrlIndex[$i][10]
	Next
	Return SetError(1, 0, 0)
EndFunc   ;==>_GUICtrlRibbon_GetLeftClkCtrlHandle
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_RestoreContextMenu
; Description ...: Caulses Context menu to pop up were item is
; Syntax ........: _GUICtrlRibbon_RestoreContextMenu($hContextMenu)
; Parameters ....: $hContextMenu        - context handle.
; Return values .: None
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_RestoreContextMenu($hContextMenu)
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][9] = $hContextMenu Then
			$cPos = ControlGetPos($_RibbonCtrlIndex[$i][1], '', $_RibbonCtrlIndex[$i][0])
			$hMenu = GUICtrlGetHandle($hContextMenu)
			$stPoint = DllStructCreate("int;int")
			$tp = DllStructCreate("int X;int Y")
			DllStructSetData($tp, "X", $cPos[0])
			DllStructSetData($tp, "Y", $cPos[1])
			$fPos = _WinAPI_ClientToScreen($_RibbonCtrlIndex[$i][1], $tp)
			$cPos[0] = DllStructGetData($tp, "X")
			$cPos[1] = DllStructGetData($tp, "Y") + $cPos[3]
			DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $cPos[0], "int", $cPos[1], "hwnd", $_RibbonCtrlIndex[$i][1], "ptr", 0)
			Return 1
		EndIf
	Next
EndFunc   ;==>_GUICtrlRibbon_RestoreContextMenu
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_GetButtonCoord
; Description ...:
; Syntax ........: _GUICtrlRibbon_GetButtonCoord($hRibbonButton)
; Parameters ....: $hRibbonButton       - the item handle.
; Return values .: Success              - Returns an array containing size and possition of the item
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid Tab item handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_GetButtonCoord($hRibbonButton)
	$hRibbonButton = StringReplace($hRibbonButton,"R","")
		For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][5] = $hRibbonButton Then
			$cPos = ControlGetPos($_RibbonCtrlIndex[$i][1], '', $_RibbonCtrlIndex[$i][0])
			$stPoint = DllStructCreate("int;int")
			$tp = DllStructCreate("int X;int Y")
			DllStructSetData($tp, "X", $cPos[0])
			DllStructSetData($tp, "Y", $cPos[1])
			$fPos = _WinAPI_ClientToScreen($_RibbonCtrlIndex[$i][1], $tp)
			$cPos[0] = DllStructGetData($tp, "X")
			$cPos[1] = DllStructGetData($tp, "Y")
			Return $cPos
		EndIf
	Next
	Return SetError(1,0,0)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_RestoreContextMenuAtMouse
; Description ...: creates context at current mouse coordonates.
; Syntax ........: _GUICtrlRibbon_RestoreContextMenuAtMouse($hContextMenu)
; Parameters ....: $hContextMenu        - The item handle.
; Return values .: None
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_RestoreContextMenuAtMouse($hContextMenu)
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][9] = $hContextMenu Then
			$cPos = MouseGetPos()
			$hMenu = GUICtrlGetHandle($hContextMenu)
			DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $cPos[0], "int", $cPos[1], "hwnd", $_RibbonCtrlIndex[$i][1], "ptr", 0)
			Return 1
		EndIf
	Next
EndFunc   ;==>_GUICtrlRibbon_RestoreContextMenu
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_RestoreTab
; Description ...: Restores a tab
; Syntax ........: _GUICtrlRibbon_RestoreTab($hRibbonTab)
; Parameters ....: $hRibbonTab          - The tab handle.
; Return values .: Success              - Returns 1
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid Tab item handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_RestoreTab($hRibbonTab)
	$hRibbonTab = StringReplace($hRibbonTab, "R", "")
	If UBound($_RibbonTabs) < $hRibbonTab Then Return SetError(1, 0, 0)
	If $_Ribbon[$_RibbonTabs[$hRibbonTab][0]][11] Then Return 0
	$act = WinGetHandle("[Active]")
	GUISetState(@SW_SHOW, $_RibbonTabs[$hRibbonTab][1])
	If $_RibbonTabs[$VisTabId][1] <> "" Then
		GUISetState(@SW_HIDE, $_RibbonTabs[$VisTabId][1])
	EndIf
	__GUICtrlRibbon_HideCtrl($_RibbonTabs[$VisTabId][3])
	__GUICtrlRibbon_HideCtrl($_RibbonTabs[$VisTabId][5])
	__GUICtrlRibbon_HideCtrl($_RibbonTabs[$VisTabId][7])
	For $i = 0 To UBound($_RibbonCtrlIndex) - 1
		If $_RibbonCtrlIndex[$i][5] = $VisTabId Then
			$_RibbonCtrlIndex[$i][7] = True
		ElseIf $_RibbonCtrlIndex[$i][5] = $hRibbonTab Then
			$_RibbonCtrlIndex[$i][7] = False
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][2])
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][3])
			__GUICtrlRibbon_HideCtrl($_RibbonCtrlIndex[$i][4])
		EndIf
	Next
	$VisTabId = $hRibbonTab
	GUICtrlSetState($_RibbonTabs[$hRibbonTab][3], $GUI_SHOW)
	GUICtrlSetState($_RibbonTabs[$hRibbonTab][5], $GUI_SHOW)
	GUICtrlSetState($_RibbonTabs[$hRibbonTab][7], $GUI_SHOW)
	_WinAPI_RedrawWindow($_RibbonTabs[$hRibbonTab][1])
	WinActivate($act)
	Return 1
EndFunc   ;==>_GUICtrlRibbon_RestoreTab
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_MinimizeRibbon
; Description ...: minimizes the ribbon
; Syntax ........: _GUICtrlRibbon_MinimizeRibbon($hRibbon)
; Parameters ....: $hRibbon             - The ribbon handle.
; Return values .: Success              - Returns 1
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid ribbon handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_MinimizeRibbon($hRibbon)
	If UBound($_Ribbon) < $hRibbon Then Return SetError(1, 0, 0)
	If $VisTabId <> "" Then
		GUISetState(@SW_HIDE, $_RibbonTabs[$VisTabId][1])
	EndIf
	ControlMove($_Ribbon[$hRibbon][0], "", $_Ribbon[$hRibbon][3], 0, $_Ribbon[$hRibbon][10])
	ControlMove($_Ribbon[$hRibbon][0], "", $_Ribbon[$hRibbon][2], 0, 0, $_Ribbon[$hRibbon][12], $_Ribbon[$hRibbon][10])
	$_Ribbon[$hRibbon][11] = True
	GUIStartGroup($_Ribbon[$hRibbon][0])
	Return 1
EndFunc   ;==>_GUICtrlRibbon_MinimizeRibbon
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_RestoreRibbon
; Description ...: restores the ribbon
; Syntax ........: _GUICtrlRibbon_RestoreRibbon($hRibbon)
; Parameters ....: $hRibbon             - The ribbon handle.
; Return values .: Success              - Returns a grand button handle usually has prefix of R
;                  Failure              - Returns 0 and sets @error
;                                       - @error
;                                         |1 = Invalid ribbon handle
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_RestoreRibbon($hRibbon)
	If UBound($_Ribbon) < $hRibbon Then Return SetError(1, 0, 0)
	ControlMove($_Ribbon[$hRibbon][0], "", $_Ribbon[$hRibbon][3], 0, $_Ribbon[$hRibbon][8] + 130)
	ControlMove($_Ribbon[$hRibbon][0], "", $_Ribbon[$hRibbon][2], 0, 0, $_Ribbon[$hRibbon][12], $_Ribbon[$hRibbon][8] + 130)
	_WinAPI_RedrawWindow($_Ribbon[$hRibbon][0])
	If $VisTabId <> "" Then
		GUISetState(@SW_SHOW, $_RibbonTabs[$VisTabId][1])
		_WinAPI_RedrawWindow($_RibbonTabs[$VisTabId][1])
	EndIf
	$_Ribbon[$hRibbon][11] = False
	GUIStartGroup($_Ribbon[$hRibbon][0])
	Return 1
EndFunc   ;==>_GUICtrlRibbon_RestoreRibbon
; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlRibbon_RedrawCurrentTab
; Description ...: Redraws current tab
; Syntax ........: _GUICtrlRibbon_RedrawCurrentTab()
; Parameters ....: None
; Return values .: None
; Author ........: Sycam0inc
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlRibbon_RedrawCurrentTab()
	_WinAPI_RedrawWindow($_RibbonTabs[$VisTabId][1])
EndFunc   ;==>_GUICtrlRibbon_RedrawCurrentTab

Func __GUICtrlRibbon_ShowCtrl($ctrl)
	If (GUICtrlGetState($ctrl) - $GUI_ENABLE) <> $GUI_SHOW Then
		GUICtrlSetState($ctrl, $GUI_SHOW)
	EndIf
EndFunc   ;==>__GUICtrlRibbon_ShowCtrl

Func __GUICtrlRibbon_HideCtrl($Ctrl)
	If GUICtrlGetState($Ctrl) <> 96 Then
		GUICtrlSetState($Ctrl, $GUI_HIDE)
	EndIf
EndFunc   ;==>__GUICtrlRibbon_HideCtrl

Func __GUICtrlRibbon_DrawRibbon($hRibbon)
	If UBound($_Ribbon) < $hRibbon Then Return SetError(1, 0, 0)
	Local $hWndPos = WinGetClientSize($_Ribbon[$hRibbon][0])
	If @error Then Return SetError(3, 0, 0)
	Local $ICO1, $ICO2, $ICO3
	Switch $_Ribbon[$hRibbon][1]
		Case 'blue'
			$ICO1 = "BLUE02"
			$ICO2 = "BLUE03"
			$ICO3 = "BLUE04"
		Case 'black'
			$ICO1 = "BLACK02"
			$ICO2 = "BLACK03"
			$ICO3 = "BLACK04"
		Case 'silver'
			$ICO1 = "SILVER02"
			$ICO2 = "SILVER03"
			$ICO3 = "SILVER04"
		Case Else
			Return SetError(2, 0, 0)
	EndSwitch
	GUICtrlCreateIcon($_BarIconDll, $ICO1, 0, 0, 9, 92)
	GUICtrlCreateIcon($_BarIconDll, $ICO2, 9, 0, $hWndPos[0] - 18, 92)
	GUICtrlCreateIcon($_BarIconDll, $ICO3, $hWndPos[0] - 9 - 9, 0, 9, 92)
	_WinAPI_RedrawWindow($_Ribbon[$hRibbon][0])
	Return 1
EndFunc   ;==>__GUICtrlRibbon_DrawRibbon

Func __GUICtrlRibbon_RegHover($Dummy, $hWnd, $Ctrl1, $Ctrl2, $Ctrl3, $hHandle, $hRibbon, $LDummy = GUICtrlCreateDummy())
	$i = UBound($_RibbonCtrlIndex)
	ReDim $_RibbonCtrlIndex[$i + 1][12]
	$_RibbonCtrlIndex[$i][0] = $Dummy
	$_RibbonCtrlIndex[$i][1] = $hWnd
	$_RibbonCtrlIndex[$i][2] = $Ctrl1
	$_RibbonCtrlIndex[$i][3] = $Ctrl2
	$_RibbonCtrlIndex[$i][4] = $Ctrl3
	$_RibbonCtrlIndex[$i][5] = $hHandle
	$_RibbonCtrlIndex[$i][7] = True
	$_RibbonCtrlIndex[$i][10] = $LDummy
	$_RibbonCtrlIndex[$i][11] = $hRibbon
EndFunc   ;==>__GUICtrlRibbon_RegHover

Func __GUICtrlRibbon_Bump(ByRef $i)
	Do
		If UBound($_RibbonGrandButtons) < $i And UBound($_RibbonSmallButtons) < $i And UBound($_RibbonTabs) < $i Then
			ExitLoop
		Else
			$i += 1
		EndIf
	Until False
EndFunc   ;==>__GUICtrlRibbon_Bump

Func __GUICtrlRibbon_SetIconAlpha($hWnd, $sIcon, $iIndex, $iWidth, $iHeight)
	If Not IsHWnd($hWnd) Then
		$hWnd = GUICtrlGetHandle($hWnd)
		If $hWnd = 0 Then
			Return SetError(1, 0, 0)
		EndIf
	EndIf
	Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex,$iWidth,$iHeight)
	If $hIcon = 0 Then
		Return SetError(1, 0, 0)
	EndIf
	Local $hBitmap, $hObj, $hDC, $hMem, $hSv
	$hDC = _WinAPI_GetDC($hWnd)
	$hMem = _WinAPI_CreateCompatibleDC($hDC)
	$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
	$hSv = _WinAPI_SelectObject($hMem, $hBitmap)
	_WinAPI_DrawIconEx($hMem, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 2)
	_WinAPI_ReleaseDC($hWnd, $hDC)
	_WinAPI_SelectObject($hMem, $hSv)
	_WinAPI_DeleteDC($hMem)
	_WinAPI_DestroyIcon($hIcon)
	_WinAPI_DeleteObject(_sendMessage($hWnd, 0x0172, 0, 0))
	_sendMessage($hWnd, 0x0172, 0, $hBitmap)
	$hObj = _sendMessage($hWnd, 0x0173)
	If $hObj <> $hBitmap Then
		_WinAPI_DeleteObject($hBitmap)
	EndIf
	Return 1
EndFunc   ;==>__GUICtrlRibbon_SetIconAlpha
