#include-once

#include <Constants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <String.au3>
Opt("MustDeclareVars", 1)

OnAutoItExitRegister( _GDIPlus_Shutdown )
Opt("MouseCoordMode", 1) 

Global Const $aidArray = 0, 	$asPosName = 1,		$ahFrameGUI = 2,		$ahGraphics = 3,		  $ahGraphicsContext = 17,	$ahBitmap = 18	
Global Const $aiPosLeft = 6, 	$aiPosTop = 7,		$aiPosRight = 8, 		$aiPosBottom = 9,	  $anPenWidht = 13
Global Const $ahPinsel1 = 4,	$ahPinsel2 = 5	
Global Const $aeError = 10, 	$aeExtended = 11, 	$aeDescription = 12,	$aNamePosition = 14,  $aiColour1 = 15,  $aiColour2 = 16
If Not IsDeclared('iColour1Defalt') Then Global Const $iColour1Defalt = Binary(0xFF0000FF)
If Not IsDeclared('iColour2Defalt') Then Global Const $iColour2Defalt = Binary(0xFFfa0aa0)
If Not IsDeclared('iMAXALLOWEDFRAMES') Then Global Const $iMAXALLOWEDFRAMES = 20
If Not IsDeclared('sDefaltName_GDIplusWindow_AdTo_sPosName') Then Global Const $sDefaltName_GDIplusWindow_AdTo_sPosName = "FrameGui"
		
Global Const $nOfFrames	= 1
Global $iNOW_AKTIV_FRAMES = 0
Global $g_bGDIPlus_Lounched = _GDIPlus_Startup()
Global $g_nPenWidthDefalt = 50
ConsWriteExt(1, @ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)', PixelChecksum(50, 50, 150, 150) ) ; x/left y/top
ConsWriteExt(4, @ScriptLineNumber, 'Hex(PixelGetColor(50,50))', Hex(PixelGetColor(50,50)),'Hex((PixelGetColor(150,150))', Hex(PixelGetColor(150,150)) )
Sleep(200)
Local $wtf = DrawFrame(50, 50, 150, 150, 0xFFFFFF55,0xFF66FF70)
Sleep(20)
ConsWriteExt(4, @ScriptLineNumber, 'Hex(PixelGetColor(50,50))', Hex(PixelGetColor(50,50)),'Hex((PixelGetColor(150,150))', Hex(PixelGetColor(150,150)) )
Sleep(20)
local $aMousePos = MouseGetPos()
MouseMove(50,50)
Sleep(100)
ConsWriteExt(4, @ScriptLineNumber, 'Hex(PixelGetColor(50,50))', Hex(PixelGetColor(50,50)),'Hex((PixelGetColor(150,150))', Hex(PixelGetColor(150,150)) )
Sleep(2500)
MouseMove($aMousePos[0],$aMousePos[1])
;Local $wtf2 = DrawFrameold(50, 50, 150, 150) 0xFFFFFF
;Sleep(1500)



ConsWriteExt(1, @ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)',PixelChecksum(50, 50, 150, 150)) 
;ClearFrame($wtf2)
Sleep(500)	
ClearFrame($wtf)
Sleep(500)
ConsWriteExt(1, @ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)',PixelChecksum(50, 50, 150, 150)) 
ConsWriteExt(4, @ScriptLineNumber, 'Hex(PixelGetColor(50,50))', Hex(PixelGetColor(50,50)),'Hex((PixelGetColor(150,150))', Hex(PixelGetColor(150,150)) )

ConsWriteExt(7, @ScriptLineNumber,@ScriptLineNumber,@ScriptLineNumber)

