Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

29 Jan 2020, 04:52

I am working on a update to a old wrapper function I have that creates / sets up a layered window.

I have two things that I could use a hand with.

1: Include a effective method of moving a layered window ( click and drag ) if the user is using Windows 7 or older.

2: Delete a instance ( This ) of the class from within the class method ( DeleteWindow() ) so that the extra step of OBJ := "" can be avoided outside the class.

Code: Select all

;***************************************************************************************************
;***************************************************************************************************
;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
;***************************************************************************************************
;***************************************************************************************************
#SingleInstance,Force
SetBatchLines -1
OnExit,GuiClose

Window := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , window := 1 , title := "Test Window" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
	
return
GuiClose:
GuiContextMenu:
*ESC::
	Window.DeleteWindow( 1 )
	ExitApp

;________________________________________________________________________________________________________
;________________________________________________________________________________________________________
;        <><><><><>   Testing   <><><><><>
;________________________________________________________________________________________________________
;________________________________________________________________________________________________________
numpad1:: ;Test painting the background and clearing the graphics
	Window.PaintBackground( "0xFF3377ff" , 1 )
	sleep, 500
	Window.ClearWindow( 1 )
	sleep, 500
	Window.PaintBackground( "0xFFff0000" , 1 )
	return

Numpad2:: ;Test moving the window and drawing a bitmap to the graphics
	Window.ShowWindow( 1 , { x: 1400 , y: 200 , w: Window.W , h: Window.H } )
	sleep, 500
	Window.PaintBackground( "0xFF222529" , 1 )
	Window.Draw( HB_BITMAP_MAKER() , { X: 75 , Y: 2 , W: 150 , H: 40 } , , 1 )
	return
	
Numpad3:: ;Test deleting the layered window	, shuting down gdip , and creating a new window
	Window.DeleteWindow( 1 )
	Window := ""
	sleep, 1000
	Window := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , window := 1 , title := "Bob" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
	Window.ShowWindow( 1 , { x: 700 , y: 200 , w: Window.W , h: Window.H } )
	sleep, 500
	Window.Draw( HB_BITMAP_MAKER() , { X: 75 , Y: 2 , W: 150 , H: 40 } , , 1 )
	return

;***********************************************************************************************************************************************************************
;***																																								 ***
;***																		Layered Window Class																	 ***
;***																																								 ***
;***********************************************************************************************************************************************************************
class LayeredWindow	{
	__New( x := 0 , y := 0 , w := 100 , h := 100 , window := 1 , title := "Layered Window " , smoothing := 4 , options := "" , autoShow := 1 , GdipStart := 0 , WinMover := "" , BackgroundColor := "" ){
		This.X := x 
		This.Y := y 
		This.W := w
		This.H := h 
		This.Window := window
		This.Title := title
		This.Options := options
		This.Smoothing := smoothing
		
		( GdipStart ) ? ( This.Token := Gdip_Startup() )
		
		This._CreateWindow()
		
		( autoShow ) ? ( This.ShowWindow() )
		
		This._SetUpdateLayeredWindow()
		
		( WinMover ) ? ( This._AddMoveTrigger( WinMover ) )
		
		( BackgroundColor ) ? ( This.PaintBackground( BackgroundColor , 1 ) )
		
	}
	_CreateWindow(){
		Gui , % This.Window ": New" , % " +E0x80000 +LastFound -Caption " This.Options 
		This.Hwnd := WinExist()
		This.hbm := CreateDIBSection( This.W , This.H )
		This.hdc := CreateCompatibleDC()
		This.obm := SelectObject( This.hdc , This.hbm )
		This.G := Gdip_GraphicsFromHDC( This.hdc )
		Gdip_SetSmoothingMode( This.G , This.Smoothing )
	}
	_SetUpdateLayeredWindow(){
		UpdateLayeredWindow( This.hwnd , This.hdc , This.X , This.Y , This.W , This.H )
	}
	UpdateWindow(){
		UpdateLayeredWindow( This.hwnd , This.hdc )
	}
	ShowWindow( update := 1 , Position := "" ){ ;Show this window
		if( !Position )
			Gui , % This.Window ": Show" , % "w" This.W " h" This.H " NA" , % ( This.Title ) ? ( This.Title ) : ( "" )
		else
			Gui , % This.Window ": Show" , % "x" Position.X " y" Position.Y "w" Position.W " h" Position.H " NA" , % ( This.Title ) ? ( This.Title )  : ( "" )
		( update )?( This.UpdateWindow() )
	}
	_AddMoveTrigger( positons ){ ;Add a text control to act as a trigger to move the window
		local hwnd , bd
		Gui , % This.Window " : Add" , Text , % "x" positons.x " y" positons.y " w" positons.w " h" positons.h " hwndhwnd"
		bd := This._WindowMover.Bind( This )
		GuiControl , % This.Window ": +G" , %hwnd% , % bd
	}
	_WindowMover(){ ;Move this window
		PostMessage, 0xA1 , 2
	}
	PaintBackground( BackgroundColor := "0xFF000000" , update := 0){ ;Use a brush to paint the background of the window
		local Brush
		Brush := Gdip_BrushCreateSolid( BackgroundColor )
		Gdip_FillRectangle( This.G , Brush , 0 , 0 , This.W , This.H )
		Gdip_DeleteBrush( Brush )
		( update ) ? ( This.UpdateWindow() )
	}
	Draw( pBitmap , Positions := "" , update := 1 , disposeBitmap := 0 ){ ;Draw a bitmap onto the graphics of the window.
		Gdip_DrawImage( This.G 
						, pBitmap 
						, ( Positions.X1 ) ? ( Positions.X1 ) : ( Positions.X ) ? ( Positions.X ) : ( "" )
						, ( Positions.Y1 ) ? ( Positions.Y1 ) : ( Positions.Y ) ? ( Positions.Y ) : ( "" ) 
						, ( Positions.W1 ) ? ( Positions.W1 ) : ( Positions.W ) ? ( Positions.W ) : ( "" ) 
						, ( Positions.H1 ) ? ( Positions.H1 ) : ( Positions.H ) ? ( Positions.H ) : ( "" ) 
						, ( Positions.X2 ) ? ( Positions.X2 ) : ( Positions.SX ) ? ( Positions.SX ) : ( "" )
						, ( Positions.Y2 ) ? ( Positions.Y2 ) : ( Positions.SY ) ? ( Positions.SY ) : ( "" )
						, ( Positions.W2 ) ? ( Positions.W2 ) : ( Positions.SW ) ? ( Positions.SW ) : ( "" )
						, ( Positions.H2 ) ? ( Positions.H2 ) : ( Positions.SH ) ? ( Positions.SH ) : ( "" ) )
						
		( update ) ? ( This.UpdateWindow() )
		
		( disposeBitmap ) ? ( Gdip_DisposeImage( pBitmap ) )
		
	}
	ClearWindow( update := "" ){ ;Clear the graphics
		Gdip_GraphicsClear( This.G )
		( update ) ? ( This.UpdateWindow() )
	}
	DeleteWindow( TurnOffGdip := 0 ){
		SelectObject( This.hdc , This.obm )
		DeleteObject( This.hbm )
		DeleteDC( This.hdc )
		Gdip_DeleteGraphics( This.G )
		( TurnOffGdip && This.Token ) ? ( Gdip_Shutdown( This.Token ) )
		Gui, % This.Window " : Destroy"
	}
}