;Func DrawFrame(
;Func DrawFrame(
;Func DrawFrame(
Func DrawFrame($iLeft, $iTop, $iRight, $iBottom, $iColour1 = $iColour1Defalt, _
$iColour2 = $iColour2Defalt, $nPenWidth = $g_nPenWidthDefalt,  $sPosName = "") ;The string "FrameGui" will be added at the End $sPosName
	
	Dim $Array[19] = [18]
	Local $sNewName_GDIplusWindow = $sPosName & $sDefaltName_GDIplusWindow_AdTo_sPosName
	Local $_GDIPlus_GraphicsDrawRectOK2
	Local $vReturn
    Local $f = 1 / $nOfFrames
	Local $idrawPenWidth = $nPenWidth * 0.8 - 1 ;shod be a littel smaler.
	#Region check input if corect
	ConsWriteExt('BL', @ScriptLineNumber, '$idrawPenWidth',$idrawPenWidth )
		
	If StringIsDigit($iLeft)  	 	Then $iLeft  		= Number($iLeft)
	If StringIsDigit($iTop)   		Then $iTop   		= Number($iTop)
	If StringIsDigit($iRight) 		Then $iRight 		= Number($iRight)
	If StringIsDigit($iBottom)		Then $iBottom		= Number($iBottom)
	If StringIsDigit($nPenWidth)	Then $nPenWidth	    = Number($nPenWidth)
	If Binary(0x00000000) <= Binary($iColour1)  And Binary($iColour1) <= Binary(0xFFFFFFFF)  and IsBinary( Binary($iColour1) ) then $iColour1 = Binary($iColour1)
	If Binary(0x00000000) <= Binary($iColour2)  And Binary($iColour2) <= Binary(0xFFFFFFFF)  and IsBinary( Binary($iColour2) ) then $iColour2 = Binary($iColour2)	
		
	ConsoleWrite('0x00000000 <= $iColour1 <= 0xFFFFFFFF # ' & Binary(0x00000000) & '<' & Binary($iColour1) & '<' & Binary(0xFFFFFFFF) & @LF )
	ConsoleWrite('0x00000000 <= $iColour1 <= 0xFFFFFFFF # ' & Binary(0x00000000) & '<' & Binary($iColour2) & '<' & Binary(0xFFFFFFFF) & @LF )
	
	
	
	$Array[$aiPosLeft] 		= $iLeft
	$Array[$aiPosTop]		= $iTop
	$Array[$aiPosRight]		= $iRight
	$Array[$aiPosBottom] 	= $iBottom
	$Array[$anPenWidht]	    = $nPenWidth
	$Array[$aiColour1]		= $iColour1
	$Array[$aiColour2]		= $iColour2
	$Array[$asPosName] 		= $sPosName	;$Array[$asPosName]	-> Wir im Select Case weiter bearbeitet
	
	
	
	ConsoleWrite('> (' & @ScriptLineNumber & ') $Array IsArray = ' & IsArray($Array) & ', UBound($Array) = ' & UBound($Array) & ',     ' & @TAB& @TAB & @LF)

	Local $___i = 0
	
	Do 
		ConsWriteExt(0, @ScriptLineNumber,'$___i', $___i, '$Array[' & $___i &  ']' , $Array[$___i]) 
		;ConsoleWrite('$Array[' & $___i &  '] = ' & $Array[$___i] & ',     ')
		;If Not IsFloat( $___i / 2 ) Then ConsoleWrite('> (' & @ScriptLineNumber & ') , $___i = ' & $___i  & @LF)
		$___i = $___i + 1	
	Until $___i = UBound($Array) 
	
	If IsFloat( $___i / 2 ) Then ConsoleWrite(@LF)

	ConsWriteExt('POS', @ScriptLineNumber, 'Bevor Select' )
	
	
	Select 
		Case Not IsNumber($iLeft)
			$Array[$aeError] = $aiPosLeft
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiPosLeft, @ScriptLineNumber, $Array)

		Case Not IsNumber($iTop)
			$Array[$aeError] = $aiPosTop
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiPosTop, @ScriptLineNumber, $Array)
		
		Case Not IsNumber($iRight)	
			$Array[$aeError] = $aiPosRight
			$Array[$aeExtended] = @ScriptLineNumber
		 	ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiPosRight, @ScriptLineNumber, $Array)
						
		Case Not IsNumber($iBottom)
			$Array[$aeError] = $aiPosBottom
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiPosBottom, @ScriptLineNumber, $Array)
						
		Case Not IsNumber($nPenWidth)
			$Array[$aeError] = $anPenWidht
			$Array[$aeExtended] = @ScriptLineNumber
			ConsWriteExt(0, @ScriptLineNumber, 'IsNumber($nPenWidth)' , IsNumber($nPenWidth), '$nPenWidth', $nPenWidth)
			Return SetError($anPenWidht, @ScriptLineNumber, $Array)
						
		Case Not IsBinary($iColour1)
			$Array[$aeError] = $aiColour1
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiColour1, @ScriptLineNumber, $Array)
						
		Case Not IsBinary($iColour2)
			$Array[$aeError] = $aiColour2
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($aiColour2, @ScriptLineNumber, $Array)
			
		Case Not IsString( String($Array[$asPosName]) )
			$Array[$aeError] = $asPosName
			$Array[$aeExtended] = @ScriptLineNumber
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Return SetError($asPosName, @ScriptLineNumber, $Array)
							
		Case $iMAXALLOWEDFRAMES <= $iNOW_AKTIV_FRAMES
			$Array[$aeError] = $iMAXALLOWEDFRAMES + $asPosName
			$Array[$aeExtended] = @ScriptLineNumber
			$Array[$aeDescription] = 'its not possible to open more then in $iMAXALLOWEDFRAMES = ' & $iMAXALLOWEDFRAMES & ' definind frames at one time'
			ConsoleWrite('> (' & @ScriptLineNumber & ') '& $Array[$aeDescription] & @LF )
			Return SetError( $iMAXALLOWEDFRAMES + $asPosName, @ScriptLineNumber, $Array)
						
		Case WinExists($sNewName_GDIplusWindow) 	
			Local $i = 2 ; Das 1. Fenster hat keine Nr., wird aber gezählt
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )
			Do
				If $i >= $iMAXALLOWEDFRAMES then 
					$Array[$aeError] = $iMAXALLOWEDFRAMES + $asPosName
					$Array[$aeExtended] = @ScriptLineNumber
					Return SetError($asPosName, @ScriptLineNumber, $Array)
				EndIf
				$sNewName_GDIplusWindow = $sNewName_GDIplusWindow & '_' & $i
				$i = $i + 1
				
			Until Not WinExists($sNewName_GDIplusWindow) 
			ConsoleWrite('> (' & @ScriptLineNumber & ') ' )	
	EndSelect
	ConsWriteExt(3, @ScriptLineNumber, 'End Select' )					
					
	Local $t, $tt
	
	
	If $iLeft > $iRight Then ;Change
		$t = $iLeft
		$iLeft = $iRight
		$iRight = $t
	EndIf
	
	If $iTop > $iBottom Then ;Change
		$tt = $iTop
		$iTop = $iBottom
		$iBottom = $tt
	EndIf

	If $iTop > $iBottom Then ;Change
		$tt = $iTop
		$iTop = $iBottom
		$iBottom = $tt
	EndIf
	#EndRegion ;==> check input if corect
	
#Region GDIPlus_Startup()
	
	Local $bGDIPlus_Lounched = _GDIPlus_Startup()
		
	If $bGDIPlus_Lounched = False Then
		$Array[$aeError] = @error
		$Array[$aeExtended] = @ScriptLineNumber
		$Array[$aeDescription] = '$bGDIPlus_Lounched = FALSE = ' & $bGDIPlus_Lounched & @LF
		Return SetError(@error, @ScriptLineNumber, $Array)
	EndIf
#EndRegion _GDIPlus_Startup()
	
#Region calc GuiSise
	;CALC GUI
;	Local $iWidth_GUI  = $iRight - $iLeft + (2 * $nPenWidth) ;+ $nPenWidth/$nOfFrames
;	Local $iHeight_GUI = $iBottom - $iTop + (2 * $nPenWidth) ;+ $nPenWidth/$nOfFrames $nPenWidth$nPenWidth
	Local $f = 1 / $nOfFrames
	Local $iX_GUI = $iLeft - $nPenWidth*$nOfFrames - 1 ; - $nPenWidth
	Local $iY_GUI = $iTop  - $nPenWidth*$nOfFrames - 1
	Local $iWidth_GUI  = $iRight - $iLeft + $nPenWidth *  $nOfFrames * 2  ;+ $nPenWidth/$nOfFrames
	Local $iHeight_GUI = $iBottom - $iTop + $nPenWidth *  $nOfFrames * 2  ;$nPenWidth * 2  * $nOfFrames(2 * $nPenWidth) ;+ $nPenWidth/$nOfFramesLocal $iWidth_GUI  = $iRight - $iLeft + (2 * $nPenWidth) ;+ $nPenWidth/$nOfFrames

	ConsoleWrite('(' & @ScriptLineNumber & ') $nPenWidth = '& $nPenWidth & ' | $iX_GUI         = ' &        $iX_GUI _ 
										 & ';            $iY_GUI         = ' &        $iY_GUI _
										 & ';            $iWidth_GUI         = ' &    $iWidth_GUI _
										 & ';            $iHeight_GUI        = ' &   $iHeight_GUI & @LF )
	
#EndRegion calc GuiSise	

#Region Creat Gui
	;$Array[$ahFrameGUI] = GUICreate($sNewName_GDIplusWindow, $iWidth_GUI, $iHeight_GUI, $iX_GUI, $iY_GUI, $WS_POPUP, BitOR( $WS_EX_LAYERED,$WS_EX_TOPMOST )) ;BitOR( )) ;$WS_EX_LAYERED,
	$Array[$ahFrameGUI] = GUICreate($sNewName_GDIplusWindow, $iWidth_GUI, $iHeight_GUI, $iX_GUI, $iY_GUI, $WS_POPUP, $WS_EX_TOPMOST ) ;BitOR( )) ;$WS_EX_LAYERED,
	ConsWriteExt(1, @ScriptLineNumber, '$Array[$ahFrameGUI]', $Array[$ahFrameGUI])
	$vReturn = WinMove($sNewName_GDIplusWindow,WinGetText($Array[$ahFrameGUI]) ,$iX_GUI,$iY_GUI)
	ConsWriteExt(1, @ScriptLineNumber, 'WinMove($sNewName_GDIplusWindow,WinGetText($Array[$ahFrameGUI]) ,$iX_GUI,$iY_GUI)', $vReturn)
	If Not IsHWnd($Array[$ahFrameGUI]) Then
		$Array[$aeError] = @error
		$Array[$aeExtended] = @ScriptLineNumber
		$Array[$aeDescription] = 'GUICreate() = FALSE = ' & $Array[$ahFrameGUI] & @LF
		ConsWriteExt(1, @ScriptLineNumber, 'IsHWnd($Array[$ahFrameGUI])', $Array[$ahFrameGUI])
		Return SetError(@error, @ScriptLineNumber, $Array)
	EndIf

#EndRegion Creat Gui