;***********************************************************************************************************************************************************************
;***********************************************************************************************************************************************************************
HB_BITMAP_MAKER(){ ;Create Test Bitmap
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( 150 , 40 ) 
	 G := Gdip_GraphicsFromImage( pBitmap )
	Gdip_SetSmoothingMode( G , 2 )
	Brush := Gdip_BrushCreateSolid( "0xFF272928" )
	Gdip_FillRectangle( G , Brush , 0 , 0 , 150 , 40 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 7 , 21 , 2 , 23 , "0xFF52C2DA" , "0xFF111111" , 1 , 1 )
	Gdip_FillRoundedRectangle( G , Brush , 1 , 1 , 148 , 37 , 18 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF343933" )
	Gdip_FillRoundedRectangle( G , Brush , 6 , 4 , 138 , 31 , 14 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF272928" )
	Gdip_FillRectangle( G , Brush , 30 , 1 , 90 , 10 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF272928" )
	Gdip_FillRectangle( G , Brush , 30 , 28 , 90 , 10 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF232B32" )
	Gdip_FillRoundedRectangle( G , Brush , 9 , 6 , 132 , 27 , 10 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrush( 71 , 20 , 70 , 20 , "0xFF24404C" , "0xFF3E8191" , 2 )
	Gdip_FillRoundedRectangle( G , Brush , 11 , 8 , 128 , 23 , 10 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF0FBBE1" )
	Gdip_FillRectangle( G , Brush , 20 , 9 , 110 , 1 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF0FBBE1" )
	Gdip_FillRectangle( G , Brush , 30 , 5 , 90 , 1 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF0FBBE1" )
	Gdip_FillRectangle( G , Brush , 30 , 34 , 90 , 1 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF0FBBE1" )
	Gdip_FillRectangle( G , Brush , 20 , 30 , 110 , 1 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF111111" )
	Gdip_TextToGraphics( G , "Hellbent" , "s16 Center vCenter c" Brush " x0 y1" , "Arial Black" , 150 , 40 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF111111" )
	Gdip_TextToGraphics( G , "Hellbent" , "s16 Center vCenter c" Brush " x0 y1" , "Arial Black" , 150 , 40 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF111111" )
	Gdip_TextToGraphics( G , "Hellbent" , "s16 Center vCenter c" Brush " x1 y2" , "Arial Black" , 150 , 40 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFFE7FEFF" )
	Gdip_TextToGraphics( G , "Hellbent" , "s16 Center vCenter c" Brush " x0 y1" , "Arial Black" , 150 , 40 )
	Gdip_DeleteBrush( Brush )
	Gdip_DeleteGraphics( G )
	return pBitmap
}
Thanks.
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 04:21

GUI index can be static in your class and why don't you create another layered window with new variable and then delete the previous, the GUI parameters in your class are perfect i do not know much about gdip lib but I am using your button class, in one of my code where I find initial version of the this class as function Layered_Window_SetUp()

Code: Select all

Numpad3:: ;Test Create new layered window and the deleting then previous layered window

Window2 := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , , title := "Tom" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
Window2.ShowWindow( 1 , { x: 700 , y: 200 , w: Window2.W , h: Window2.H } )
Window2.PaintBackground( "0xFF3377ff" , 1 )
sleep, 500
Window2.Draw( HB_BITMAP_MAKER() , { X: 75 , Y: 2 , W: 150 , H: 40 } , , 1 )
sleep, 1000

Window.DeleteWindow( 1 )
Window := ""
msgbox, % "now you need to reload script coz obj window deleted"
. "`nwindow1 >" Window.window
. "`nwindow2 >" Window2.window
return

;***********************************************************************************************************************************************************************
;***																																								 ***
;***																		Layered Window Class																	 ***
;***																																								 ***
;***********************************************************************************************************************************************************************
class LayeredWindow	{
	__New( x := 0 , y := 0 , w := 100 , h := 100 , window := 1 , title := "Layered Window " , smoothing := 4 , options := "" , autoShow := 1 , GdipStart := 0 , WinMover := "" , BackgroundColor := "" ){
		static i := 0
		++i
		This.X := x 
		This.Y := y 
		This.W := w
		This.H := h 
		This.Window := i ;window
		; .................
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 07:03

GUI index can be static in your class
Thanks for the pointer, this is actually something that I started doing awhile ago but I have left this class with user defined gui names because I find it more familiar to what I'm used to. For example, once a window is created I still often need to do things like adding other gui controls (triggers) and it would drive me crazy to type out Gui, % ObjectName.Window ":Add", Text instead of just typing out what I called the window Gui, 1:Add, Text Just a personal preference I guess.
I do know that I can just set the gui as Default but I really don't like that practice and there are cases where that leads to problems lol. I ALWAYS add the name of the gui every time a control / option is added or changed etc. ALWAYS!

This is from a recent class I made that uses a static class variable for creating the window name.

Code: Select all

class ColorTip	{
	static WindowCount := 0
	__New(){		
		This.Name := "ColorTipWindow_" ++ColorTip.WindowCount
		...

why don't you create another layered window with new variable and then delete the previous

Code: Select all

Numpad3:: ;Test deleting the layered window	, shuting down gdip , and creating a new window
	Window.DeleteWindow( 1 )
	Window := ""
	sleep, 1000
	Window := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , window := 1 , title := "Bob" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
	return
In the case of that example code it was just meant to show how to go about deleting the window and then freeing the objects memory, the fact that I recreated a new instance with the same name is just because I like using gui 1: as my goto main gui name. That way I can just use my:

Code: Select all

return
GuiClose:
GuiContextMenu:
*ESC::
	ExitApp
That I include with every script when I first start writing them.

the GUI parameters in your class are perfect i do not know much about gdip lib but I am using your button class, in one of my code where I find initial version of the this class as function Layered_Window_SetUp()
Thanks.
Honestly, I'm still a bit of a newbie when it comes to GDIP. I only really started using it once I had created my bitmap maker (Drawing program).
Before that I found it to be too much of a pain in the ... to do much of anything with. I still have tons to learn about what can be done with it and what all the terms (names of functions etc) even mean let alone what they are used for. Like, WTF is a DIB? [Device Independent Bitmap], or locking Bits? *rhetorical* lol

I don't miss using my old Layered_Window_SetUp() This new class is so much easier to use.

I still need to find a way to include the ability to add triggers for windows 7 users, but I don't think it will happen ¯\_(ツ)_/¯

For example, if the user is on window 8 or higher, this window is moveable by clicking and dragging it. Windows 7 users are sol.

Code: Select all

New_Window := New LayeredWindow(x := "" , y := "" , w := 1000 , h := 600 , window := 1 , title := " " , smoothing := 2 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , WinMover := { x: 0 , y: 0 , w: w , h: h } , BackgroundColor := "0xFF888888")
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 10:28

Hellbent wrote:
11 Jan 2021, 07:03
I still need to find a way to include the ability to add triggers for windows 7 users, but I don't think it will happen ¯\_(ツ)_/¯
I got windows 7 and moving window working for me, line 12

Code: Select all

Window := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , window := 1 , title := "Test Window" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 10:38

Xeo786 wrote:
11 Jan 2021, 10:28
Hellbent wrote:
11 Jan 2021, 07:03
I still need to find a way to include the ability to add triggers for windows 7 users, but I don't think it will happen ¯\_(ツ)_/¯
I got windows 7 and moving window working for me, line 12

Code: Select all

Window := New LayeredWindow( x := "" , y := "", w := 300 , h := 100 , window := 1 , title := "Test Window" , smoothing := 4 , options := "+AlwaysOnTop" , autoShow := 1 , GdipStart := 1 , { x: 0 , y: 0 , w: 300 , h: 42 } , BackgroundColor := "0xFF222529" )
For real? You can click and move that window while using windows 7?

And what is "line 12"?

What about this script can you interact with the gui? Try moving it, try "Right clicking" it and then try pressing the "Get Color" button and then the second square on the bottom.

Code: Select all

;*************************************************************************************************************************
;*************************************************************************************************************************
;*************************************************************************************************************************

;Written By: 	Hellbent
;Date Started: 	Nov 21st 2019
;Name: Not Named Yet

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;                         HOTKEYS:
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;~ Hotkey , *^ESC , GuiClose  ; Ctrl + Esc to exit     ;<------------------------------   Activate to use.


Hotkey, Numpad1 , Take_ScreenShot   ;<---------------------  Take screenshot of pre-selected area.

;*************************************************************************************************************************
;Auto-Execute Section

;The following code executes as soon as the script is run. 
;Setup of script settings and options.
;Declaration of global and other variables used throughout the script.
;Creation of the main gui.
;Creation of the folder to store saved screenshots.

;*************************************************************************************************************************

	;Set the script to exit the previous instance if it is run again while it is already running
#SingleInstance, Force

	;Set the script to use no environment variables
#NoEnv

	;Set the script to run at top speed
SetBatchLines, -1

	;Set the coordmode used when selecting pixel positions to be related to the screen
CoordMode, Pixel , Screen

	;Set the coordmode used when selecting cursor positions to be related to the screen
CoordMode, Mouse , Screen

	;Start using Gdip.
Gdip_Startup()

IfNotExist, %A_ScriptDir%\Screen Shots
	;If the folder to hold the saved screenshots doen't already exist.

		;Create a folder to hold the saved screenshots.
	FileCreateDir, %A_ScriptDir%\Screen Shots
	
	;Set the working dir to be the folder that will hold any screenshots taken.
SetWorkingDir, %A_ScriptDir%\Screen Shots

;Declaration of global variables used throughout the execution of the script.
;****************************************************************************************************
global CapActive := 0 , SP , XCAP , YCAP , WCAP , HCAP , OB := 0

global CapWin := {} , Monitors := New MonitorClass()

;~ global TXC , TYC , BB := New_Brush( "000000" , "88" ) , GB := New_Brush( "00ff00" , "55" ) , RB := New_Brush( "ff0000" , "55" )
global TXC , TYC , BB := New_Brush( "000000" , "ff" ) , GB := New_Brush( "00ff00" , "55" ) , RB := New_Brush( "ff0000" , "55" )

global ShowWin := {} , ImageList1 := [] , ZoomWindow := {}

global Index := 1 , Frame1 , Detached , Message

global OutColor := "3399FF"
;****************************************************************************************************

;###################################################################################################
;Added Jan 7th, 2020
;Check if there are any saved colors and dump them into a variable.
IfNotExist, %A_ScriptDir%\Saved Colors.txt
	FileAppend,3399FF`,3399FF`,3399FF`,3399FF,%A_ScriptDir%\Saved Colors.txt
FileRead, SavedColors, %A_ScriptDir%\Saved Colors.txt
global SavedColors:=StrSplit(SavedColors,",")
;~ ToolTip,% SavedColors[1] "`n" SavedColors[2] "`n" SavedColors[3] "`n" SavedColors[4]
;###################################################################################################

	;Create a instance of a layered window for the main gui
global CDisplay := Layered_Window_SetUp( 4 , A_ScreenWidth - 250 , 50 , 200 , 200 , 1 , "-Caption -DPIScale +ToolWindow +AlwaysOnTop" )

	;Add a text control to act as a trigger for moving the window
Gui, 1: Add , Text , x0 y0 w200 h40 gMove_Window hwndForumTestHwnd

	;Add a text control to act as a trigger for getting a color from the screen
Gui, 1: Add , Text , x45 y75 w110 h30 gGetColor

	;Add a text control to act as a trigger for running the setting menu.
Gui, 1: Add , Text , x45 y103 w110 h30 gGetColor

	;Add a text control to act as a trigger for taking a screenshot.
Gui, 1: Add , Text , x45 y135 w20 h20 gCreate_Capture_Size_Window

	;Add a text control to act as a trigger for displaying the screenshots saved in the scripts folder.
Gui, 1: Add , Text , x75 y135 w20 h20 gShowPics


	;Add a text control to act as a trigger for launching the 3rd function.
Gui, 1: Add , Text , x105 y135 w20 h20 gTemp1

	;Add a text control to act as a trigger for launching the 4th function.
Gui, 1: Add , Text , x135 y135 w20 h20 gTemp2

	;Draw the main windows background to the graphics.
Gdip_DrawImage( CDisplay.G , HB_BITMAP_MAKER() , 0 , 0 , CDisplay.w , CDisplay.h ) 

	;Draw the Get Color button to the graphics.
Gdip_DrawImage( CDisplay.G , _Create_Default_Bitmap( 110 , 30 , "0xFF2D2F33" , "0xFF000000" , "0xFF3399FF" , "Get Color" , "12 Bold" , "0" , "Segoe UI" ) , 45 , 75 , 110 , 30 ) 

	;Draw the Settings button to the graphics.
Gdip_DrawImage( CDisplay.G , _Create_Default_Bitmap( 110 , 30 , "0xFF2D2F33" , "0xFF000000" , "0xFF3399FF" , "Settings" , "12 Bold" , "0" , "Segoe UI" ) , 45 , 103 , 110 , 30 ) 

	;Draw the graphics to the main window and set its default size and positioning.
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc , CDisplay.x , CDisplay.y , CDisplay.w , CDisplay.h )

	;Create a new brush 
Brush := Gdip_BrushCreateSolid( "0xFF2D2F33" )

	;Use the brush to cover the section of the graphics that will contain the text displaying the color.
Gdip_FillRectangle( CDisplay.G , Brush , 45 , 55 , 110 , 20 )

	;Delete the brush.
Gdip_DeleteBrush( Brush )

	;Add text to the graphics containing the color.
Gdip_TextToGraphics( CDisplay.G , OutColor := "0x3399ff" , "s12 Bold Center vCenter cFF3399FF  x45 y50" , "Segoe UI" , 110 , 30 )

	;Show the window hidden to set its default width and height.
Gui, 1: Show , hide w200 h200 , Gadget 

	;Show the window with its tabbed size.
Gui, 1: Show , % "h" 45 

	;Draw the graphics to the main window.
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )

;###################################################################################################
;Added Jan 7th, 2020
;Update the main window with the saved colors

Loop, 4	{
	OutColor := SavedColors[A_Index]
	ChangeColor(A_Index)
}

;###################################################################################################


	;Set a timer that will keep the main window on top of all other windows
SetTimer, Always , 2000

	;End of the Auto-Execute Section.
return

;*************************************************************************************************************************

;Subroutine: GuiClose

;Triggered by press the close button on a gui or by pressing the Hotkey Escape
;Once called the script will exit.

;*************************************************************************************************************************

GuiClose:
;~ *Esc::
	ExitApp


;*************************************************************************************************************************

;Function: Move_Window

;Called whenever the trigger text control at the top of the main gui or the sides of the Display Window are clicked.
;Allows the window to be moved around. Thinking about having the Display window follow the main window if it hasn't been moved yet.

;*************************************************************************************************************************

Move_Window(){
	;~ ToolTip, % A_GuiEvent
	if(A_GuiEvent="DoubleClick")
		ExitApp
		;Post WM_NCLBUTTONDOWN message to allow the active window to be dragged to a new location
	PostMessage, 0xA1 , 2
		
		;Redraw the graphics
	UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
	
}

;*************************************************************************************************************************

;Function: Temp1

;A placeholder function for button 3

;*************************************************************************************************************************

Temp1(){
	
	if(GetKeyState("Shift")){
		;If Shift is being held
		
			;Change the color of this button on the main gui to the one currently in the main color display.
		ChangeColor(3)
			
			;Write the new list of saved colors to file.
		WriteColors(3)
		
			;exit this thread
		return
		
	}
}

;*************************************************************************************************************************

;Function: Temp2

;A placeholder function for button 4

;*************************************************************************************************************************

Temp2(){
	
	if(GetKeyState("Shift")){
		;If Shift is being held
		
			;Change the color of this button on the main gui to the one currently in the main color display.
		ChangeColor(4)
		
			;Write the new list of saved colors to file.
		WriteColors(4)
		
			;exit this thread
		return
		
	}
	
}


;*************************************************************************************************************************

;Function: Always

;A timed function that puts the main gui on top of any other window ( even ones that are using the AlwaysOnTop setting )

;*************************************************************************************************************************

Always(){
	
		;Draw the window on top of all other windows
	Gui,1:Show,NA
	
}


;*************************************************************************************************************************

;Function: WriteColors

;This function is called every time one of the four saved colors is changed.
;Deletes the old file and then writes a new one with the updated saved colors.

;*************************************************************************************************************************

WriteColors(Position){
	SavedColors[Position] := OutColor 
	FileDelete,%A_ScriptDir%\Saved Colors.txt
	Loop, 4	{
		FileAppend,% SavedColors[A_Index]",",%A_ScriptDir%\Saved Colors.txt
	}
}



;*************************************************************************************************************************

;Function: GuiContextMenu

;Triggered by right clicking the main gui.
;Toggles between showing the main window at full size or tab sized.

;*************************************************************************************************************************

GuiContextMenu(){
	
		;Create a static variable to maintain the value of the toggle state
	static Tog := 1
	if( Tog := !Tog )
		;test if the inverted value is true while also setting it as the value
	
			;Show the main window with the tab sized height
		Gui , 1: Show , % "h" 45 
		
		
	else	{
		;if the value of the toggle is false 
	
			;Show the full sized main window
		Gui, 1: Show , % "h" 200
		
	}
	
		;Redraw the graphics
	UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
	
}

;*************************************************************************************************************************

;Function: ShowPics

;Triggered by pressing the Second Square on the main gui.
;This function is a hub for a number of actions that can happen depending on the keys that are being pressed when the button is pressed.
;Shows a timed tooltip displaying the main function of this button.

;*************************************************************************************************************************

ShowPics(){
	
		;Set the value for the message that contains the name of the main operation for this button
	Message := "View ScreenShots"
	
		;Set a timer to show the tooltip containing the message quickly following the mouse until the other timer turns it off.
	SetTimer, TooltipFollow , 30
	
		;Set a one time timer to turn off the tooltip timers
	SetTimer, TooltipOff , -900
	
	if( GetKeyState( "Shift" ) )
		;if the key shift is being held down when the button is pressed
	
			;Call the function to change the color on the button for this function ( Button 2 ), return and then write the new colors
		return ChangeColor( 2 ) , WriteColors( 2 )	
		
	else if( GetKeyState( "ctrl" ) )
		;If Control is being held when the button is pressed.
	
			;No action currently assigned for this key... yet.
		return
		
		;Get the x and y positions of the main gui to be used for the positioning of the Display Window.
	WingetPos, tx , ty ,,, % "ahk_ID " CDisplay.Hwnd
	
		;Call the function to create the Display Window, passing it the x and y coords. 
	Create_Display_Window( tx , ty + 190 )
	
}

;*************************************************************************************************************************

;Function: TooltipFollow

;A timed function that displays a tooltip at the current cursor location rapidly.
;This timer is terminated by another timer.

;*************************************************************************************************************************

TooltipFollow(){
	
		;Set the owner of the tooltip to the main gui so that the tooltip will always show above all windows.
	Gui, 1: +OwnDialogs
	
		;Display the tooltip containing the message.
	Tooltip, % Message
	
}

;*************************************************************************************************************************

;Function: TooltipOff

;A timed function that displays a tooltip at the current cursor location rapidly.
;This timer is terminated by another timer.

;*************************************************************************************************************************

TooltipOff(){
	
		;Turn off the timer for the message tooltip.
	SetTimer, TooltipFollow , Off
	
		;Turn off any active tooltips
	ToolTip,
	
}

;*************************************************************************************************************************

;Function: Create_Display_Window

;Create a small window that displays the screenshots taken with this device.

;*************************************************************************************************************************

Create_Display_Window( tx := "" , ty := "" ){
	
		;Select the object
	SelectObject( ShowWin.hdc , ShowWin.obm )
	
		;Delete the object
	DeleteObject( ShowWin.hbm )
	
		;Delete the device context
	DeleteDC( ShowWin.hdc )
	
		;Delete the graphics
	Gdip_deleteGraphics( ShowWin.G )
	
		;Destroy the Display Window if it already exists. I could just use the "New" option, but destroying the window is more fun. 
	Gui,5:Destroy
	
		;Create a new layered window.
	ShowWin := Layered_Window_SetUp( 3 , 0 , 0 , 970 , 220 , "5" , "+AlwaysOnTop -DPIScale -Caption +Owner1" ) 
	
		;Draw the graphics to the Display Window and set its default size and positioning.
	UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc , ShowWin.x , ShowWin.y , ShowWin.w , ShowWin.h )
	
		;Draw the background onto the graphics.
	Gdip_DrawImage(ShowWin.G, DW := DisplayWindow(), 0, 0, ShowWin.w, ShowWin.h) 
	
		;Delete the Background bitmap.
	Gdip_DisposeImage(DW)
	
		;Add a text control to act as a trigger for moving this window.
	Gui,5:Add,Text,x0 y0 w43 h220 gMove_Window
	
		;Add a text control to act as a trigger for moving this window.
	Gui,5:Add,Text,x927 y0 w43 h220 gMove_Window
	
		;Add a text control to act as a trigger for closing this window.
	Gui,5:Add,Text,x904 y40 w20 h110 g5GuiClose
	
		;Add a text control to act as a trigger for moving forward in the image list.
	Gui,5:Add,Text,x691 y176 w112 h19 gMoveForward
	
		;Add a text control to act as a trigger for moving Backward in the image list.
	Gui,5:Add,Text,x181 y176 w112 h19 gMoveBackward
	
		;Add a text control to act as a trigger for refreshing the image list and updating the Dispaly Window.
	Gui,5:Add,Text,x47 y42 w16 h106 gRefresh
	
		;Add a text control to act as a trigger for the center frame of the Display Window.
	Gui,5:Add,Text,x411 y21 w150 h150 hwndFrame1 gGetInfo1 
	
		;Add a text control to act as a trigger for moving Backward in the image list. (this may change, currently attached to one of the frames)
	Gui,5:Add,Text,x241 y21 w150 h150 hwndFrame2 gMoveBackward
	
		;Add a text control to act as a trigger for moving Backward in the image list. (this may change, currently attached to one of the frames)
	Gui,5:Add,Text,x71 y21 w150 h150 hwndFrame3 gMoveBackward
	
		;Add a text control to act as a trigger for moving Forward in the image list. (this may change, currently attached to one of the frames)
	Gui,5:Add,Text,x581 y21 w150 h150 hwndFrame4 gMoveforward
	
		;Add a text control to act as a trigger for moving Forward in the image list. (this may change, currently attached to one of the frames)
	Gui,5:Add,Text,x751 y21 w150 h150 hwndFrame5 gMoveforward
	
		;Get the size of the monitor that the cursor is currently in.
		;This is used in position the Display Window when it is first created.
		;Purpose is to have the Dispaly Window line up with the left edge of the main gui when possible or line up with the right side of the monitor when not.
	temp:=Monitors.Get_New_Window_Position(Monitors.Get_Current_Monitor(),0,0,2,2)
	
		;Get the current position of the main gui
	WinGetPos , tX, tY,,, % "ahk_ID " CDisplay.hwnd
	
		;Calculate if the Dispaly Window can be popped up at the same x position as the main gui, or if it needs to line up along the right side of the monitor
	(tx+970>temp.x)?(ntx := temp.x - 970 ):(ntx := tx)
	
		;Calculate if the Display Window can sit below the main gui, or if it needs to be placed above it.
	(ty+200+220+10 > temp.y)?(nty := (ty - 220) -10 ):(nty := ty + 200 + 10)
	
		;Show the Dispaly Window at the calculated position
	Gui, 5: Show , % "x" ntx " y" nty " w970 h220 NA"
	
		;Draw the graphics onto the Dispaly Window
	UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc )
	
		;Create a new List of all the images in the target folder
	ImageList1 := "" , ImageList1 := Get_File_List()
	
		;Draw a group of the images from the list to the Display Window Frames. (Based around the current value of "Index")
	UpdateWheel( Index , ImageList1 )
	
		;Start a timer to watch for the cursor moving over the center frame. This will cause a small window to pop up above the Display Window containing the Indexed Image
	SetTimer, ImageZoom , 300
	
}

;*************************************************************************************************************************

;Function: UpdateWheel

;Update the Display Window with the images found in the screenshot folder

;*************************************************************************************************************************

UpdateWheel( Index , ImageList1 ){
	
	if( !ImageList1 )
		;If there are no images in the folder
		
			;exit the function
		Return
	
		;Set an array with the positions for images to be placed.
	Positions := [ { x : 411 , y: 21 } , { x : 241 , y: 21 } , { x : 71 , y: 21 } , { x : 581 , y: 21 } , { x : 751 , y: 21 } ]
	
		;Create some variable / arrays to help in determining which image needs to get placed and what size it should be.
	Images := [] , PB := [] , caseit := [ 0 , -1 , -2 , +1 , +2 ] , Set := [ 150 , 70 , 70 , 70 , 70 ] 
	
	Loop, 5		{
		;Loop once for every frame in the Display Window.
	
			;Create a new brush, use it to redraw over each frame to remove any previous images, then delete the brush.
		Brush := Gdip_BrushCreateSolid( "0xFF000000" ) , Gdip_FillRectangle( ShowWin.G , Brush , Positions[A_Index].X , Positions[A_Index].Y , 150 , 150 ) , Gdip_DeleteBrush( Brush )
		
			;Create bitmaps of the images that need to be dispalyed.
		PB[ A_Index ] := Gdip_CreateBitmapFromFile( ImageList1[Index + caseit[ A_Index ] ] )
			
			;Resize each of the bitmaps to fit within the allotted space while maintaining the same aspect ratio 
		Centering := ResizeIt( PB[ A_Index ] , Width , Height , Set[ A_Index ] )
		
			;Check if there is a bitmap for the current index, and if there is, Draw it to the graphics
		( PB[ A_Index ] ) ? ( Gdip_DrawImage( ShowWin.G , PB[ A_Index ] , Positions[ A_Index ].X  , Positions[ A_Index ].Y  , Width , Height ) )
		
			;Delete the bitmaps to free up the memory
		Gdip_DisposeImage( PB[ A_Index ] )
		
	}
		
		;Create a new brush, paint over the area that contains the "Index" text, then delete the brush. 
	Brush := Gdip_BrushCreateSolid( "0xff333333" ),Gdip_FillRectangle( ShowWin.G , Brush , 810 , 174 , 80 , 20 ),Gdip_DeleteBrush( Brush )	
	
		;Create a new brush, paint the "Index" number, then delete the brush (Bottom layer of the text).
	Brush := Gdip_BrushCreateSolid( "0xff000000" ),Gdip_TextToGraphics( ShowWin.G , Index , "s18 Center vCenter Bold c" Brush " x800 y175" , "Segoe UI" , 100 , 20 ),Gdip_DeleteBrush( Brush )	
		
		;Create a new brush, paint the "Index" number, then delete the brush (Top layer of the text).
		Brush := Gdip_BrushCreateSolid( "0xff3399FF" ),Gdip_TextToGraphics( ShowWin.G , Index , "s18 Center vCenter Bold c" Brush " x801 y176" , "Segoe UI" , 100 , 20 ),Gdip_DeleteBrush( Brush )	
	
		;Draw the graphics to the Display Window.
	UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc )
	
}


;*************************************************************************************************************************

;Function: ImageZoom

;A timed routine that checks if the cursor is over the center image display frame in the Display Window ("ShowWin")
;If it is, create a small window with a larger example of the center image ("Index")

;*************************************************************************************************************************

ImageZoom(){
	
		;create a static control variable to help with flow of control
	static ActiveFrame 
	
		;get the hwnd of the control under the cursor
	MouseGetPos,,,, ctrl, 2
	
	if( !ActiveFrame && ctrl = Frame1 ) {
		;if the image display is not already active and if the control under the cursor is the center frame panel
		;create a display window containing the image from the center frame ("Index")
	
			;create a bitmap of the image (.png) saved in the folder
		pBit := Gdip_CreateBitmapFromFile( ImageList1[ Index ] ) 
	
			;resize and scale the image to its new size 
		ResizeIt( pBit, Width, Height, 400 )
		
			;Create a new floating window directly above the center frame containing the selected image
		CreateZoomWindow( pBit, Width, Height )
		
			;Once drawn to the graphics, the bitmap can get deleted. 
		Gdip_DisposeImage(pBit)
		
			;Set control variable to 1 so this part gets skipped until the control under the cursor is no longer the correct one.
		ActiveFrame := 1
		
	}else if( ActiveFrame && ctrl != Frame1 ){
		;if the image display is already active and if the control under the cursor is not the center frame panel
		;Destroy the zoom window and swap the value of the control variable
		
			;Destroy the Zoom Window
		Gui,6:Destroy
		
			;Set the control variable back to 0 so that the routine can begin waiting for the cursor can be back over the center frame again
		ActiveFrame := 0
	}
}

;*************************************************************************************************************************
;Function: CreateZoomWindow

; Create a window containing the selected image and display it directly above the certer frame of the Display Window ("ShowWin")
; Takes: pointer to the selected Bitmap, and the resized Width and Height. 
;*************************************************************************************************************************

CreateZoomWindow( pBit, Width, Height ){
		
		;if this window already exists, destory it ( destroying things is fun! ).
	Gui, 6: Destroy
	
		;Select the object
	SelectObject( ZoomWindow.hdc,ZoomWindow.obm)
	
		;Delete the object
	DeleteObject(ZoomWindow.hbm)
	
		;Delete the device context
	DeleteDC(ZoomWindow.hdc)
	
		;Delete the graphics
	Gdip_deleteGraphics(ZoomWindow.G)
	
		;Create a new Layered window to display the image on
	ZoomWindow := Layered_Window_SetUp( 2 , 0 , 0 , Width , Height , "6" , "+AlwaysOnTop -DPIScale -Caption +Owner5" ) 
	
		;Create a brush for the background of the Layered Window
	Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , Width , Height , "0xFF777777" , "0xFF000000" , 1 , 1 )
	
		;Paint the background of the window 
	Gdip_FillRectangle( ZoomWindow.G , Brush , 0 , 0 , Width , Height )
	
		;Delete the brush to free up the memory
	Gdip_DeleteBrush( Brush )	
	
		;Draw the bitmap of the selected image to onto the Graphics for the Layered Window 
	Gdip_DrawImage(ZoomWindow.G, pBit, 1, 1, ZoomWindow.w-2, ZoomWindow.h-2) 
	;~ Gdip_DisposeImage(pBit)
	
		;Update (Redraw) the Layered Window with the newly changed Graphics
	UpdateLayeredWindow(ZoomWindow.hwnd, ZoomWindow.hdc, ZoomWindow.x, ZoomWindow.y, ZoomWindow.w, ZoomWindow.h)
	
		;Get the position of the Dispaly Window 
	WinGetPos,tx,ty,,,% "ahk_ID " ShowWin.Hwnd
	
		;Display the ZoomWindow offset from the Display Window
	Gui,6:Show,% "x" ( tx + 411 + 75 - Width // 2 ) " y" ( ty + 21 - height - 20 ) " w" Width " h" Height " NA"
	
}

;*************************************************************************************************************************
;Function: ResizeIt

; Get the dimensions from a bitmap and then resize it so that the scale is maintained but the size is adjusted to fit in a defined space
; Takes: Pointer to a bitmap, defined Width and Height variable, The size of the defined area.
;*************************************************************************************************************************

ResizeIt( PB , ByRef tWidth , ByRef tHeight , InputValue ){
	
		;Get the Width and Height of the bitmap.
	Gdip_GetDimensions( PB , tWidth , tHeight )
	
	if( tWidth > InputValue && tWidth >= tHeight )
		;If the width is greater than the defined area and the width is greater than or equal to the height
		
			;Set the scale ratio to be the height divided by the width, set the width to be the max size, set the height to be the scaled value. 
		Ratio := tHeight / tWidth , tWidth := InputValue , tHeight := InputValue * Ratio 
		
		
	else if( tHeight > InputValue && tHeight >= tWidth )
		;If the height is greater than the defined area and the height is greater than or equal to the width
	
			;Set the scale ratio to be the width divided by the height, set the height to be the max size, set the width to be the scaled value. 
		Ratio := tWidth / tHeight , tHeight := InputValue , tWidth := InputValue * Ratio 
		
		
	else if( tWidth > InputValue && tWidth <= tHeight )
		;If the width is greater than the defined area and the Height is greater than or equal to the Width
	
			;Set the scale ratio to be the width divided by the height, set the height to be the max size, set the width to be the scaled value. 
		Ratio := tWidth / tHeight , tHeight := InputValue , tWidth := InputValue * Ratio 
		
}

;*************************************************************************************************************************
;Function: Refresh

; Creates a new list of the images in the target folder and then displays the newly updated list in the display window. 
;*************************************************************************************************************************

Refresh(){
	
		;Create a list of all the full paths of images in a folder
	ImageList1 := "" , ImageList1 := Get_File_List()
		
		;Draw the images on to the display window with the selected image in the center frame
	UpdateWheel( Index , ImageList1 )
	
}

;*************************************************************************************************************************
;Function: GetInfo1

; This is a hub for a number of actions that are connected to the center frame of the Display Window.
; Depending on the keys being pressed, different actions will occur. 

;*************************************************************************************************************************

GetInfo1(){
	
	if( GetKeyState( "ctrl" ) && GetKeyState( "Shift" ) )
		;If both the shift and control keys are being pressed when the frame is clicked
	
			;Remove the image from the Display Window and delete the image file in the target folder.
		RemoveImage( Index )
		
	else if( GetKeyState( "Shift" ) )
		;If only the shift key is being pressed when the center frame is click
	
		Try
			;Try to do a action, if it fails, do so silently
		
				;Run the center image in windows image viewer
			Run, % ImageList1[ Index ]
			
	else
		;If no keys are being pressed.
	
			;Put the full path of the image into the clipboard.
		Clipboard := ImageList1[ Index ]
		
}

;*************************************************************************************************************************
;Function: RemoveImage

;Delete the selected image file from the screenshot folder and then refresh the Dispaly Window and update the image list.
;Takes: The current index for the image in the center frame of the Display Window

;*************************************************************************************************************************

RemoveImage( inVal ){
	
		;Delete the selected file
	FileDelete, % ImageList1[ inVal ]
	
		;Refresh the Display Window
	Refresh()
	
}

;*************************************************************************************************************************

;Subroutine: MoveForward

;Triggered by pressing either the forward arrow button or by clicking on one of the frames to the right of the center frame in the Display Window 

;*************************************************************************************************************************

MoveForward:

	if( GetKeyState( "Shift" ) ){
		;If shift is being held when the button/buttons are pressed.
		
			;Check to see if the length of the image list is greater than the current index + 10, if it is, move forward 10, else set the index to the last position.
		( Index + 10 > ImageList1.Length() ) ? ( Index := ImageList1.Length() ) : ( Index += 10 )
		
			;Draw the newly selected batch of 5 images to the Display Window.
		UpdateWheel( Index , ImageList1 )
		
			;Exit thread
		return
		
	}
	
	if( Index >= ImageList1.Length() )
		;If the current value of "Index" is already at the end of the list.
	
			;Exit thread
		return
		
		;Add one to the value of "Index" and then draw the newly selected batch of 5 images to the Display Window.
	UpdateWheel( Index += 1 , ImageList1 )
	
	
	return
	
;*************************************************************************************************************************

;Subroutine: MoveBackward

;Triggered by pressing either the back arrow button or by clicking on one of the frames to the left of the center frame in the Display Window 

;*************************************************************************************************************************
	
MoveBackward:
	if( GetKeyState( "Shift" ) ){
		;If shift is being held when the button/buttons are pressed. 
		
			;Check to see if subtracting 10 from the current value of "Index" will be less than 1, if it is, set "Index" to 1, else set it to the current value - 10.
		( Index - 10 < 1 ) ? ( Index := 1 ) : ( Index -= 10 )
		
			;Draw the newly selected batch of 5 images to the Display Window.
		UpdateWheel( Index , ImageList1 )
		
			;Exit thread
		return
		
	}
	
	if( Index - 1 <= 0 )
		;If the value of "Index" is already at 1 or less
	
			;Exit thread
		return
		
		;Subtract one from the value of "Index" and then draw the newly selected batch of 5 images to the Display Window.
	UpdateWheel( Index -= 1 , ImageList1 )
	
	return
	
;*************************************************************************************************************************
;Function: Get_File_List

;Creates a list containing the full path to all .pngs in the screenshot folder

;*************************************************************************************************************************	

Get_File_List(){
		
		;Create a array to hold the file paths, set the loop index to 0
	Full_Path := [] , Index2 := 0
		
	Loop, %A_ScriptDir%\Screen Shots\*.png
		;Loop through the contents of the screenshot folder and sort for the ones with a .png extention.
	
			;Add the full path for each found file with the .png extention to the array.
		Full_Path[ ++Index2 ] := A_LoopFileFullPath
		
		;return the array to the caller.
	return Full_Path
	
}

;*************************************************************************************************************************

;Subroutine/s: 5GuiClose - 5GuiContextMenu

;Triggered by press the close button on the Display Window or by right clicking the window
;Once called the Display Window will be closed and related timers are turned off.

;*************************************************************************************************************************

5GuiClose:
5GuiContextMenu:

		;Select the object
	SelectObject( ShowWin.hdc,ShowWin.obm)
	
		;Delete the object
	DeleteObject(ShowWin.hbm)
	
		;Delete the device context
	DeleteDC(ShowWin.hdc)
	
		;Delete the graphics
	Gdip_deleteGraphics(ShowWin.G)
	
		;Destroy the Display Window
	Gui, 5: Destroy
	
	return

;*************************************************************************************************************************
;Function: Create_Capture_Size_Window

;Create a layered window that will be used to draw the cross lines for setting the capture area for the screenshot.  

;*************************************************************************************************************************	

Create_Capture_Size_Window(){
	
		;Create a static variable that is used to check if this is the first time this function is being called. Default = null / 0 / ""
	static ft
	
		;Set the main gui as the owner of the any tooltips so that they stay on top of all other windows
	Gui, 1: +OwnDialogs
	
		;Display a tooltip containing a message about what this button does ( its main function ).
	Tooltip, % Message := "Take ScreenShot"
	
		;Start a timer that once expired will turn off the other timer
	SetTimer, TooltipOff , -1800
	
		;Start a timer that will repeatedly display the message under the cursor
	SetTimer, TooltipFollow , 30
	
	if( GetKeyState( "Shift" ) ){
		;if the Shift key is being held when the button is pressed.
		
			;Change the color of this button on the main gui to the one currently in the main color display.
		ChangeColor( 1 )
		
			;Write the new list of saved colors to file.
		WriteColors( 1 )	
		
			;Exit thread
		return
		
	}
	
		;If this window already exists, destroy it. 
	Gui, 2: Destroy
	
		;Create a new Layered window to display the capture area lines
	CapWin := Layered_Window_SetUp( 3 , 0 , 0 , A_ScreenWidth , A_ScreenHeight , "2" , "+AlwaysOnTop -DPIScale -Caption +Owner1" )
	
	if( !ft )
		;If this is the first time running this function
		
			;Set the static variable to 1 so that this only happens the first time this function is called.
			;Create a timer that moves the drawing area to cover the current monitor.
		Monitors.Set_Window_Move_Timer( GUINAME := 2 , GUIHWND := CapWin.hwnd , TCount := 300 , xpOff := 0 , ypOff := 0 , xr := 1 , yr := 1 , Fill_Screen := 1 ) , ft := 1
	
	else
		;If this isn't the first time.
			
			;Turn on the timer for moving the drawing area to cover the current monitor
		Monitors.Window_Move_Obj.GUIHWND := CapWin.hwnd , Monitors.Turn_On_Window_Move_Timer()
	
		;Show the window
	Gui, 2: Show
	
		;Set the control variables used in the flow of the drawing function.
	CapActive := 1 , SP := 0 , OB := 0
	
		;Set a timer to be used for drawing the lines of the capture area.
	SetTimer, Set_Positions , 10
	
}

;*************************************************************************************************************************
;Function: ChangeColor

;Changes the color of one of the 4 colored buttons on the main gui  
;Takes: The position of the button being changed

;*************************************************************************************************************************	

ChangeColor( Value ){
	
		;Create a local array with the x position of the colored buttons.
	local tempArr := [ 48 , 78 , 108 , 138 ]
	
		;Create a brush, and then paint the button with the color in the main color display, then delete the brush.
	Brush := Gdip_BrushCreateSolid( "0xFF" SubStr( OutColor , 3 ) ) , Gdip_FillRectangle( CDisplay.G , Brush , tempArr[ Value ] , 139 , 14 , 12 ) , Gdip_DeleteBrush( Brush )
	
		;Create a line brush ( gradient brush ). 
	Brush := Gdip_CreateLineBrushFromRect( tempArr[ Value ] , 139 , 14 , 12 , "0xFF000000" , "0xFF777777" , 1 , 1 ) 
	
		;Create a pen from the brush.
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	
		;Delete the brush.
	Gdip_DeleteBrush( Brush )
	
		;Use the pen to draw a border around the new color.
	Gdip_DrawRectangle( CDisplay.G , Pen , tempArr[ Value ] , 139 , 14 , 12 )
	
		;Delete the pen.
	Gdip_DeletePen( Pen )
	
		;Draw the graphics to the window.
	UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
	
}

;*************************************************************************************************************************
;Function: Set_Positions

;A timed function that draws lines onto the screen.
;Used for setting the capture area of a screenshot.

;*************************************************************************************************************************	

Set_Positions(){
	
		;Set the coordmode used for tarcking the mouse position to be relative to the active window.
	Coordmode, Mouse , Window
	
		;Activate the capture window.
	WinActivate,% "ahk_ID " CapWin.Hwnd
	
		;Clear the graphics so that they can be redrawn in their new positions.
	Gdip_GraphicsClear(CapWin.g)
	
		;Get the current cursor position.
	MouseGetPos, tx , ty
	
	if(SP=0){
		;If setting the first position of the capture area.
		
			;Draw a line from the top of the current monitor to the bottom of the current monitor.
		Fill_Box(CapWin.G,BB,tx,0,1,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Bottom-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Top)
		
			;Draw a line from the Left side of the current monitor to the Right side of the current monitor.
		Fill_Box(CapWin.G,BB,0,ty,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Right-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Left,1)
		
			;Store the x and y positions into new variables
		TXC:=tx,TYC:=ty
		
	}else if(SP=1){
		;If the first position has already been set.
	
			;Draw the first line (starting position) for the x axis
		Fill_Box(CapWin.G,BB,TXC,0,1,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Bottom-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Top)
		
			;Draw the first line (starting position) for the y axis
		Fill_Box(CapWin.G,BB,0,TYC,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Right-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Left,1)
		
			;Draw a line at the current y position for the end point of the x axis
		Fill_Box(CapWin.G,BB,tx,0,1,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Bottom-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Top)
		
			;Draw a line at the current x position for the end point of the y axis
		Fill_Box(CapWin.G,BB,0,ty,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Right-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Left,1)
		
		if(TXC<tx&&TYC<ty){
			;if the second set of lines are below and to the right of the first set of lines.
			
				;Fill the area between the two sets of lines with a semi transparent green rectangle.
			Fill_Box(CapWin.G,GB,TXC,TYC,tx-TXC,ty-TYC)
			
				;Update some variables.
			WCAP:=tx-TXC,HCAP:=ty-TYC,OB:=0
			
				;Get the position of the top and left side of the current monitor. This is used to calculate the capture area.
			XCAP := TXC + Monitors.Monitor[ Monitors.Window_Move_Obj.Current_Monitor ].Left 
			
			YCAP := TYC + Monitors.Monitor[ Monitors.Window_Move_Obj.Current_Monitor ].Top
		
		}else if(TXC>tx&&TYC<ty){
			;If the second set of lines is above and to the left of the first set of lines.
			
				;Fill the area between the two sets of lines with a semi transparent red rectangle. (will be changing this to a valid action)
			Fill_Box( CapWin.G , GB , tx , TYC , TXC - tx , ty - TYC )
				
				;Set a variable to determin if a valid capture area has been set.
			;~ OB := 1
			
			WCAP := tx - TXC
			HCAP := ty - TYC
			OB := 1
			
			XCAP := TXC + Monitors.Monitor[ Monitors.Window_Move_Obj.Current_Monitor ].Left 
			
			YCAP := TYC + Monitors.Monitor[ Monitors.Window_Move_Obj.Current_Monitor ].Top
		
		}else if( TXC > tx && TYC > ty ){
			;if the second set of lines are below and to the left of the first set of lines.
			
				;Fill the area between the two sets of lines with a semi transparent red rectangle. (will be changing this to a valid action)
			Fill_Box( CapWin.G , RB , tx , ty , TXC - tx , TYC - ty )
			
				;Set a variable to determin if a valid capture area has been set.
			OB:=1
		
		}else if(TXC<tx&&TYC>ty){
			;if the second set of lines are above and to the right of the first set of lines.
			
				;Fill the area between the two sets of lines with a semi transparent red rectangle. (will be changing this to a valid action)
			Fill_Box(CapWin.G,RB,TXC,ty,tx-TXC,TYC-ty)
			
				;Set a variable to determin if a valid capture area has been set.
			OB:=1
		
		}
	
	}
	
		;Draw the graphics to the window.
	UpdateLayeredWindow(CapWin.hwnd, CapWin.hdc,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Left,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Top,Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Right-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Left, Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Bottom-Monitors.Monitor[Monitors.Window_Move_Obj.Current_Monitor].Top)

}

#IF (CapActive=1)

	LButton::
		if(SP=0)
			SP:=1
		else if(SP=1&&OB=0){
			
		
			CaptureShutDown()
			
			gosub,Take_ScreenShot
		
		}
		
		return
		
RButton::
CaptureShutDown(){
	
	
	Monitors.Turn_Off_Window_Move_Timer()
	
	
	CapActive := 0
	
	;~ SelectObject( CapWin.hdc , CapWin.obm ) , DeleteObject( CapWin.hbm ) , DeleteDC( CapWin.hdc ) , gdip_deleteGraphics( CapWin.g )
		
		;Select the object
	SelectObject( CapWin.hdc,CapWin.obm)
	
		;Delete the object
	DeleteObject(CapWin.hbm)
	
		;Delete the device context
	DeleteDC(CapWin.hdc)
	
		;Delete the graphics
	Gdip_deleteGraphics(CapWin.G)
	
	CapWin := "" , SP := 0
	
	
	Gui,2:Destroy
	
	
	SetTimer,Set_Positions,Off
	
	
	Sleep, 300
	
}	

	return
		
#IF



Take_ScreenShot:
	TempBitmap:=Gdip_BitmapFromScreen(XCAP "|" YCAP "|" WCAP "|" HCAP)
	ShotName:=A_Now
	Gdip_SaveBitmapToFile(TempBitmap,A_WorkingDir "\" ShotName ".png", 100)
	Gdip_DisposeImage(TempBitmap)
	Traytip,,Shot Saved
	return	



GetColor(){
	While(!GetKeyState("ctrl")){
		ToolTip,Hover over a color and press "ctrl"
		MouseGetPos,tx,ty
		PixelGetColor,OutColor,tx,ty, RGB
		Brush := Gdip_BrushCreateSolid( "0xFF2D2F33" )
		Gdip_FillRectangle( CDisplay.G , Brush , 45 , 55 , 110 , 20 )
		Gdip_DeleteBrush( Brush )
		Gdip_TextToGraphics( CDisplay.G , OutColor , "s12 Bold Center vCenter cFF3399FF  x45 y50" , "Segoe UI" , 110 , 30 )
		Brush := Gdip_BrushCreateSolid( "0xFF" SubStr(OutColor, 3 ) )
		Gdip_FillRectangle( CDisplay.G , Brush , 55 , 15 , 90 , 20 )
		Gdip_DeleteBrush( Brush )
		UpdateLayeredWindow(CDisplay.hwnd, CDisplay.hdc)
	}
	ToolTip,
	Clipboard := SubStr(OutColor, 3 )
}


_Create_Default_Bitmap( W , H , Background_Color , Font_Color_Bottom , Font_Color_Top , Text , Font_Size , Y_Offset , Font ){
		
		;Bitmap Created Using: HB Bitmap Maker
		pBitmap:=Gdip_CreateBitmap( W , H ) 
		G := Gdip_GraphicsFromImage( pBitmap )
		Gdip_SetSmoothingMode( G , 1 )
		Brush := Gdip_BrushCreateSolid( Background_Color )
		Gdip_FillRectangle( G , Brush , -2 , 0 , W+3 , H+3 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF141416" )
		Gdip_FillRectangle( G , Brush , 3 , 3 , W-6 , H-6 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 4 , 3 , W-9 , H-7 , "0xFF363C45" , "0xFF2B2C2E" , 1 , 1 )
		Gdip_FillRectangle( G , Brush , 4 , 4 , W-8 , H-8 )
		Gdip_DeleteBrush( Brush )
		Pen := Gdip_CreatePen( "0xFF4D535B" , 1 )
		Gdip_DrawLine( G , Pen , 4 , 4 , W-5 , 4 )
		Gdip_DeletePen( Pen )
		Brush := Gdip_BrushCreateSolid( Font_Color_Bottom )
		Gdip_TextToGraphics( G , Text , "s" Font_Size " Center vCenter c" Brush " x0 y1" , Font , W , H )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( Font_Color_Top )
		Gdip_TextToGraphics( G , Text, "s" Font_Size " Center vCenter c" Brush " x1 y0"  , Font , W , H )
		Gdip_DeleteBrush( Brush )
		Gdip_DeleteGraphics( G )
		return pBitmap
	}



HB_BITMAP_MAKER(){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( 200 , 200 ) 
	G := Gdip_GraphicsFromImage( pBitmap )
	Gdip_SetSmoothingMode( G , 4 )
	Brush := Gdip_CreateLineBrush( 0 , 0 , 100 , 100 , "0x88F0F0F0" , "0xaa000000" , 1 )
	Gdip_FillRoundedRectangle( G , Brush , 10 , 50 , 180 , 140 , 25 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrush( 7 , 184 , 100 , 100 , "0x44F0F0F0" , "0x88000000" , 1 )
	Gdip_FillRoundedRectangle( G , Brush , 10 , 50 , 180 , 140 , 25 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF2D2F33" )
	Gdip_FillRectangle( G , Brush , 40 , 50 , 120 , 110 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 17 , 13 , 165 , 177 , "0xFFF0F0F0" , "0xFF000000" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 3 ) 
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRoundedRectangle( G , Pen , 10 , 50 , 180 , 140 , 25 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 53 , 10 , 116 , 56 , "0xFF444444" , "0xFF030E0E" , 1 , 1 )
	Gdip_FillRoundedRectangle( G , Brush , 50 , 10 , 100 , 30 , 5 ) 
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrush( 110 , 46 , 113 , -3 , "0xFF102A2A" , "0xFFF0F0F0" , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRoundedRectangle( G , Pen , 50 , 10 , 100 , 30 , 5 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrush( 110 , 46 , 113 , -3 , "0xFF004444" , "0xFFF0F0F0" , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 2 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRoundedRectangle( G , Pen , 50 , 10 , 100 , 30 , 5 ) 
	Gdip_DeletePen( Pen )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRoundedRectangle( G , Brush , 55 , 15 , 90 , 20 , 5 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 43 , 131 , 56 , 57 , "0xFF444444" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 45 , 135 , 20 , 20 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 133 , 132 , 27 , 31 , "0xFF777777" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 135 , 135 , 20 , 20 )  ;<----------
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 133 , 132 , 27 , 31 , "0xFF777777" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 45 , 135 , 20 , 20 )  ;<---------------------
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF444444" )
	Gdip_FillRectangle( G , Brush , 105 , 135 , 20 , 20 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF444444" )
	Gdip_FillRectangle( G , Brush , 75 , 135 , 20 , 20 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 133 , 132 , 27 , 31 , "0xFF777777" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 75 , 135 , 20 , 20 ) ;<---------------------
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRectangle( G , Brush , 48 , 139 , 14 , 12 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRectangle( G , Brush , 78 , 139 , 14 , 12 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 133 , 132 , 27 , 31 , "0xFF777777" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 105 , 135 , 20 , 20 ) ;<---------------------
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRectangle( G , Brush , 108 , 139 , 14 , 12 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" )
	Gdip_FillRectangle( G , Brush , 138 , 139 , 14 , 12 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 45 , 135 , 20 , 20 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 75 , 135 , 20 , 20 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 105 , 135 , 20 , 20 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 48 , 139 , 14 , 12 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 78 , 139 , 14 , 12 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 108 , 139 , 14 , 12 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 66 , 157 , 26 , 25 , "0xFF000000" , "0xFF777777" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 138 , 139 , 14 , 12 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_CreateLineBrushFromRect( 133 , 133 , 23 , 22 , "0xFF777777" , "0xFF000000" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 1 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRectangle( G , Pen , 135 , 135 , 20 , 20 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFF121315" , 3)
	Gdip_DrawLine( G , Pen , 40 , 160 , 40 , 53 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFF121315" , 2)
	Gdip_DrawLine( G , Pen , 40 , 160 , 159 , 160 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFF121315" , 3)
	Gdip_DrawLine( G , Pen , 160 , 53 , 160 , 160 )
	Gdip_DeletePen( Pen )
	Gdip_DeleteGraphics( G )
	return pBitmap
}

DisplayWindow(){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( 970 , 220 ) 
	G := Gdip_GraphicsFromImage( pBitmap )
	Gdip_SetSmoothingMode( G , 2 )
	;~ 
	Brush := Gdip_CreateLineBrushFromRect( 14 , 9 , 947 , 178 , "0x44F0F0F0" , "0x88000000" , 1 , 1 )
	Gdip_FillRoundedRectangle( G , Brush , 10 , 10 , 950 , 200 , 25 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF333333" )
	Gdip_FillRectangle( G , Brush , 40 , 10 , 890 , 190 )
	Gdip_DeleteBrush( Brush )
	;Slot 1
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 70 , 20 , 150 , 150 )
	Gdip_DeleteBrush( Brush )
	;Slot  2
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 240 , 20 , 150 , 150 )
	Gdip_DeleteBrush( Brush )
	;Slot  3
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 410 , 20 , 150 , 150 )
	Gdip_DeleteBrush( Brush )
	;Slot  4
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 580 , 20 , 150 , 150 )
	Gdip_DeleteBrush( Brush )
	;Slot  5
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 750 , 20 , 150 , 150 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 17 , 13 , 165 , 177 , "0xFFF0F0F0" , "0xFF000000" , 1 , 1 )
	Pen := Gdip_CreatePenFromBrush( Brush , 3 )
	Gdip_DeleteBrush( Brush )
	Gdip_DrawRoundedRectangle( G , Pen , 10 , 10 , 950 , 200 , 25 )
	Gdip_DeletePen( Pen )
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 320 , 184 , 350 , 5 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 180 , 0 , 210 , 376 , "0xFF333333" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 181 , 176 , 112 , 19 ) ;<--------------------------------------------------------------
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF444444" )
	Gdip_FillPolygon( G , Brush , "260,180|215,185|260,190|" )
	Gdip_DeleteBrush( Brush )
	;close button
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 904 , 40 , 20 , 110 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_CreateLineBrushFromRect( 905 , 42 , 34 , 191 , "0xFF333333" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 906 , 42 , 16 , 106 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x99000000" )
	;part of close
	Gdip_TextToGraphics( G , "Close" , "s10 Center vCenter Bold c" Brush " x907 y32" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x99F0F0F0" )
	;part of close
	Gdip_TextToGraphics( G , "CLOSE" , "s10 Center vCenter Bold c" Brush " x909 y33" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x993399FF" )
	;part of close
	Gdip_TextToGraphics( G , "CLOSE" , "s10 Center vCenter Bold c" Brush " x909 y33" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_CreateLineBrushFromRect( 180 , 0 , 210 , 376 , "0xFF333333" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 691 , 176 , 112 , 19 )
	Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFF444444" )
	Gdip_FillPolygon( G , Brush , "725,180|770,185|725,190|" )
	Gdip_DeleteBrush( Brush )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 905 , 41 , 18 , 108 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 40 , 12 , 889 , 188 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 69 , 19 , 152 , 152 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 239 , 19 , 152 , 152 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 409 , 19 , 152 , 152 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 579 , 19 , 152 , 152 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 749 , 19 , 152 , 152 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 180 , 175 , 114 , 21 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 319 , 183 , 352 , 6 )
	Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 690 , 175 , 114 , 21 )
	Gdip_DeletePen( Pen )
	;close button
	Brush := Gdip_BrushCreateSolid( "0xFF000000" )
	Gdip_FillRectangle( G , Brush , 45 , 40 , 20 , 110 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_CreateLineBrushFromRect( 905 , 42 , 34 , 191 , "0xFF333333" , "0xFF000000" , 1 , 1 )
	Gdip_FillRectangle( G , Brush , 47 , 42 , 16 , 106 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x99000000" )
	;part of close
	Gdip_TextToGraphics( G , "REFRESH" , "s10 Center vCenter Bold c" Brush " x49 y32" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x99F0F0F0" )
	;part of close
	Gdip_TextToGraphics( G , "REFRESH" , "s10 Center vCenter Bold c" Brush " x50 y33" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	;part of close
	Brush := Gdip_BrushCreateSolid( "0x993399FF" )
	;part of close
	Gdip_TextToGraphics( G , "REFRESH" , "s10 Center vCenter Bold c" Brush " x50 y33" , "Segoe UI" , 10 , 130 )
	Gdip_DeleteBrush( Brush )
	Pen := Gdip_CreatePen( "0x443399FF" , 1 )
	Gdip_DrawRectangle( G , Pen , 46 , 41 , 18 , 108 )
	Gdip_DeletePen( Pen )
	Gdip_DeleteGraphics( G )
	return pBitmap
}

;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------

class MonitorClass	{
	__New(){
		This._SetMonCount()
		This._SetPrimeMonitor()
		This._Set_Bounds()
	}
	_SetMonCount(){
		local MC
		SysGet, MC, MonitorCount 
		This.MonitorCount := MC
	}
	_SetPrimeMonitor(){
		local PM
		SysGet, PM, MonitorPrimary
		This.PrimeMonitor := PM
	}
	_Set_Bounds(){
		local bmon,bmonLeft,bmonRight,bmonTop,bmonBottom
		This.Monitors:=[]
		Loop,% This.MonitorCount	{
			SysGet, bmon, Monitor, % A_Index
			This.Monitor[A_Index]:=	{ Left		: 	bmonLeft
									, Top		: 	bmonTop
									, Right		: 	bmonRight
									, Bottom	: 	bmonBottom 	}
		}
	}
	Get_Current_Monitor(){
		local x,y
		CoordMode,Mouse,Screen
		MouseGetPos,x,y
		Loop,% This.MonitorCount	{
			if(x>=This.Monitor[A_Index].Left&&x<=This.Monitor[A_Index].Right&&y>=This.Monitor[A_Index].Top&&y<=This.Monitor[A_Index].Bottom){
				return A_Index
			}
		}
	}
	Get_New_Window_Position(curMon,xpOff,ypOff,xr,yr){
		local tposa:="",tposa:={}
		if(xr=1) ; 1 xr = relative to the left side ; 2 xr = relative to the right side
			tposa.x:=This.Monitor[curMon].Left+xpOff
		else 
			tposa.x:=This.Monitor[curMon].Right-xpOff
		if(yr=1) ; 1 yr = relative to the top  ; 2 yr = relative to the bottom
			tposa.y:=This.Monitor[curMon].Top+ypOff
		else 
			tposa.y:=This.Monitor[curMon].Bottom-ypOff
		return tposa
	}
	Set_Window_Move_Timer(GUINAME:=1,GUIHWND:="",TCount:=500,xpOff:=0,ypOff:=0,xr:=1,yr:=1,Fill_Screen:=0){
		
		local Window_Timer
		
		This.Window_Move_Obj:=	{ 	Interval		:	TCount
								,	GUINAME			:	GUINAME
								,	FILLSCREEN		:	Fill_Screen
								,	GUIHWND			:	GUIHWND
								,	XPOFF			:	xpOff
								,	YPOFF			:	ypOff
								,	XRelative		:	xr
								,	YRelative		:	yr	
								,	Current_Monitor	:	This.Get_Current_Monitor()
								,	Old_Monitor		:	This.Get_Current_Monitor()	
								,	NEW_GUI_POS		:	This.Get_New_Window_Position(This.Get_Current_Monitor(),xpOff,ypOff,xr,yr)	}
								
		This.Window_Timer := Window_Timer :=  ObjBindMethod(This, "_Window_Move_Timer")
		
		This._Set_TFTime()
		
		SetTimer,%Window_Timer%,%TCount%
		
	}
	_Window_Move_Timer(){
		This.Window_Move_Obj.Current_Monitor := This.Get_Current_Monitor()
		if(This.Window_Move_Obj.Current_Monitor!=This.Window_Move_Obj.Old_Monitor&&!DllCall("IsIconic", "Ptr", This.Window_Move_Obj.GUIHWND, "UInt")){
			This.Window_Move_Obj.NEW_GUI_POS:=This.Get_New_Window_Position(This.Window_Move_Obj.Current_Monitor,This.Window_Move_Obj.XPOFF,This.Window_Move_Obj.YPOFF,This.Window_Move_Obj.XRelative,This.Window_Move_Obj.YRelative)
			This._Move_Window()
			This.Window_Move_Obj.Old_Monitor := This.Window_Move_Obj.Current_Monitor
		}
	}
	_Set_TFTime(){
		This.Window_Move_Obj.Current_Monitor := This.Get_Current_Monitor()
		This.Window_Move_Obj.NEW_GUI_POS:=This.Get_New_Window_Position(This.Window_Move_Obj.Current_Monitor,This.Window_Move_Obj.XPOFF,This.Window_Move_Obj.YPOFF,This.Window_Move_Obj.XRelative,This.Window_Move_Obj.YRelative)
		This.Window_Move_Obj.Old_Monitor := This.Window_Move_Obj.Current_Monitor
		This._Move_Window()
	}
	_Move_Window(){
		if(!This.Window_Move_Obj.FILLSCREEN)
			Gui,% This.Window_Move_Obj.GUINAME ":Show",% "x" This.Window_Move_Obj.NEW_GUI_POS.X " y" This.Window_Move_Obj.NEW_GUI_POS.Y " NA"
		else
			Gui,% This.Window_Move_Obj.GUINAME ":Show",% "x" This.Window_Move_Obj.NEW_GUI_POS.X " y" This.Window_Move_Obj.NEW_GUI_POS.Y " w" This.Monitor[This.Window_Move_Obj.Current_Monitor].Right " h" This.Monitor[This.Window_Move_Obj.Current_Monitor].Bottom " NA"
	}
	Turn_Off_Window_Move_Timer(){
		local Window_Timer
		Window_Timer := This.Window_Timer
		SetTimer,%Window_Timer%,Off
	}
	Turn_On_Window_Move_Timer(){
		local Window_Timer
		Window_Timer := This.Window_Timer
		This._Set_TFTime()
		SetTimer,%Window_Timer%,On
	}
	GetGuiPos(){
		local x,y
		WinGetPos,x,y,,,% "ahk_id " This.Window_Move_Obj.GUIHWND 
		return x
	}
}




;Shit that I (Hellbent) added
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Layered_Window_SetUp(Smoothing,Window_X,Window_Y,Window_W,Window_H,Window_Name:=1,Window_Options:=""){
	Layered:={}
	Layered.W:=Window_W
	Layered.H:=Window_H
	Layered.X:=Window_X
	Layered.Y:=Window_Y
	Layered.Name:=Window_Name
	Layered.Options:=Window_Options
	;~ Layered.Token:=Gdip_Startup()
	Create_Layered_GUI(Layered)
	Layered.hwnd:=winExist()
	Layered.hbm := CreateDIBSection(Window_W,Window_H)
	Layered.hdc := CreateCompatibleDC()
	Layered.obm := SelectObject(Layered.hdc,Layered.hbm)
	Layered.G := Gdip_GraphicsFromHDC(Layered.hdc)
	Gdip_SetSmoothingMode(Layered.G,Smoothing)
	return Layered
}

Create_Layered_GUI(Layered){
	Gui,% Layered.Name ": +E0x80000 +LastFound " Layered.Options 
	;~ Gui,% Layered.Name ":Show",% "x" Layered.X " y" Layered.Y " w" Layered.W " h" Layered.H " NA"
}
	
Layered_Window_ShutDown(This){
	SelectObject(This.hdc,This.obm)
	DeleteObject(This.hbm)
	DeleteDC(This.hdc)
	gdip_deleteGraphics(This.g)
	Gdip_Shutdown(This.Token)
}

New_Brush(colour:="000000",Alpha:="FF"){
	new_colour := "0x" Alpha colour 
	return Gdip_BrushCreateSolid(new_colour)
}

New_Pen(colour:="000000",Alpha:="FF",Width:= 5){
	new_colour := "0x" Alpha colour 
	return Gdip_CreatePen(New_Colour,Width)
}	

Fill_Box(pGraphics,pBrush,x,y,w,h)	{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRectangle", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
}
;######################################################################################################################################
;#####################################################   					    #######################################################
;#####################################################  	  Gdip LITE		    #######################################################
;#####################################################  					    #######################################################
;######################################################################################################################################
; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
;#####################################################################################
;~ Gdip_DeleteRegion(Region)
;~ {
	;~ return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
;~ }
DestroyIcon(hIcon)
{
	return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
}
Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	, PtrA := A_PtrSize ? "UPtr*" : "UInt*"
	
	SplitPath, sFile,,, ext
	if ext in exe,dll
	{
		Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
		BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
		
		VarSetCapacity(buf, BufSize, 0)
		Loop, Parse, Sizes, |
		{
			DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
			
			if !hIcon
				continue

			if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
			{
				DestroyIcon(hIcon)
				continue
			}
			
			hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
			hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
			if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
			{
				DestroyIcon(hIcon)
				continue
			}
			break
		}
		if !hIcon
			return -1

		Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
		hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
		if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
		{
			DestroyIcon(hIcon)
			return -2
		}
		
		VarSetCapacity(dib, 104)
		DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
		Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
		DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
		pBitmap := Gdip_CreateBitmap(Width, Height)
		G := Gdip_GraphicsFromImage(pBitmap)
		, Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
		SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
		Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
		DestroyIcon(hIcon)
	}
	else
	{
		if (!A_IsUnicode)
		{
			VarSetCapacity(wFile, 1024)
			DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
			DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
		}
		else
			DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
	}
	
	return pBitmap
}

Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height){
	Gdip_GetImageDimensions(pBitmap, Width, Height)
}

Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
{
    return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
}

BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster=""){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdi32\BitBlt", Ptr, dDC, "int", dx, "int", dy, "int", dw, "int", dh, Ptr, sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020)
}

Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
	return pBitmap
}

UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if ((x != "") && (y != ""))
		VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")

	if (w = "") ||(h = "")
		WinGetPos,,, w, h, ahk_id %hwnd%
   
	return DllCall("UpdateLayeredWindow"
					, Ptr, hwnd
					, Ptr, 0
					, Ptr, ((x = "") && (y = "")) ? 0 : &pt
					, "int64*", w|h<<32
					, Ptr, hdc
					, "int64*", 0
					, "uint", 0
					, "UInt*", Alpha<<16|1<<24
					, "uint", 2)
}

Gdip_BitmapFromScreen(Screen=0, Raster="")
{
	if (Screen = 0)
	{
		Sysget, x, 76
		Sysget, y, 77	
		Sysget, w, 78
		Sysget, h, 79
	}
	else if (SubStr(Screen, 1, 5) = "hwnd:")
	{
		Screen := SubStr(Screen, 6)
		if !WinExist( "ahk_id " Screen)
			return -2
		WinGetPos,,, w, h, ahk_id %Screen%
		x := y := 0
		hhdc := GetDCEx(Screen, 3)
	}
	else if (Screen&1 != "")
	{
		Sysget, M, Monitor, %Screen%
		x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
	}
	else
	{
		StringSplit, S, Screen, |
		x := S1, y := S2, w := S3, h := S4
	}

	if (x = "") || (y = "") || (w = "") || (h = "")
		return -1

	chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
	BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
	ReleaseDC(hhdc)
	
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
	return pBitmap
}

Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	SplitPath, sOutput,,, Extension
	if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
		return -1
	Extension := "." Extension

	DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
	VarSetCapacity(ci, nSize)
	DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
	if !(nCount && nSize)
		return -2
	
	If (A_IsUnicode){
		StrGet_Name := "StrGet"
		Loop, %nCount%
		{
			sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
			if !InStr(sString, "*" Extension)
				continue
			
			pCodec := &ci+idx
			break
		}
	} else {
		Loop, %nCount%
		{
			Location := NumGet(ci, 76*(A_Index-1)+44)
			nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
			VarSetCapacity(sString, nSize)
			DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
			if !InStr(sString, "*" Extension)
				continue
			
			pCodec := &ci+76*(A_Index-1)
			break
		}
	}
	
	if !pCodec
		return -3

	if (Quality != 75)
	{
		Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
		if Extension in .JPG,.JPEG,.JPE,.JFIF
		{
			DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
			VarSetCapacity(EncoderParameters, nSize, 0)
			DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
			Loop, % NumGet(EncoderParameters, "UInt")      ;%
			{
				elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
				if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
				{
					p := elem+&EncoderParameters-pad-4
					NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
					break
				}
			}      
		}
	}

	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
		VarSetCapacity(wOutput, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
		VarSetCapacity(wOutput, -1)
		if !VarSetCapacity(wOutput)
			return -4
		E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
	}
	else
		E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
	return E ? -5 : 0
}

Gdip_Shutdown(pToken)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
	if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("FreeLibrary", Ptr, hModule)
	return 0
}

Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
	DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
}

Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
{
	pi := 3.14159, TAngle := Angle*(pi/180)
	if !(Width && Height)
		return -1
	RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
	RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
}

;#####################################################################################
Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
{
	pi := 3.14159, TAngle := Angle*(pi/180)	

	Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
	if ((Bound >= 0) && (Bound <= 90))
		xTranslation := Height*Sin(TAngle), yTranslation := 0
	else if ((Bound > 90) && (Bound <= 180))
		xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
	else if ((Bound > 180) && (Bound <= 270))
		xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
	else if ((Bound > 270) && (Bound <= 360))
		xTranslation := 0, yTranslation := -Width*Sin(TAngle)
}

Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	if (Matrix&1 = "")
		ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
	else if (Matrix != 1)
		ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
	if(sx = "" && sy = "" && sw = "" && sh = ""){
		if(dx = "" && dy = "" && dw = "" && dh = ""){
			sx := dx := 0, sy := dy := 0
			sw := dw := Gdip_GetImageWidth(pBitmap)
			sh := dh := Gdip_GetImageHeight(pBitmap)
		}else	{
			sx := sy := 0,sw := Gdip_GetImageWidth(pBitmap),sh := Gdip_GetImageHeight(pBitmap)
		}
	}
	E := DllCall("gdiplus\GdipDrawImageRectRect", Ptr, pGraphics, Ptr, pBitmap, "float", dx, "float", dy, "float", dw, "float", dh, "float", sx, "float", sy, "float", sw, "float", sh, "int", 2, Ptr, ImageAttr, Ptr, 0, Ptr, 0)
	if ImageAttr
		Gdip_DisposeImageAttributes(ImageAttr)
	return E
}
Gdip_SetImageAttributesColorMatrix(Matrix){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	VarSetCapacity(ColourMatrix, 100, 0)
	Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
	StringSplit, Matrix, Matrix, |
	Loop, 25
	{
		Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
		NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
	}
	DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
	DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
	return ImageAttr
}
Gdip_GetImageWidth(pBitmap){
   DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
   return Width
}
Gdip_GetImageHeight(pBitmap){
   DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
   return Height
}
Gdip_DeletePen(pPen){
   return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
}
Gdip_DeleteBrush(pBrush){
   return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
}
Gdip_DisposeImage(pBitmap){
   return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
}
Gdip_DeleteGraphics(pGraphics){
   return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}
Gdip_DisposeImageAttributes(ImageAttr){
	return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
}
Gdip_DeleteFont(hFont){
   return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
}
Gdip_DeleteStringFormat(hFormat){
   return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
}
Gdip_DeleteFontFamily(hFamily){
   return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
}
CreateCompatibleDC(hdc=0){
   return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
SelectObject(hdc, hgdiobj){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
}
DeleteObject(hObject){
   return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
}
GetDC(hwnd=0){
	return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
}
GetDCEx(hwnd, flags=0, hrgnClip=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
    return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
}
ReleaseDC(hdc, hwnd=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
}
DeleteDC(hdc){
   return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
Gdip_SetClipRegion(pGraphics, Region, CombineMode=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	hdc2 := hdc ? hdc : GetDC()
	VarSetCapacity(bi, 40, 0)
	NumPut(w, bi, 4, "uint"), NumPut(h, bi, 8, "uint"), NumPut(40, bi, 0, "uint"), NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16, "uInt"), NumPut(bpp, bi, 14, "ushort")
	hbm := DllCall("CreateDIBSection", Ptr, hdc2, Ptr, &bi, "uint", 0, A_PtrSize ? "UPtr*" : "uint*", ppvBits, Ptr, 0, "uint", 0, Ptr)
	if !hdc
		ReleaseDC(hdc2)
	return hbm
}
Gdip_GraphicsFromImage(pBitmap){
	DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
	return pGraphics
}
Gdip_GraphicsFromHDC(hdc){
    DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
    return pGraphics
}
Gdip_GetDC(pGraphics){
	DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
	return hdc
}
Gdip_Startup(){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("LoadLibrary", "str", "gdiplus")
	VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
	DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
	return pToken
}
Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0){
	IWidth := Width, IHeight:= Height
	RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
	RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
	RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
	RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
	RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
	RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
	RegExMatch(Options, "i)NoWrap", NoWrap)
	RegExMatch(Options, "i)R(\d)", Rendering)
	RegExMatch(Options, "i)S(\d+)(p*)", Size)
	if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
		PassBrush := 1, pBrush := Colour2
	if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
		return -1
	Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
	Loop, Parse, Styles, |
	{
		if RegExMatch(Options, "\b" A_loopField)
		Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
	}
	Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
	Loop, Parse, Alignments, |
	{
		if RegExMatch(Options, "\b" A_loopField)
			Align |= A_Index//2.1      ; 0|0|1|1|2|2
	}
	xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
	ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
	Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
	Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
	if !PassBrush
		Colour := "0x" (Colour2 ? Colour2 : "ff000000")
	Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
	Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
	hFamily := Gdip_FontFamilyCreate(Font)
	hFont := Gdip_FontCreate(hFamily, Size, Style)
	FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
	hFormat := Gdip_StringFormatCreate(FormatStyle)
	pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
	if !(hFamily && hFont && hFormat && pBrush && pGraphics)
		return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
	CreateRectF(RC, xpos, ypos, Width, Height)
	Gdip_SetStringFormatAlign(hFormat, Align)
	Gdip_SetTextRenderingHint(pGraphics, Rendering)
	ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
	if vPos
	{
		StringSplit, ReturnRC, ReturnRC, |
		if (vPos = "vCentre") || (vPos = "vCenter")
			ypos += (Height-ReturnRC4)//2
		else if (vPos = "Top") || (vPos = "Up")
			ypos := 0
		else if (vPos = "Bottom") || (vPos = "Down")
			ypos := Height-ReturnRC4
		CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
		ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
	}
	if !Measure
		E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
	if !PassBrush
		Gdip_DeleteBrush(pBrush)
	Gdip_DeleteStringFormat(hFormat)
	Gdip_DeleteFont(hFont)
	Gdip_DeleteFontFamily(hFamily)
	return E ? E : ReturnRC
}
Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
		VarSetCapacity(wString, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
	}
	return DllCall("gdiplus\GdipDrawString", Ptr, pGraphics, Ptr, A_IsUnicode ? &sString : &wString, "int", -1, Ptr, hFont, Ptr, &RectF, Ptr, hFormat, Ptr, pBrush)
}
Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
	DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
	return LGpBrush
}
Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1){
	CreateRectF(RectF, x, y, w, h)
	DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
	return LGpBrush
}
Gdip_CloneBrush(pBrush){
	DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
	return pBrushClone
}
Gdip_FontFamilyCreate(Font){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
		VarSetCapacity(wFont, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
	}
	DllCall("gdiplus\GdipCreateFontFamilyFromName", Ptr, A_IsUnicode ? &Font : &wFont, "uint", 0, A_PtrSize ? "UPtr*" : "UInt*", hFamily)
	return hFamily
}
Gdip_SetStringFormatAlign(hFormat, Align){
   return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
}
Gdip_StringFormatCreate(Format=0, Lang=0){
   DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
   return hFormat
}
Gdip_FontCreate(hFamily, Size, Style=0){
   DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
   return hFont
}
Gdip_CreatePen(ARGB, w){
   DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
   return pPen
}
Gdip_CreatePenFromBrush(pBrush, w){
	DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
	return pPen
}
Gdip_BrushCreateSolid(ARGB=0xff000000){
	DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
	return pBrush
}
Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0){
	DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
	return pBrush
}
CreateRectF(ByRef RectF, x, y, w, h){
   VarSetCapacity(RectF, 16)
   NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
}
Gdip_SetTextRenderingHint(pGraphics, RenderingHint){
	return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
}
Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	VarSetCapacity(RC, 16)
	if !A_IsUnicode
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
		VarSetCapacity(wString, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
	}
	DllCall("gdiplus\GdipMeasureString", Ptr, pGraphics, Ptr, A_IsUnicode ? &sString : &wString, "int", -1, Ptr, hFont, Ptr, &RectF, Ptr, hFormat, Ptr, &RC, "uint*", Chars, "uint*", Lines)
	return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
}
CreateRect(ByRef Rect, x, y, w, h){
	VarSetCapacity(Rect, 16)
	NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
}
CreateSizeF(ByRef SizeF, w, h){
   VarSetCapacity(SizeF, 8)
   NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")
}
CreatePointF(ByRef PointF, x, y){
   VarSetCapacity(PointF, 8)
   NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")
}
Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawArc", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawLine", Ptr, pGraphics, Ptr, pPen, "float", x1, "float", y1, "float", x2, "float", y2)
}
Gdip_DrawLines(pGraphics, pPen, Points){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}
	return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
}
Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRectangle", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r){
	Region := Gdip_GetClipRegion(pGraphics)
	Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
	E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
	Gdip_SetClipRegion(pGraphics, Region, 0)
	Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
	Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
	Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
	Gdip_SetClipRegion(pGraphics, Region, 0)
	Gdip_DeleteRegion(Region)
	return E
}
Gdip_GetClipRegion(pGraphics){
	Region := Gdip_CreateRegion()
	DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
	return Region
}
Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0){
   return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
}
Gdip_SetClipPath(pGraphics, Path, CombineMode=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
}
Gdip_ResetClip(pGraphics){
   return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}
Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRegion(pGraphics, pBrush, Region){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
}
Gdip_FillPath(pGraphics, pBrush, Path){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
}
Gdip_CreateRegion(){
	DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
	return Region
}
Gdip_DeleteRegion(Region){
	return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
}
Gdip_CreateBitmap(Width, Height, Format=0x26200A){
    DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
    Return pBitmap
}
Gdip_SetSmoothingMode(pGraphics, SmoothingMode){
   return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
}
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r){
	Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
	E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
	Gdip_ResetClip(pGraphics)
	Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
	Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
	Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
	Gdip_ResetClip(pGraphics)
	return E
}
Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff){
	DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
	return hbm
}
SetImage(hwnd, hBitmap){
	SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
	E := ErrorLevel
	DeleteObject(E)
	return E
}
Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}
	return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
}
What you should see after you press the second button

.
20210111103758.png
20210111103758.png (69.44 KiB) Viewed 705 times
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 10:53

Hellbent wrote:
11 Jan 2021, 10:38
And what is "line 12"?
winmove working for This Line 12 from your initial post, see snap,
Attachments
check.png
check.png (104.49 KiB) Viewed 701 times
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 11:19

Well I can't take screenshot, I see traytip saying so, but screenshot folder is still empty,

rightclick, show and hide the GUI having two buttons and
Get color and stetting buttons are not working for me,
color is blue is text blue and 4 little color box are blue,


here is the code where winmove and other events and button trigger works for me

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gui events ;;;;;;;;;;;;;;;;;;;;;;;;

Move_Window(){
	SetTimer,Watch_Hover,Off
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		sleep, 10
	SetTimer,Watch_Hover,On
}

Button_Press(){
	if(!Button[A_GuiControl].Draw_Pressed())
		return
	SoundBeep,% Random(400,900)
}

Random(Min,Max){
	Random,OUT,Min,Max
	return Out
}

Watch_Hover(){
	Static Index,lctrl,Hover_On
	MouseGetPos,,,,ctrl,2
	GuiControlGet,cName,1:Name,%ctrl%
	if(!Hover_On&&ctrl){
		loop,% Button.Length()	{
			if(cName=Button[A_Index].Name){
				Button[A_Index].Draw_Hover()
				lctrl:=ctrl,Index:=A_Index,Hover_On:=1
				break
			}
		}
	}else if(Hover_On=1){
		if((!ctrl||lctrl!=ctrl)&&Button[Index].isPressed=0){
			Button[Index].Draw_Default()
			Hover_On:=0
		}
	}
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gdi button class;;;;;;;;;;;;;;;;;;;;;;;;;

class Button_Type1	{
	__New(x,y,w,h,text,FontSize,name,label,Window,Color:="0xFF3399FF"){
		This.X:=X
		This.Y:=Y
		This.W:=W 
		This.H:=H
		This.FontSize:=FontSize
		This.Text:=Text
		This.Name:=Name
		This.Label:=Label
		This.Color:=Color
		This.Window:=Window
		This.isPressed:=0
		This.Default_Bitmap:=This.Create_Default_Button()
		This.Hover_Bitmap:=This.Create_Hover_Button()
		This.Pressed_Bitmap:=This.Create_Pressed_Button()
		This.Add_Trigger()
		This.Draw_Default()
	}
	Add_Trigger(){
		global
		Gui,% This.Window ":Add",Text,% "x" This.X " y" This.Y " w" This.W " h" This.H " v" This.Name " g" This.Label
	}
	Create_Default_Button(){
		;Bitmap Created Using: HB Bitmap Maker
		pBitmap:=Gdip_CreateBitmap( This.W , This.H ) 
		G := Gdip_GraphicsFromImage( pBitmap )
		Gdip_SetSmoothingMode( G , 4 )
		Brush := Gdip_BrushCreateSolid( "0xFF1C2125" )
		Gdip_FillRectangle( G , Brush , -1 , -1 , This.W+2 , This.H+2 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF161B1F" )
		Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , This.W-5 , This.H-7 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF262B2F" )
		Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , This.W-7 , This.H-9 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , This.W , This.H-10 , "0xFF3F444A" , "0xFF24292D" , 1 , 1 )
		Gdip_FillRoundedRectangle( G , Brush , 4 , 5 , This.W-9 , This.H-11 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF272C32" )
		Gdip_FillRoundedRectangle( G , Brush , 5 , 7 , This.W-11 , This.H-14 , 5 )
		Gdip_DeleteBrush( Brush )
		Gdip_TextToGraphics( G , This.Text , "s" This.FontSize " Bold Center vcenter caaF0F0F0 x0 y0" , "Segoe UI" , This.W , This.H )
		Gdip_DeleteGraphics( G )
		return pBitmap
	}
	Create_Hover_Button(){
		;Bitmap Created Using: HB Bitmap Maker
		pBitmap:=Gdip_CreateBitmap( This.W , This.H ) 
		G := Gdip_GraphicsFromImage( pBitmap )
		Gdip_SetSmoothingMode( G , 4 )
		Brush := Gdip_BrushCreateSolid( "0xFF1C2125" )
		Gdip_FillRectangle( G , Brush , -1 , -1 , This.W+2 , This.H+2 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF151A20" )
		Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , This.W-5 , This.H-7 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF2B3036" )
		Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , This.W-7 , This.H-9 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , This.W , This.H-10 , "0xFF464D55" , "0xFF1E2329" , 1 , 1 )
		Gdip_FillRoundedRectangle( G , Brush , 4 , 5 , This.W-9 , This.H-11 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , This.W-30 , This.H+21 , "0xFF2D343C", This.Color  , 1 , 1 )
		Gdip_FillRoundedRectangle( G , Brush , 4 , 7 , This.W-9 , This.H-13 , 5 )
		Gdip_DeleteBrush( Brush )
		Gdip_TextToGraphics( G , This.Text , "s" This.FontSize " Bold Center vcenter caaF0F0F0 x0 y0" , "Segoe UI" , This.W , This.H )
		Gdip_DeleteGraphics( G )
		return pBitmap
	}
	Create_Pressed_Button(){
		;Bitmap Created Using: HB Bitmap Maker
		pBitmap:=Gdip_CreateBitmap( This.W , This.H ) 
		G := Gdip_GraphicsFromImage( pBitmap )
		Gdip_SetSmoothingMode( G , 4 )
		Brush := Gdip_BrushCreateSolid( "0xFF1C2125" )
		Gdip_FillRectangle( G , Brush , -1 , -1 , This.W+2 , This.H+2 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( "0xFF31363B" )
		Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , This.W-5 , This.H-6 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , This.W , This.H , "0xFF151A20" , "0xFF151A20" , 1 , 1 )
		Gdip_FillRoundedRectangle( G , Brush , 2 , 3 , This.W-5 , This.H-8 , 5 )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , This.W-7 , This.H-10 , "0xFF22272D" , "0xFF33383E" , 1 , 1 )
		Gdip_FillRoundedRectangle( G , Brush , 3 , 4 , This.W-7 , This.H-10 , 5 )
		Gdip_DeleteBrush( Brush )
		Gdip_TextToGraphics( G , This.Text , "s" This.FontSize " Bold Center vcenter caaF0F0F0 x0 y-1" , "Segoe UI" , This.W , This.H )
		Gdip_DeleteGraphics( G )
		return pBitmap
	}
	Draw_Default(){
		Gdip_DrawImage( Main.G, This.Default_Bitmap, This.X, This.Y, This.W, This.H)
		UpdateLayeredWindow(Main.hwnd,Main.hdc)
	}
	Draw_Hover(){
		Gdip_DrawImage( Main.G, This.Hover_Bitmap, This.X, This.Y, This.W, This.H)
		UpdateLayeredWindow(Main.hwnd,Main.hdc)
	}
	Draw_Pressed(){
		Gdip_DrawImage( Main.G, This.Pressed_Bitmap, This.X, This.Y, This.W, This.H)
		UpdateLayeredWindow(Main.hwnd,Main.hdc)
		This.isPressed:=1
		While(GetKeyState("LButton"))
			sleep,10
		This.isPressed:=0
		MouseGetPos,,,,ctrl,2
		GuiControlGet,cName,1:Name,%ctrl%
		if(cName!=This.Name){
			This.Draw_Default()
			return false
		}else	{
			This.Draw_Hover()
			return true
		}
	}
}

;                         GDIP LIB
;############################################################################################################################################
;############################################################################################################################################
;############################################################################################################################################
;############################################################################################################################################
;Shit that I (Hellbent) added
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Layered_Window_SetUp(Smoothing,Window_X,Window_Y,Window_W,Window_H,Window_Name:=1,Window_Options:=""){
	Layered:={}
	Layered.W:=Window_W
	Layered.H:=Window_H
	Layered.X:=Window_X
	Layered.Y:=Window_Y
	Layered.Name:=Window_Name
	Layered.Options:=Window_Options
	Layered.Token:=Gdip_Startup()
	Create_Layered_GUI(Layered)
	Layered.hwnd:=winExist()
	Layered.hbm := CreateDIBSection(Window_W,Window_H)
	Layered.hdc := CreateCompatibleDC()
	Layered.obm := SelectObject(Layered.hdc,Layered.hbm)
	Layered.G := Gdip_GraphicsFromHDC(Layered.hdc)
	Gdip_SetSmoothingMode(Layered.G,Smoothing)
	return Layered
}

Create_Layered_GUI(Layered){
	Gui,% Layered.Name ": +E0x80000 +LastFound " Layered.Options 
	Gui,% Layered.Name ":Show",% "x" Layered.X " y" Layered.Y " w" Layered.W " h" Layered.H " NA"
}

Layered_Window_ShutDown(This){
	SelectObject(This.hdc,This.obm)
	DeleteObject(This.hbm)
	DeleteDC(This.hdc)
	gdip_deleteGraphics(This.g)
	Gdip_Shutdown(This.Token)
}

Gdip_RotateBitmap(pBitmap, Angle, Dispose=1) { ; returns rotated bitmap. By Learning one.
	Gdip_GetImageDimensions(pBitmap, Width, Height)
	Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
	Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
	
	pBitmap2 := Gdip_CreateBitmap(RWidth, RHeight)
	G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
	Gdip_TranslateWorldTransform(G2, xTranslation, yTranslation)
	Gdip_RotateWorldTransform(G2, Angle)
	Gdip_DrawImage(G2, pBitmap, 0, 0, Width, Height)
	
	Gdip_ResetWorldTransform(G2)
	Gdip_DeleteGraphics(G2)
	if Dispose
		Gdip_DisposeImage(pBitmap)
	return pBitmap2
}

New_Brush(colour:="000000",Alpha:="FF"){
	new_colour := "0x" Alpha colour 
	return Gdip_BrushCreateSolid(new_colour)
}

New_Pen(colour:="000000",Alpha:="FF",Width:= 5)
{
	new_colour := "0x" Alpha colour 
	return Gdip_CreatePen(New_Colour,Width)
}	
Fill_Box(pGraphics,pBrush,x,y,w,h)	
{
	;~ Gdip_FillRectangle(G, Brush, x, y, w, h)
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRectangle"
					, Ptr, pGraphics
					, Ptr, pBrush
					, "float", x
					, "float", y
					, "float", w
					, "float", h)
}
Draw_Box(pGraphics, pPen, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}	
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
;
; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
;
;#####################################################################################
;#####################################################################################
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if ((x != "") && (y != ""))
		VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
	
	if (w = "") ||(h = "")
		WinGetPos,,, w, h, ahk_id %hwnd%
	
	return DllCall("UpdateLayeredWindow"
					, Ptr, hwnd
					, Ptr, 0
					, Ptr, ((x = "") && (y = "")) ? 0 : &pt
					, "int64*", w|h<<32
					, Ptr, hdc
					, "int64*", 0
					, "uint", 0
					, "UInt*", Alpha<<16|1<<24
					, "uint", 2)
}

BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster=""){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdi32\BitBlt", Ptr, dDC, "int", dx, "int", dy, "int", dw, "int", dh, Ptr, sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020)
}
StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster=""){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdi32\StretchBlt", Ptr, ddc, "int", dx, "int", dy, "int", dw, "int", dh, Ptr, sdc, "int", sx, "int", sy, "int", sw, "int", sh, "uint", Raster ? Raster : 0x00CC0020)
}
SetStretchBltMode(hdc, iStretchMode=4){
	return DllCall("gdi32\SetStretchBltMode", A_PtrSize ? "UPtr" : "UInt", hdc, "int", iStretchMode)
}
SetImage(hwnd, hBitmap){
	SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
	E := ErrorLevel
	DeleteObject(E)
	return E
}
SetSysColorToControl(hwnd, SysColor=15){
	WinGetPos,,, w, h, ahk_id %hwnd%
	bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
	pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
	pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
	Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
	hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
	SetImage(hwnd, hBitmap)
	Gdip_DeleteBrush(pBrushClear)
	Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
	return 0
}
Gdip_BitmapFromScreen(Screen=0, Raster=""){
	if (Screen = 0)
	{
		Sysget, x, 76
		Sysget, y, 77	
		Sysget, w, 78
		Sysget, h, 79
	}
	else if (SubStr(Screen, 1, 5) = "hwnd:")
	{
		Screen := SubStr(Screen, 6)
		if !WinExist( "ahk_id " Screen)
			return -2
		WinGetPos,,, w, h, ahk_id %Screen%
		x := y := 0
		hhdc := GetDCEx(Screen, 3)
	}
	else if (Screen&1 != "")
	{
		Sysget, M, Monitor, %Screen%
		x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
	}
	else
	{
		StringSplit, S, Screen, |
		x := S1, y := S2, w := S3, h := S4
	}
	
	if (x = "") || (y = "") || (w = "") || (h = "")
		return -1
	
	chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
	BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
	ReleaseDC(hhdc)
	
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
	return pBitmap
}
Gdip_BitmapFromHWND(hwnd){
	WinGetPos,,, Width, Height, ahk_id %hwnd%
	hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
	PrintWindow(hwnd, hdc)
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
	return pBitmap
}
CreateRectF(ByRef RectF, x, y, w, h){
	VarSetCapacity(RectF, 16)
	NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
}
CreateRect(ByRef Rect, x, y, w, h){
	VarSetCapacity(Rect, 16)
	NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
}
CreateSizeF(ByRef SizeF, w, h){
	VarSetCapacity(SizeF, 8)
	NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")     
}
CreatePointF(ByRef PointF, x, y){
	VarSetCapacity(PointF, 8)
	NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")     
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	hdc2 := hdc ? hdc : GetDC()
	VarSetCapacity(bi, 40, 0)
	NumPut(w, bi, 4, "uint"), NumPut(h, bi, 8, "uint"), NumPut(40, bi, 0, "uint"), NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16, "uInt"), NumPut(bpp, bi, 14, "ushort")
	hbm := DllCall("CreateDIBSection", Ptr, hdc2, Ptr, &bi, "uint", 0, A_PtrSize ? "UPtr*" : "uint*", ppvBits, Ptr, 0, "uint", 0, Ptr)
	if !hdc
		ReleaseDC(hdc2)
	return hbm
}
PrintWindow(hwnd, hdc, Flags=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
}
DestroyIcon(hIcon){
	return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
}
PaintDesktop(hdc){
	return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
}
CreateCompatibleBitmap(hdc, w, h){
	return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
}
CreateCompatibleDC(hdc=0){
	return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
SelectObject(hdc, hgdiobj){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
}
DeleteObject(hObject){
	return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
}
GetDC(hwnd=0){
	return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
}
GetDCEx(hwnd, flags=0, hrgnClip=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
}
ReleaseDC(hdc, hwnd=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
}
DeleteDC(hdc){
	return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
Gdip_LibraryVersion(){
	return 1.45
}
Gdip_LibrarySubVersion(){
	return 1.47
}
Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0){
	Static FName = "ObjRelease"
	if !BRAFromMemIn
		return -1
	Loop, Parse, BRAFromMemIn, `n
	{
		if (A_Index = 1)
		{
			StringSplit, Header, A_LoopField, |
			if (Header0 != 4 || Header2 != "BRA!")
				return -2
		}
		else if (A_Index = 2)
		{
			StringSplit, Info, A_LoopField, |
			if (Info0 != 3)
				return -3
		}
		else
			break
	}
	if !Alternate
		StringReplace, File, File, \, \\, All
	RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
	if !FileInfo
		return -4
	hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
	pData := DllCall("GlobalLock", Ptr, hData, Ptr)
	DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
	DllCall("GlobalUnlock", Ptr, hData)
	DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
	DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
	If (A_PtrSize)
		%FName%(pStream)
	Else
		DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
	return pBitmap
}
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r){
	Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
	E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
	Gdip_ResetClip(pGraphics)
	Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
	Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
	Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
	Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
	Gdip_ResetClip(pGraphics)
	return E
}
Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawBezier", Ptr, pgraphics, Ptr, pPen, "float", x1, "float", y1, "float", x2, "float", y2, "float", x3, "float", y3, "float", x4, "float", y4)
}
Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawArc", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipDrawLine", Ptr, pGraphics, Ptr, pPen, "float", x1, "float", y1, "float", x2, "float", y2)
}
Gdip_DrawLines(pGraphics, pPen, Points){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)   
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}
	return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
}
Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRectangle", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r){
	Region := Gdip_GetClipRegion(pGraphics)
	Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
	Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
	E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
	Gdip_SetClipRegion(pGraphics, Region, 0)
	Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
	Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
	Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
	Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
	Gdip_SetClipRegion(pGraphics, Region, 0)
	Gdip_DeleteRegion(Region)
	return E
}
Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)   
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}   
	return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
}
Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillPie", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
}
Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
}
Gdip_FillRegion(pGraphics, pBrush, Region){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
}
Gdip_FillPath(pGraphics, pBrush, Path)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
}
Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)   
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}
	
	if (Matrix&1 = "")
		ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
	else if (Matrix != 1)
		ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
	
	if (sx = "" && sy = "" && sw = "" && sh = "")
	{
		sx := 0, sy := 0
		sw := Gdip_GetImageWidth(pBitmap)
		sh := Gdip_GetImageHeight(pBitmap)
	}
	
	E := DllCall("gdiplus\GdipDrawImagePointsRect"
				, Ptr, pGraphics
				, Ptr, pBitmap
				, Ptr, &PointF
				, "int", Points0
				, "float", sx
				, "float", sy
				, "float", sw
				, "float", sh
				, "int", 2
				, Ptr, ImageAttr
				, Ptr, 0
				, Ptr, 0)
	if ImageAttr
		Gdip_DisposeImageAttributes(ImageAttr)
	return E
}
Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if (Matrix&1 = "")
		ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
	else if (Matrix != 1)
		ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
	
	if (sx = "" && sy = "" && sw = "" && sh = "")
	{
		if (dx = "" && dy = "" && dw = "" && dh = "")
		{
			sx := dx := 0, sy := dy := 0
			sw := dw := Gdip_GetImageWidth(pBitmap)
			sh := dh := Gdip_GetImageHeight(pBitmap)
		}
		else
		{
			sx := sy := 0
			sw := Gdip_GetImageWidth(pBitmap)
			sh := Gdip_GetImageHeight(pBitmap)
		}
	}
	
	E := DllCall("gdiplus\GdipDrawImageRectRect"
				, Ptr, pGraphics
				, Ptr, pBitmap
				, "float", dx
				, "float", dy
				, "float", dw
				, "float", dh
				, "float", sx
				, "float", sy
				, "float", sw
				, "float", sh
				, "int", 2
				, Ptr, ImageAttr
				, Ptr, 0
				, Ptr, 0)
	if ImageAttr
		Gdip_DisposeImageAttributes(ImageAttr)
	return E
}
Gdip_SetImageAttributesColorMatrix(Matrix)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	VarSetCapacity(ColourMatrix, 100, 0)
	Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
	StringSplit, Matrix, Matrix, |
	Loop, 25
	{
		Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
		NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
	}
	DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
	DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
	return ImageAttr
}

Gdip_GraphicsFromImage(pBitmap)
{
	DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
	return pGraphics
}
Gdip_GraphicsFromHDC(hdc)
{
	DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
	return pGraphics
}
Gdip_GetDC(pGraphics)
{
	DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
	return hdc
}
Gdip_ReleaseDC(pGraphics, hdc)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
}
Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
{
	return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
}
Gdip_BlurBitmap(pBitmap, Blur)
{
	if (Blur > 100) || (Blur < 1)
		return -1	
	sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
	dWidth := sWidth//Blur, dHeight := sHeight//Blur
	pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
	G1 := Gdip_GraphicsFromImage(pBitmap1)
	Gdip_SetInterpolationMode(G1, 7)
	Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
	Gdip_DeleteGraphics(G1)
	pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
	G2 := Gdip_GraphicsFromImage(pBitmap2)
	Gdip_SetInterpolationMode(G2, 7)
	Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
	Gdip_DeleteGraphics(G2)
	Gdip_DisposeImage(pBitmap1)
	return pBitmap2
}
Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	SplitPath, sOutput,,, Extension
	if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
		return -1
	Extension := "." Extension
	DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
	VarSetCapacity(ci, nSize)
	DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
	if !(nCount && nSize)
		return -2
	If (A_IsUnicode){
		StrGet_Name := "StrGet"
		Loop, %nCount%
		{
			sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
			if !InStr(sString, "*" Extension)
				continue
			
			pCodec := &ci+idx
			break
		}
	} else {
		Loop, %nCount%
		{
			Location := NumGet(ci, 76*(A_Index-1)+44)
			nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
			VarSetCapacity(sString, nSize)
			DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
			if !InStr(sString, "*" Extension)
				continue
			pCodec := &ci+76*(A_Index-1)
			break
		}
	}
	
	if !pCodec
		return -3
	if (Quality != 75)
	{
		Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
		if Extension in .JPG,.JPEG,.JPE,.JFIF
		{
			DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
			VarSetCapacity(EncoderParameters, nSize, 0)
			DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
			Loop, % NumGet(EncoderParameters, "UInt")      ;%
			{
				elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
				if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
				{
					p := elem+&EncoderParameters-pad-4
					NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
					break
				}
			}      
		}
	}
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
		VarSetCapacity(wOutput, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
		VarSetCapacity(wOutput, -1)
		if !VarSetCapacity(wOutput)
			return -4
		E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
	}
	else
		E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
	return E ? -5 : 0
}
Gdip_GetPixel(pBitmap, x, y)
{
	DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
	return ARGB
}
Gdip_SetPixel(pBitmap, x, y, ARGB)
{
	return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
}
Gdip_GetImageWidth(pBitmap){
	DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
	return Width
}
Gdip_GetImageHeight(pBitmap){
	DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
	return Height
}
Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
	DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
}
Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height){
	Gdip_GetImageDimensions(pBitmap, Width, Height)
}
Gdip_GetImagePixelFormat(pBitmap){
	DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
	return Format
}
Gdip_GetDpiX(pGraphics){
	DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
	return Round(dpix)
}
Gdip_GetDpiY(pGraphics){
	DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
	return Round(dpiy)
}
Gdip_GetImageHorizontalResolution(pBitmap){
	DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
	return Round(dpix)
}
Gdip_GetImageVerticalResolution(pBitmap){
	DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
	return Round(dpiy)
}
Gdip_BitmapSetResolution(pBitmap, dpix, dpiy){
	return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
}
Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize=""){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	, PtrA := A_PtrSize ? "UPtr*" : "UInt*"
	SplitPath, sFile,,, ext
	if ext in exe,dll
	{
		Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
		BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
		
		VarSetCapacity(buf, BufSize, 0)
		Loop, Parse, Sizes, |
		{
			DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
			if !hIcon
				continue
			if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
			{
				DestroyIcon(hIcon)
				continue
			}
			hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
			hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
			if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
			{
				DestroyIcon(hIcon)
				continue
			}
			break
		}
		if !hIcon
			return -1
		Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
		hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
		if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
		{
			DestroyIcon(hIcon)
			return -2
		}
		VarSetCapacity(dib, 104)
		DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
		Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
		DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
		pBitmap := Gdip_CreateBitmap(Width, Height)
		G := Gdip_GraphicsFromImage(pBitmap)
		, Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
		SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
		Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
		DestroyIcon(hIcon)
	}
	else
	{
		if (!A_IsUnicode)
		{
			VarSetCapacity(wFile, 1024)
			DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
			DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
		}
		else
			DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
	}
	
	return pBitmap
}
Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
	return pBitmap
}
Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff){
	DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
	return hbm
}
Gdip_CreateBitmapFromHICON(hIcon){
	DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
	return pBitmap
}
Gdip_CreateHICONFromBitmap(pBitmap){
	DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
	return hIcon
}
Gdip_CreateBitmap(Width, Height, Format=0x26200A){
	DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
	Return pBitmap
}
Gdip_CreateBitmapFromClipboard(){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	if !DllCall("OpenClipboard", Ptr, 0)
		return -1
	if !DllCall("IsClipboardFormatAvailable", "uint", 8)
		return -2
	if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
		return -3
	if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
		return -4
	if !DllCall("CloseClipboard")
		return -5
	DeleteObject(hBitmap)
	return pBitmap
}
Gdip_SetBitmapToClipboard(pBitmap){
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
	hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
	DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
	hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
	pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
	DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
	DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
	DllCall("GlobalUnlock", Ptr, hdib)
	DllCall("DeleteObject", Ptr, hBitmap)
	DllCall("OpenClipboard", Ptr, 0)
	DllCall("EmptyClipboard")
	DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
	DllCall("CloseClipboard")
}
Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A){
	DllCall("gdiplus\GdipCloneBitmapArea", "float", x, "float", y, "float", w, "float", h, "int", Format, A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
	return pBitmapDest
}
Gdip_CreatePen(ARGB, w){
	DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
	return pPen
}
Gdip_CreatePenFromBrush(pBrush, w){
	DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
	return pPen
}
Gdip_BrushCreateSolid(ARGB=0xff000000){
	DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
	return pBrush
}
Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0){
	DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
	return pBrush
}

;#####################################################################################

Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	, PtrA := A_PtrSize ? "UPtr*" : "UInt*"
	
	if !(w && h)
		DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
	else
		DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
	return pBrush
}

Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
	DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
	return LGpBrush
}

Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
{
	CreateRectF(RectF, x, y, w, h)
	DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
	return LGpBrush
}

Gdip_CloneBrush(pBrush)
{
	DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
	return pBrushClone
}

Gdip_DeletePen(pPen)
{
	return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
}

Gdip_DeleteBrush(pBrush)
{
	return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
}

Gdip_DisposeImage(pBitmap)
{
	return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
}

Gdip_DeleteGraphics(pGraphics)
{
	return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}

Gdip_DisposeImageAttributes(ImageAttr)
{
	return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
}

Gdip_DeleteFont(hFont)
{
	return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
}

Gdip_DeleteStringFormat(hFormat)
{
	return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
}

Gdip_DeleteFontFamily(hFamily)
{
	return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
}

Gdip_DeleteMatrix(Matrix)
{
	return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
}

Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
{
	IWidth := Width, IHeight:= Height
	
	RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
	RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
	RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
	RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
	RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
	RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
	RegExMatch(Options, "i)NoWrap", NoWrap)
	RegExMatch(Options, "i)R(\d)", Rendering)
	RegExMatch(Options, "i)S(\d+)(p*)", Size)
	
	if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
		PassBrush := 1, pBrush := Colour2
	
	if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
		return -1
	
	Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
	Loop, Parse, Styles, |
	{
		if RegExMatch(Options, "\b" A_loopField)
			Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
	}
	
	Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
	Loop, Parse, Alignments, |
	{
		if RegExMatch(Options, "\b" A_loopField)
			Align |= A_Index//2.1      ; 0|0|1|1|2|2
	}
	
	xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
	ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
	Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
	Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
	if !PassBrush
		Colour := "0x" (Colour2 ? Colour2 : "ff000000")
	Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
	Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
	
	hFamily := Gdip_FontFamilyCreate(Font)
	hFont := Gdip_FontCreate(hFamily, Size, Style)
	FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
	hFormat := Gdip_StringFormatCreate(FormatStyle)
	pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
	if !(hFamily && hFont && hFormat && pBrush && pGraphics)
		return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
	
	CreateRectF(RC, xpos, ypos, Width, Height)
	Gdip_SetStringFormatAlign(hFormat, Align)
	Gdip_SetTextRenderingHint(pGraphics, Rendering)
	ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
	
	if vPos
	{
		StringSplit, ReturnRC, ReturnRC, |
		
		if (vPos = "vCentre") || (vPos = "vCenter")
			ypos += (Height-ReturnRC4)//2
		else if (vPos = "Top") || (vPos = "Up")
			ypos := 0
		else if (vPos = "Bottom") || (vPos = "Down")
			ypos := Height-ReturnRC4
		
		CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
		ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
	}
	
	if !Measure
		E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
	
	if !PassBrush
		Gdip_DeleteBrush(pBrush)
	Gdip_DeleteStringFormat(hFormat)   
	Gdip_DeleteFont(hFont)
	Gdip_DeleteFontFamily(hFamily)
	return E ? E : ReturnRC
}

Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
		VarSetCapacity(wString, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
	}
	
	return DllCall("gdiplus\GdipDrawString"
					, Ptr, pGraphics
					, Ptr, A_IsUnicode ? &sString : &wString
					, "int", -1
					, Ptr, hFont
					, Ptr, &RectF
					, Ptr, hFormat
					, Ptr, pBrush)
}

Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	VarSetCapacity(RC, 16)
	if !A_IsUnicode
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
		VarSetCapacity(wString, nSize*2)   
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
	}
	
	DllCall("gdiplus\GdipMeasureString"
					, Ptr, pGraphics
					, Ptr, A_IsUnicode ? &sString : &wString
					, "int", -1
					, Ptr, hFont
					, Ptr, &RectF
					, Ptr, hFormat
					, Ptr, &RC
					, "uint*", Chars
					, "uint*", Lines)
	
	return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
}

; Near = 0
; Center = 1
; Far = 2
Gdip_SetStringFormatAlign(hFormat, Align)
{
	return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
}


Gdip_StringFormatCreate(Format=0, Lang=0)
{
	DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
	return hFormat
}

Gdip_FontCreate(hFamily, Size, Style=0)
{
	DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
	return hFont
}

Gdip_FontFamilyCreate(Font)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
		VarSetCapacity(wFont, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
	}
	
	DllCall("gdiplus\GdipCreateFontFamilyFromName"
					, Ptr, A_IsUnicode ? &Font : &wFont
					, "uint", 0
					, A_PtrSize ? "UPtr*" : "UInt*", hFamily)
	
	return hFamily
}

Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
{
	DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
	return Matrix
}

Gdip_CreateMatrix()
{
	DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
	return Matrix
}
Gdip_CreatePath(BrushMode=0)
{
	DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
	return Path
}

Gdip_AddPathEllipse(Path, x, y, w, h)
{
	return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
}

Gdip_AddPathPolygon(Path, Points)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	StringSplit, Points, Points, |
	VarSetCapacity(PointF, 8*Points0)   
	Loop, %Points0%
	{
		StringSplit, Coord, Points%A_Index%, `,
		NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
	}   
	
	return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
}