#Region _GDIPlus-Settings 
	ConsWriteExt(3, @ScriptLineNumber, '#Region Create Pen' )
	$Array[$ahGraphics] 			=	 _GDIPlus_GraphicsCreateFromHWND($Array[$ahFrameGUI])
	ConsWriteExt(0, @ScriptLineNumber, 	'_GDIPlus_GraphicsCreateFromHWND($Array[$ahFrameGUI])', $Array[$ahGraphics] )
	
	$Array[$ahBitmap] 			= 		_GDIPlus_BitmapCreateFromGraphics($iWidth_GUI, $iHeight_GUI, $Array[$ahGraphics])
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_BitmapCreateFromGraphics($iWidth_GUI, $iHeight_GUI, $Array[$ahGraphics])', $Array[$ahBitmap] )
	
	$Array[$ahGraphicsContext] 	= 		_GDIPlus_ImageGetGraphicsContext($Array[$ahBitmap])
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_ImageGetGraphicsContext($Array[$ahBitmap])', $Array[$ahGraphicsContext])
	
	$vReturn 					= 		_GDIPlus_GraphicsSetPixelOffsetMode($Array[$ahGraphicsContext], 3)
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_GraphicsSetPixelOffsetMode($Array[$ahGraphicsContext], $GDIP_PIXELOFFSETMODE_NONE)', $vReturn)
	
	$vReturn 					= 		_GDIPlus_GraphicsSetCompositingMode($Array[$ahGraphicsContext], 0)
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_GraphicsSetCompositingMode($Array[$ahGraphicsContext], $GDIP_COMPOSITINGMODESOURCECOPY)', $vReturn)
	
	$vReturn 					= 		_GDIPlus_GraphicsSetCompositingQuality ($Array[$ahGraphicsContext], 0)
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_GraphicsSetCompositingQuality ($Array[$ahGraphicsContext], 0)', $vReturn)

	$vReturn 					= 		_GDIPlus_GraphicsSetSmoothingMode($Array[$ahGraphics], 2)
	ConsWriteExt(0, @ScriptLineNumber, '_GDIPlus_GraphicsSetSmoothingMode($Array[$ahGraphics], 0)', $vReturn)

	
	;$vReturn =	 _GDIPlus_GraphicsSetPixelOffsetMode($Array[$ahFrameGUI],0)
	;ConsWriteExt(1, @ScriptLineNumber, '_GDIPlus_GraphicsSetPixelOffsetMode($Array[$ahFrameGUI],2)', $vReturn)
#EndRegion _GDIPlus-Settings 

#Region Create Pen
	$Array[$ahPinsel1] = _GDIPlus_PenCreate($Array[$aiColour1], $idrawPenWidth , 2) ;Blue Rect
	$Array[$ahPinsel2] = _GDIPlus_PenCreate($Array[$aiColour2], $idrawPenWidth , 2) ;Pinc Rect
	
	
	_GDIPlus_PenSetAlignment($Array[$ahPinsel1], 1)
	_GDIPlus_PenSetAlignment($Array[$ahPinsel2], 1)
	
	_GDIPlus_PenSetLineCap ( $Array[$ahPinsel1], 0x00, 0x11, $GDIP_DASHCAPFLAT )
	_GDIPlus_PenSetLineCap ( $Array[$ahPinsel2], 0x00, 0x11, $GDIP_DASHCAPFLAT )
#EndRegion Create Pen
	
#Region  GUICreate and @SW_SHOW 
	If IsHWnd($Array[$ahFrameGUI]) Then   $iNOW_AKTIV_FRAMES = $iNOW_AKTIV_FRAMES + 1
	WinSetOnTop($Array[$ahFrameGUI], "", 1)
	GUISetBkColor(0xABCDEF) ;Setzt die Hintergrundfarbe (der wert der Farbe ist egal da dise in der Nächsten zeile auf Transparent gesetzt wird)
	_WinAPI_SetLayeredWindowAttributes($Array[$ahFrameGUI], 0xABCDEF, 255) ;der Layer (Layer = eine lage eines Mehrschichtigen Fensters) mit der farbe "0xABCDEF" wird Transparent gestetzt  durch den wert 255 = 100% transparent
	GUISetState()
#EndRegion GUICreate and @SW_SHOW 

#Region Calc and Draw Frames
	Local $iUP = 1, $iDOWN = $nOfFrames
	
	While $iUP <= $nOfFrames ;Until  $i = $nOfFrames
	;ExitLoop
	;ConsoleWrite('( ' & @ScriptLineNumber & ') Do Until  $i = ' & $i & '= $nOfFrames = ' & $nOfFrames &  @LF)
	;First Pen (BIG)
		Assign ('iX_Rect'	 & $iUP , $nPenWidth * ($iUP - 1 ) + $iUP * $f -1) ; + $nPenWidth/2 
		Assign ('iY_Rect'	 & $iUP , $nPenWidth * ($iUP - 1 ) + $iUP * $f -1);- $nPenWidth/$nOfFrames) 
		Assign ('iWidthRect' & $iUP , $iRight - $iLeft - ($iDOWN) * 1 + 2 * $nPenWidth * ($iDOWN) + 2 * $iUP )
		Assign ('iHeightRect'& $iUP , $iBottom - $iTop - ($iDOWN) * $nOfFrames + 2 * $nPenWidth * ($iDOWN) + 0.5 * $iUP + 0.5 )
	
	;Second Pen (SMAL)	
		Assign ('iX_RectSmal'	 & $iUP , $nPenWidth * 0.76 ) ; + $nPenWidth/2 
		Assign ('iY_RectSmal'	 & $iUP , $nPenWidth * 0.76 );- $nPenWidth/$nOfFrames) 
		Assign ('iWidthRectSmal' & $iUP , $iRight - $iLeft - ($iDOWN) * 1 + 2 * $nPenWidth * ($iDOWN) + 2 * $iUP )
		Assign ('iHeightRectSmal'& $iUP , $iBottom - $iTop - ($iDOWN) * $nOfFrames + 2 * $nPenWidth * ($iDOWN) + 0.5 * $iUP + 0.5 )
	
	
	
	;	Assign ('iWidthRect' & $iUP , $iRight - $iLeft + 2 * ($nPenWidth*$iDOWN)  )
	;	Assign ('iHeightRect'& $iUP , $iBottom - $iTop + 2 * ($nPenWidth*$iDOWN)  )
			
	;ConsoleWrite('( ' & @ScriptLineNumber & ') Assign (''iWidthRect'' & $i , $iRight - $iLeft + $nPenWidth + ($nPenWidth*($i-1))+ 1 ,1) = ' & Eval ('iWidthRect' & $i ) & @LF )
		ConsoleWrite('( ' & @ScriptLineNumber & ') $iUP = '& $iUP & '      | Eval(''iX_Rect'' & $i) = ' &       Eval('iX_Rect' & $iUP) _ 
										  & ';       Eval(''iY_Rect'' & $iUP) = ' &       Eval('iY_Rect' & $iUP) _
										  & ';       Eval(''iWidthRect'' & $iUP)  = ' &   Eval('iWidthRect' & $iUP) _
										  & ';       Eval(''iHeightRect'' & $iUP) = ' &   Eval('iHeightRect' & $iUP) & @LF )
										
		;~ 	ConsoleWrite('( ' & @ScriptLineNumber & ')       Eval(''iX_Rect'' & $i) = ' &  $iRight - $iLeft + $nPenWidth/2 + ($nPenWidth*($i-1))  _ 
		;~ 										  & ';       Eval(''iY_Rect'' & $i) = ' &  $iBottom - $iTop + $nPenWidth/2 + ($nPenWidth*($i-1))  _
		;~ 										  & ';       Eval(''iWidthRect''  & $i) = ' &  $iRight - $iLeft + $nPenWidth + ($nPenWidth*($i-1))+ 1 _
		;~ 										  & ';       Eval(''iHeightRect'' & $i) = ' &  $iBottom - $iTop + $nPenWidth + ($nPenWidth*($i-1))+ 1 & @LF )
 		If IsFloat($iUP/2) = True Then
			Assign ('_GDIPlus_GraphicsDrawRectOK'     & $iUP, _GDIPlus_GraphicsDrawRect($Array[$ahGraphicsContext], Eval('iX_Rect' & $iUP), Eval('iY_Rect' & $iUP), Eval('iWidthRect' & $iUP) -1 , Eval('iHeightRect' & $iUP) - 1, $Array[$ahPinsel1] ) ) ;BlueRect
			;_GDIPlus_PenSetWidth($Array[$ahPinsel1], 1) 
			_GDIPlus_GraphicsSetPixelOffsetMode($Array[$ahGraphicsContext], 4)
			Assign ('_GDIPlus_GraphicsDrawRectOKSmal' & $iUP, _GDIPlus_GraphicsDrawRect($Array[$ahGraphicsContext], Eval('iX_RectSmal' & $iUP), Eval('iY_RectSmal' & $iUP), Eval('iWidthRectSmal' & $iUP) -1 , Eval('iHeightRectSmal' & $iUP) - 1, $Array[$ahPinsel1] ) ) ;BlueRect	
			_GDIPlus_PenSetWidth($Array[$ahPinsel1], $idrawPenWidth) 
		ElseIf Assign ('_GDIPlus_GraphicsDrawRectOK' & $iUP, _GDIPlus_GraphicsDrawRect($Array[$ahGraphicsContext], Eval('iX_Rect' & $iUP), Eval('iY_Rect' & $iUP), Eval('iWidthRect' & $iUP) -1 , Eval('iHeightRect' & $iUP) - 1, $Array[$ahPinsel2] ) ) Then ;BlueRect
		EndIf
		_GDIPlus_GraphicsDrawImage($Array[$ahGraphics],$Array[$ahBitmap],0,0)
		
		If Eval('_GDIPlus_GraphicsDrawRectOK' & $iUP) = False Then
			$Array[$aeError] = $iUP
			$Array[$aeExtended] = @ScriptLineNumber
			$Array[$aeDescription] = 'Do Until  $i = $nOfFrames = ' & $iUP & @LF
			ConsWriteExt(1, @ScriptLineNumber, 'Eval(''_GDIPlus_GraphicsDrawRectOK'' & $iUP)', Eval('_GDIPlus_GraphicsDrawRectOK' & $iUP), '$iUP' , $iUP) 
			Return SetError( $Array[$aeError], $Array[$aeExtended], $Array)
		EndIf
		
		$iUP   = $iUP   + 1
		$iDOWN = $iDOWN - 1
	
	WEnd ; $i = $nOfFrames
	ConsoleWrite('( ' & @ScriptLineNumber & ') Do Until  $i = ' & $iUP & '= $nOfFrames = ' & $nOfFrames &  @LF)	
	Local $_WinAPI_SetWindowLongOK = _WinAPI_SetWindowLong($Array[$ahFrameGUI], $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($Array[$ahFrameGUI], $GWL_EXSTYLE), $WS_EX_TRANSPARENT));ClickThrough
	;Local $_WinAPI_SetWindowLongOK = _WinAPI_SetWindowLong($Array[$ahFrameGUI], $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($Array[$ahFrameGUI], $GWL_EXSTYLE), $WS_EX_TRANSPARENT));ClickThrough
	If $_WinAPI_SetWindowLongOK = 0 Then
		$Array[$aeError] = @error
		$Array[$aeExtended] = @ScriptLineNumber
		SetError(5)
		$Array[$aeDescription] = '$bGDIPlus_Lounched = ' & $bGDIPlus_Lounched
		Return $Array
	EndIf