Gdip_DeletePath(Path)
{
	return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
}

Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
{
	return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
}

Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
{
	return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
}
Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
{
	return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
}
Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
{
	return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
}

Gdip_Startup()
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("LoadLibrary", "str", "gdiplus")
	VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
	DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
	return pToken
}

Gdip_Shutdown(pToken)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
	if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("FreeLibrary", Ptr, hModule)
	return 0
}

Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
{
	return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
}

Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
{
	return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
}

Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
{
	return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
}

Gdip_ResetWorldTransform(pGraphics)
{
	return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}

Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
{
	pi := 3.14159, TAngle := Angle*(pi/180)	
	
	Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
	if ((Bound >= 0) && (Bound <= 90))
		xTranslation := Height*Sin(TAngle), yTranslation := 0
	else if ((Bound > 90) && (Bound <= 180))
		xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
	else if ((Bound > 180) && (Bound <= 270))
		xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
	else if ((Bound > 270) && (Bound <= 360))
		xTranslation := 0, yTranslation := -Width*Sin(TAngle)
}

Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
{
	pi := 3.14159, TAngle := Angle*(pi/180)
	if !(Width && Height)
		return -1
	RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
	RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
}


Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
{
	return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
}

Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
{
	return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
}

Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
}

Gdip_ResetClip(pGraphics)
{
	return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}

Gdip_GetClipRegion(pGraphics)
{
	Region := Gdip_CreateRegion()
	DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
	return Region
}

Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
}

Gdip_CreateRegion()
{
	DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
	return Region
}

Gdip_DeleteRegion(Region)
{
	return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
}


Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	CreateRect(Rect, x, y, w, h)
	VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
	E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
	Stride := NumGet(BitmapData, 8, "Int")
	Scan0 := NumGet(BitmapData, 16, Ptr)
	return E
}

Gdip_UnlockBits(pBitmap, ByRef BitmapData)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
}

Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
{
	Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
}

;#####################################################################################

Gdip_GetLockBitPixel(Scan0, x, y, Stride)
{
	return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
}

;#####################################################################################

Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
{
	static PixelateBitmap
	
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if (!PixelateBitmap)
	{
		if A_PtrSize != 8 ; x86 machine code
			MCode_PixelateBitmap =
		(LTrim Join
		558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
		397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
		8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
		4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
		C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
		8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
		148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
		B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
		F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
		038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
		1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
		FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
		D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
		45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
		89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
		0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
		75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
		8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
		B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
		451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
		75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
		8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
		)
		else ; x64 machine code
			MCode_PixelateBitmap =
		(LTrim Join
		4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
		448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
		4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
		C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
		24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
		004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
		0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
		DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
		024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
		99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
		8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
		4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
		000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
		ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
		4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
		99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
		8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
		2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
		FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
		83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
		F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
		0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
		413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
		)
		
		VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
		Loop % StrLen(MCode_PixelateBitmap)//2		;%
			NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
		DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
	}
	
	Gdip_GetImageDimensions(pBitmap, Width, Height)
	
	if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
		return -1
	if (BlockSize > Width || BlockSize > Height)
		return -2
	
	E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
	E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
	if (E1 || E2)
		return -3
	
	E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
	
	Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
	return 0
}