#EndRegion Calc and Draw Frames
	
	local $penTest = _GDIPlus_PenCreate(0xFF000000, 1, 2) ;Pinc Rect
	_GDIPlus_GraphicsDrawRect($Array[$ahGraphics],$nPenWidth, $nPenWidth ,$iRight - $iLeft, $iBottom - $iTop,$penTest)
	;ConsWriteExt(0, @ScriptLineNumber, 'PixelChecksum($iLeft, $iTop, $iRight,$iBottom)',PixelChecksum($iLeft, $iTop, $iRight,$iBottom),1,1 ) 
	;Sleep(5)
	;ConsWriteExt(0, @ScriptLineNumber, 'PixelChecksum($iLeft, $iTop, $iRight,$iBottom)',PixelChecksum($iLeft, $iTop, $iRight,$iBottom),1,1 ) 
	
	ConsWriteExt(3, @ScriptLineNumber, 'End Func' )	
	
	Return $Array
 ;PixelChecksum($iLeft, $iTop, $iRight,$iBottom)
	
	
EndFunc   ;==>DrawFrame
;Erzeugt GUI$array['GuiName'] und Zeichnet Box



Func ClearFrame($Array)
	If IsArray($Array) Then
		_GDIPlus_GraphicsClear($Array[$ahGraphics], 0xFFABCDEF)
		;Global $hGui = GUICreate("RahmenGui", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
		GUIDelete($Array[$ahFrameGUI])
		_GDIPlus_PenDispose($Array[$ahPinsel1])
		_GDIPlus_PenDispose($Array[$ahPinsel2])
		_GDIPlus_GraphicsDispose($Array[$ahGraphics])
		_GDIPlus_GraphicsDispose($Array[$ahGraphicsContext])
		_GDIPlus_BitmapDispose($Array[$ahBitmap])
		WinClose($Array[$asPosName], "")
	EndIf
EndFunc   ;==>ClearFrame



Func GetAbsolutClientPos_0_X($hwnd)
	Local $tpoint = DllStructCreate("int X;int Y") ;Erzeugt eine Struktur im C/C++-Stil die mit DllCall genutzt werden kann. Jeder Datentyp muss mit einem Semikolon getrennt werden ';',int  : 32bit(4bytes) signed integer
	DllStructSetData($tpoint, "X", 0) ; Setzt Daten in einem Element der Struktur Syntax:DllStructSetData ( Struct, Element, value [, index] ), Struct: Struktur, zurückgegeben von DllStructCreate. , Element: Das Element in der Struktur, auf das man zugreifen möchte (beginnend bei 1) oder der Elementname, wie er mit DllStructCreate festgelegt wurde.
	_WinAPI_ClientToScreen($hwnd, $tpoint)
	Return DllStructGetData($tpoint, "X")
EndFunc   ;==>GetAbsolutClientPos_0_X

Func GetAbsolutClientPos_0_Y($hwnd)
	Local $tpoint = DllStructCreate("int X;int Y") ;Erzeugt eine Struktur im C/C++-Stil die mit DllCall genutzt werden kann. Jeder Datentyp muss mit einem Semikolon getrennt werden ';',int  : 32bit(4bytes) signed integer
	DllStructSetData($tpoint, "Y", 0) ; Setzt Daten in einem Element der Struktur Syntax:DllStructSetData ( Struct, Element, value [, index] ), Struct: Struktur, zurückgegeben von DllStructCreate. , Element: Das Element in der Struktur, auf das man zugreifen möchte (beginnend bei 1) oder der Elementname, wie er mit DllStructCreate festgelegt wurde.
	_WinAPI_ClientToScreen($hwnd, $tpoint)
	Return DllStructGetData($tpoint, "Y")
EndFunc   ;==>GetAbsolutClientPos_0_Y

;~ Func OldCalc()
;~ #Region calc frame sise
;~ 	Local $_GDIPlus_GraphicsDrawRectOK2
;~ 	Local $iWidth_GUI = $iRight - $iLeft + 2 * ($nPenWidth)
;~ 	Local $iHeight_GUI = $iBottom - $iTop + 2 * ($nPenWidth)
;~ 	Local $iX_GUI = $iLeft - ($nPenWidth)
;~ 	Local $iY_GUI = $iTop - ($nPenWidth)
;~ 	;
;~ 	Local $iWidth_Rect1 = $iRight - $iLeft + $nPenWidth + 1
;~ 	Local $iHeight_Rect1 = $iBottom - $iTop + $nPenWidth + 1
;~ 	Local $iX_Rect1 = ($nPenWidth / 2) ;X coordinate of the upper left corner
;~ 	Local $iY_Rect1 = ($nPenWidth / 2) ;Y coordinate of the upper left corner
;~ ;~
;~ 	Local $iWidth_Rect2 = $iRight - $iLeft + ($nPenWidth) + 1
;~ 	Local $iHeight_Rect2 = $iBottom - $iTop + ($nPenWidth) + 1
;~ 	Local $iX_Rect2 = ($nPenWidth / 2) ;X coordinate of the upper left corner
;~ 	Local $iY_Rect2 = ($nPenWidth / 2) ;Y coordinate of the upper left corner
;~ 	
;~ 	#EndRegion ;==> calc frame sise
;~ EndFunc

Func ConsWriteExt($nStart, $iSLN, $sString, $vValue = '', $sString2 = Null, $vValue2 = Null) ;ConsoleWriteExtended
;If $g__bDebug = True Then
Local $sStart1 = '(', $sStart2 = ') '
Select

	Case Int($nStart) = Int(1) Or String($nStart) = String('BU')
		$sStart1 = '>( '
		$sStart2 = ') : '
	
	Case Int($nStart) = Int(2) Or String($nStart) = String('OG')
		$sStart1 = '-( '
		$sStart2 = '): '
	
	Case Int($nStart) = Int(3) Or String($nStart) = String('GN')
		$sStart1 = '+( '
		$sStart2 = ') + '
	
	Case Int($nStart) = Int(4) Or String($nStart) = String('RD')
		$sStart1 = ' ( '
		$sStart2 = ') : '
	
	Case Int($nStart) = Int(5) Or String($nStart) = String('POS') Or String($nStart) = String('PAST')
		ConsoleWrite('..(.' & $iSLN & ')...LINE.PAST...'& @TAB & @TAB & $iSLN & @TAB & @TAB & $sString & @TAB& @TAB & $vValue & @LF)
		Return

	
	
	
	Case $nStart = Int(6) Or String($nStart) = String('!')
		$sStart1 = '!( '
		$sStart2 = ') '
		
	
	
	Case $nStart = Int(7) Or String($nStart) = String('@@')
		$sStart1 = '@@DEBUG ('
		$sStart2 = ')'
		
	;LAST CASR!!!
	Case Int($nStart) = Int(0) Or String($nStart) = String('BK')
		$sStart1 = ' ('
		$sStart2 = ') '	
	
EndSelect		
IF $sString2 = Null Then 
		ConsoleWrite($sStart1 & $iSLN & $sStart2 & $sString & ' = ' & $vValue & @LF)  
Else	
		ConsoleWrite($sStart1 & $iSLN & $sStart2 & $sString & ' = ' & $vValue & ' ;  ' & @TAB & $sString2 & ' = ' & $vValue2 & @LF)  
EndIf
;EndIf

EndFunc

;;;;;;;;;;;;;;;;;;;;;
Func DrawFrameOLD($left, $top, $right, $bottom, $Rahmen = 20)
	Dim $Array[14] = [14]
	
	If StringIsDigit($left)   Then $left  =  Number($left)
	If StringIsDigit($top)    Then $top   =  Number($top)
	If StringIsDigit($right)  Then $right  = Number($right)
	If StringIsDigit($bottom) Then $bottom = Number($bottom)
	If StringIsDigit($Rahmen) Then $Rahmen = Number($Rahmen)
	
	$Array[6]  = $left
	$Array[7]  = $top
	$Array[8]  = $right
	$Array[9]  = $bottom
	$Array[13] = $Rahmen
	
	If Not IsNumber($left)   Then $left  =  False
	If Not IsNumber($top)    Then $top   =  False
	If Not IsNumber($right)  Then $right  = False
	If Not IsNumber($bottom) Then $bottom = False
	If Not IsNumber($Rahmen) Then $Rahmen = False
	
	

	
	
	If  $left =  False Or  $top =  False  Or $right =  False Or $bottom =  False Or $Rahmen =  False Then 
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(3)
		$Array[12] =  'Input Is No Digit and Number'
		Return $Array
	EndIf
	
	Local $t, $tt
	ConsoleWrite('$left = ' & $left & ', $right  = ' & $right & @CRLF)
	ConsoleWrite('$top  = ' & $top & ',  $bottom = ' & $bottom & @CRLF)
	If $left > $right Then ;Change
		$t = $left
		$left = $right
		$right = $t
	EndIf
	
	If $top > $bottom Then ;Change
		$tt = $top
		$top = $bottom
		$bottom = $tt
	EndIf

	ConsoleWrite('$left = ' & $left & ', $right  = ' & $right & @CRLF)
	ConsoleWrite('$top  = ' & $top & ',  $bottom = ' & $bottom & @CRLF)
	
If $top > $bottom Then ;Change
		$tt = $top
		$top = $bottom
		$bottom = $tt
	EndIf
	
	ConsoleWrite('$left = ' & $left & ', $right  = ' & $right & @CRLF)
	ConsoleWrite('$top  = ' & $top & ',  $bottom = ' & $bottom & @CRLF)
	
	Local $_GDIPlus_GraphicsDrawRectOK2
	Local $iWidth_GUI = $right - $left + 2 * ($Rahmen)
	Local $iHeight_GUI = $bottom - $top + 2 * ($Rahmen)
	Local $iX_GUI = $left - ($Rahmen)
	Local $iY_GUI = $top - ($Rahmen)
	;
	Local $iWidth_Rect1 = $right - $left + $Rahmen + 1
	Local $iHeight_Rect1 = $bottom - $top + $Rahmen + 1
	Local $iX_Rect1 = ($Rahmen / 2) ;X coordinate of the upper left corner
	Local $iY_Rect1 = ($Rahmen / 2) ;Y coordinate of the upper left corner
;~
	Local $iWidth_Rect2 = $right - $left + ($Rahmen) + 1
	Local $iHeight_Rect2 = $bottom - $top + ($Rahmen) + 1
	Local $iX_Rect2 = ($Rahmen / 2) ;X coordinate of the upper left corner
	Local $iY_Rect2 = ($Rahmen / 2) ;Y coordinate of the upper left corner
	
	
	
	;$Array[100] = @error
	;$Array[101] = @scriptlinenumber
	;$Array[102] = 'String'
	
	$Array[1] = "RahmenGui"
	;$Array[2] = $hGui
	;$Array[3] = $hGraphic
	;$Array[4] = $hPinsel1
	;$Array[5] = $hPinsel2
	
	Local $_GDIPlus_StartupOK = _GDIPlus_Startup()
	If $_GDIPlus_StartupOK = False Then
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(1)
		$Array[12] = '$_GDIPlus_StartupOK = ' & $_GDIPlus_StartupOK
		Return $Array
	EndIf
	
	;$hGui  							Breite		Höhe,		Links/Left, Oben/Top
	$Array[2] = GUICreate($Array[1], $iWidth_GUI, $iHeight_GUI, $iX_GUI, $iY_GUI, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
	If @error = 1 Then
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(2)
		$Array[12] = 'GUICreate'
		Return $Array
	EndIf
	WinSetOnTop($Array[2], "", 1)
	GUISetBkColor(0xABCDEF) ;Setzt die Hintergrundfarbe (der wert der Farbe ist egal da dise in der Nächsten zeile auf Transparent gesetzt wird)
	_WinAPI_SetLayeredWindowAttributes($Array[2], 0xABCDEF, 255) ;der Layer (Layer = eine lage eines Mehrschichtigen Fensters) mit der farbe "0xABCDEF" wird Transparent gestetzt  durch den wert 255 = 100% transparent
	GUISetState()
	;hGraphic
	$Array[3] = _GDIPlus_GraphicsCreateFromHWND($Array[2])
	$Array[4] = _GDIPlus_PenCreate(0xFF0000FF, $Rahmen, 2) ;Blue Rect
	$Array[5] = _GDIPlus_PenCreate(0xFFfa0aa0, ($Rahmen) / 4, 2) ;Pinc Rect


	Local $_GDIPlus_GraphicsDrawRectOK1 = _GDIPlus_GraphicsDrawRect($Array[3], $iX_Rect1, $iY_Rect1, $iWidth_Rect1, $iHeight_Rect1, $Array[4]) ;Blue Rect
	If $_GDIPlus_GraphicsDrawRectOK1 = 0 Then
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(3)
		$Array[12] = '$_GDIPlus_StartupOK = ' & $_GDIPlus_StartupOK
		Return $Array
	EndIf
	
	Local $_GDIPlus_GraphicsDrawRectOK1 = _GDIPlus_GraphicsDrawRect($Array[3], $iX_Rect1, $iY_Rect1, $iWidth_Rect1, $iHeight_Rect1, $Array[5]) ;Blue Rect
	If $_GDIPlus_GraphicsDrawRectOK2 = 'False' Then
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(4)
		$Array[12] = '$_GDIPlus_StartupOK = ' & $_GDIPlus_StartupOK
		Return $Array
	EndIf
	
	Local $_WinAPI_SetWindowLongOK = _WinAPI_SetWindowLong($Array[2], $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($Array[2], $GWL_EXSTYLE), $WS_EX_TRANSPARENT));ClickThrough
	If $_WinAPI_SetWindowLongOK = 0 Then
		$Array[10] = @error
		$Array[11] = @ScriptLineNumber
		SetError(5)
		$Array[12] = '$_GDIPlus_StartupOK = ' & $_GDIPlus_StartupOK
		Return $Array
	EndIf
	
	$Array[10] = True
	$Array[11] = @ScriptLineNumber
	$Array[12] = True
	Return $Array

	ConsWriteExt(@ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)',PixelChecksum($Left, $Top, $Right, $Bottom),1,1 ) 
	Sleep(5)
	ConsWriteExt(@ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)',PixelChecksum($Left, $Top, $Right, $Bottom),1,1 )
	Sleep(5)
	ConsWriteExt(@ScriptLineNumber, 'PixelChecksum($Left, $Top, $Right,$Bottom)',PixelChecksum($Left, $Top, $Right, $Bottom),1,1 ) 
EndFunc   ;==>DrawFrame
;Erzeugt GUI$array['GuiName'] und Zeichnet Box