;#####################################################################################

Gdip_ToARGB(A, R, G, B)
{
	return (A << 24) | (R << 16) | (G << 8) | B
}

;#####################################################################################

Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
{
	A := (0xff000000 & ARGB) >> 24
	R := (0x00ff0000 & ARGB) >> 16
	G := (0x0000ff00 & ARGB) >> 8
	B := 0x000000ff & ARGB
}

;#####################################################################################

Gdip_AFromARGB(ARGB)
{
	return (0xff000000 & ARGB) >> 24
}

;#####################################################################################

Gdip_RFromARGB(ARGB)
{
	return (0x00ff0000 & ARGB) >> 16
}

;#####################################################################################

Gdip_GFromARGB(ARGB)
{
	return (0x0000ff00 & ARGB) >> 8
}

;#####################################################################################

Gdip_BFromARGB(ARGB)
{
	return 0x000000ff & ARGB
}

;#####################################################################################

StrGetB(Address, Length=-1, Encoding=0)
{
	; Flexible parameter handling:
	if Length is not integer
		Encoding := Length,  Length := -1
	
	; Check for obvious errors.
	if (Address+0 < 1024)
		return
	
	; Ensure 'Encoding' contains a numeric identifier.
	if Encoding = UTF-16
		Encoding = 1200
	else if Encoding = UTF-8
		Encoding = 65001
	else if SubStr(Encoding,1,2)="CP"
		Encoding := SubStr(Encoding,3)
	
	if !Encoding ; "" or 0
	{
		; No conversion necessary, but we might not want the whole string.
		if (Length == -1)
			Length := DllCall("lstrlen", "uint", Address)
		VarSetCapacity(String, Length)
		DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
	}
	else if Encoding = 1200 ; UTF-16
	{
		char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
		VarSetCapacity(String, char_count)
		DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
	}
	else if Encoding is integer
	{
		; Convert from target encoding to UTF-16 then to the active code page.
		char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
		VarSetCapacity(String, char_count * 2)
		char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
		String := StrGetB(&String, char_count, 1200)
	}
	
	return String
}
button from its dropdown* button gui not working..!
Attachments
check 2.png
check 2.png (90.21 KiB) Viewed 695 times
Last edited by Xeo786 on 11 Jan 2021, 11:24, edited 1 time in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 11:21

Xeo786 wrote:
11 Jan 2021, 10:53
Hellbent wrote:
11 Jan 2021, 10:38
And what is "line 12"?
winmove working for This Line 12 from your initial post, see snap,
Ok.
We had our wires a bit crossed there lol.

If you are running windows 8 or higher you are able to interact with and detect invisible gui controls.
In the layered window class for example, you can set coords to add a trigger that once clicked allows you to drag the window around

Code: Select all

class LayeredWindow	{
	__New(WinMover := ""){
		( WinMover ) ? ( This._AddMoveTrigger( WinMover ) )
	}
	_AddMoveTrigger( positons ){ 
		local hwnd , bd
		Gui , % This.Window " : Add" , Text , % "x" positons.x " y" positons.y " w" positons.w " h" positons.h " hwndhwnd"
		This.MoveHwnd := hwnd
		bd := This._WindowMover.Bind( This )
		GuiControl , % This.Window ": +G" , % This.MoveHwnd , % bd
	}
	_WindowMover(){ 
		PostMessage, 0xA1 , 2
	}
Unfortunatly if you are on windows 7 or older you can't detect MouseGetPos,,,,ctrl,2 or interact with them Left Click
The only ways I can think of to get around that is to use OnMessage() or to have a timer constantly checking if your cursor is in/over a rectangle area.

OnMessage() is no good because it would have to be outside the class so that the script writer can also use it for whatever they need it for and having a timer inside the class would be too much of a pain in the ... and would always be running using cpu time.
I think that windows 7 users would just have to code their own OnMessage() function if they want to have more interactions with a layered window.
But windows 8 users can do all kinds of cool things with it.
Last edited by Hellbent on 11 Jan 2021, 11:30, edited 1 time in total.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 11:27

@Xeo786

The reason you can interact with those Button_Type_1 Buttons is because they are on a normal gui, not a layeredWindow [E0x80000].
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Moving a layered window [ E0x80000 ] on win 7 computers && Deleting a instance of a class within a class method

11 Jan 2021, 11:34

wait a second, I am clueless,
just see these logs, its not keep checking stuff like onmsg and I just move this window (the blockbox) little down, and I got this new log saying PostMessage, 0xA1 , 2
is this supposed to work for me or not coz I am using windows 7
Attachments
check 3.PNG
check 3.PNG (49.4 KiB) Viewed 686 times
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ConnorMcLoud, Google [Bot] and 167 guests