;IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
;IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
;Distributing copies of the program in compiled format (exe) must be free of any fee!

;                   |            |      |                 |   |  ____| __  /
;   __|   _ \    _` |   _ \   _` |      __ \   |   |      |   |  __|      /
;  (     (   |  (   |   __/  (   |      |   |  |   |      |   |  |       /
; \___| \___/  \__,_| \___| \__,_|     _.__/  \__, |     \___/  _____| ____|
;                                             ____/

;                                             ____/
; Requires AutoIt version 3.3.11.3 or higher
;
;
;~ #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
;~ #AutoIt3Wrapper_Run_AU3Check=N
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Version=b
#AutoIt3Wrapper_UseX64=n

#pragma compile(Icon, Screenshooter.ico)
#pragma compile(ProductName, AutoIt Windows Screenshooter)
#pragma compile(InternalName, Windows Screenshooter)
#pragma compile(OriginalFilename, Windows Screenshooter.exe)
#pragma compile(FileDescription, "Makes screenshot of any visible window, a selectable region on the desktop or from any web site, creates a video only stream of your screen.")
#pragma compile(FileVersion, 1.8.5.0)
#pragma compile(ProductVersion, 3.3.15.4)
#pragma compile(LegalCopyright, "UEZ 2010-2021")
#pragma compile(CompanyName, "UEZ Software Development")
#pragma compile(inputboxres, false)
#pragma compile(UPX, false)
#pragma compile(AutoItExecuteAllowed, false)
#pragma compile(Comments, "https://www.autoitscript.com/forum/index.php?showtopic=122941, IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!, Distributing copies of the program in compiled format (exe) must be free of any fee!")

#AutoIt3Wrapper_Au3stripper_OnError=ForceUse
#AutoIt3Wrapper_Run_Au3Stripper=y
;#Au3Stripper_Parameters=/rsln /mo
#Au3Stripper_Parameters=/so ;/pe /rm
#Au3Stripper_Ignore_Funcs=__Au3Obj*,__ie*,Intercept_MessageBoxW,VirtualProtect,ImageDirectoryEntryToData
#Au3Stripper_Ignore_Variables=$FuncName,$arg,$__g_sIEUserErrorHandler,$__g_oIEErrorHandler
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#AutoIt3Wrapper_Res_HiDpi=Y

#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 1,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 2,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 3,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, MENU, 166,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 162,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 164,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 169,
#AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, DIALOG, 1000,

;~ #AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%"
;~ #AutoIt3Wrapper_Run_After=upx.exe --ultra-brute --crp-ms=999999 --all-methods --all-filters "%out%"
;~ #AutoIt3Wrapper_Run_After=mpress.exe -s -b -q "%out%"

Break(0)
;~ #NoTrayIcon
#include <APIMiscConstants.au3>
#include <GuiConstantsEx.au3>
#include <Clipboard.au3>
#include <ComboConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <GUIButton.au3>
#include <GUIListView.au3>
#include <GUIMenu.au3>
#include <GUIReBar.au3>
#include <GUIScrollBars.au3>
#include <GUISlider.au3>
#include <GUIToolbar.au3>
;~ #Include <IE.au3>
#include <INet.au3>
#include <ScreenCapture.au3>
#include <ScrollBarConstants.au3>
#include <StaticConstants.au3>
#include <UpDownConstants.au3>
#include <WinAPIMisc.au3>
#include <WinAPIRes.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

#Include "AutoItObject.au3"
#include "BinaryStrings.au3"
#include "MPDF_UDF.au3"
#include "TranslationArray.au3"
#include "_GDIPlus_GIFAnim.au3"
#include "XM.au3"

AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint")

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUICoordMode", 1)
AutoItSetOption("GUICloseOnESC", 0)
AutoItSetOption("GUIOnEventMode", 1)
;~ AutoItSetOption("MouseCoordMode", 1)

;~ DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

Global Const $title = "AutoIt Windows Screenshooter by UEZ "
Global Const $ver = "v1.85 Build 2021-06-12"

Global Const $sLangIni = @ScriptDir & "\Windows Screenshooter.ini"
Global $iLang = 0, $i, $width = 0, $height = 0, $bSearchForChildren = False

If @OSBuild < 2600 Then Exit _WinAPI_ShowError($title & @LF & @LF & $aTranslations[20][$iLang] & @OSVersion & " !!! :-(", False)

;~ If Not _GDIPlus_Startup(@SystemDir & "\gdiplus.dll") Then Exit _WinAPI_ShowError($aTranslations[21][$iLang], False)
If Not _GDIPlus_Startup() Then Exit _WinAPI_ShowError($aTranslations[21][$iLang], False)

#OnAutoItStartRegister "OnAutoItStart"
Global $__Restart = False

Global Const $dll = DllOpen("user32.dll")

Global Const $iStateAnim = _WinAPI_GetGUIMinMaxAnim()

;Global Enum $GDIP_WrapModeTile, $GDIP_WrapModeTileFlipX, $GDIP_WrapModeTileFlipY, $GDIP_WrapModeTileFlipXY, $GDIP_WrapModeClamp


; enum _PROCESS_DPI_AWARENESS -> https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
Global Enum $DPI_AWARENESS_INVALID = -1, $PROCESS_DPI_UNAWARE = 0, $PROCESS_SYSTEM_DPI_AWARE, $PROCESS_PER_MONITOR_DPI_AWARE

;https://docs.microsoft.com/en-us/windows/desktop/hidpi/dpi-awareness-context
Global Enum $Context_UnawareGdiScaled = -5, $Context_PerMonitorAwareV2, $Context_PerMonitorAware, $Context_SystemAware, $Context_Unaware

; enum _MONITOR_DPI_TYPE
Global Enum $MDT_EFFECTIVE_DPI = 0, $MDT_ANGULAR_DPI, $MDT_RAW_DPI
Global Const $MDT_DEFAULT = $MDT_EFFECTIVE_DPI

Global $aDPI[2] = [1, 1]

;~ If Not @Compiled Then _WinAPI_SetDPIAwareness()
_WinAPI_SetDPIAwareness()
;_WinAPI_SetProcessDpiAwarenessContext()

;$aDPI = _GDIPlus_GraphicsGetDPIRatio()
$aDPI = _WinAPI_GetDpiForMonitor()

Global $JPEG_Quality = 85, $bSave_Shadow = 1, $bSave_BgColor = True, $bClipboard_Shadow = 1
Global $bBorder = 1, $hGfx_border, $iBorderColor = 0xE0FF1010, $bTopmost = 0

Global $aLanguages[UBound($aTranslations, 2)], $aLanguagesFlags[UBound($aTranslations, 2)][3]
For $i = 0 To UBound($aTranslations, 2) - 1
	$aLanguages[$i] = $aTranslations[0][$i] ;language 3 letter codes
Next

If FileExists($sLangIni) Then
	$iLang = Int(IniRead($sLangIni, "Language", "Lang", $iLang))
	If $iLang < 0 Or $iLang > UBound($aTranslations, 2) Then $iLang = 0
	$bBorder = Int(IniRead($sLangIni, "Settings", "Border", $bBorder))
	$bBorder = $bBorder > 1 ? 1 : $bBorder < 0 ? 0 : $bBorder
	$bSave_Shadow = Int(IniRead($sLangIni, "Settings", "ShadowSave", $bSave_Shadow))
	$bSave_Shadow = $bSave_Shadow > 1 ? 1 : $bSave_Shadow < 0 ? 0 : $bSave_Shadow
	$bClipboard_Shadow = Int(IniRead($sLangIni, "Settings", "ShadowClipboard", $bClipboard_Shadow))
	$bClipboard_Shadow = $bClipboard_Shadow > 1 ? 1 : $bClipboard_Shadow < 0 ? 0 : $bClipboard_Shadow
	$iBorderColor = StringRegExp((IniRead($sLangIni, "Settings", "BorderColor", $iBorderColor)), "\b0x[[:xdigit:]]{8}?\b", 3)
	If @error Then
		$iBorderColor = 0xE0FF1010
	Else
		$iBorderColor = Int($iBorderColor[0])
	EndIf
	$width = Int(IniRead($sLangIni, "Settings", "Width", $width))
	$height = Int(IniRead($sLangIni, "Settings", "Height", $height))
	$bSearchForChildren = Int(IniRead($sLangIni, "Settings", "ListMoreWindows", $bSearchForChildren))
	$bSearchForChildren = $bSearchForChildren <> 0 ? True : False
	$bTopmost = Int(IniRead($sLangIni, "Settings", "Topmost", $bTopmost))
	$bTopmost = $bTopmost > 1 ? 1 : $bTopmost < 0 ? 0 : $bTopmost
EndIf

Global Const $iBorderWidth = 1, $hPen_Border = _GDIPlus_PenCreate($iBorderColor, $iBorderWidth)

Global $bStartMin = False
If $CMDLine[0] Then
	If $CMDLine[1] = "/min" Then $bStartMin = True
EndIf

Global Const $g32_dll = DllOpen("gdi32.dll")

Global Const $hDwmApiDll = DllOpen("dwmapi.dll")
Global $tChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($tChkAero))
Global $aero = DllStructGetData($tChkAero, 1)

DllCall("Kernel32.dll", "long", "SetProcessDEPPolicy", "dword", 0) ;disable DEP for this process

Global $icon_GUI = 196
Global $icon_redo = 238
Global $icon_jpg_qual = 302
Global $icon_timestamp = 239
If @OSBuild < 6000 Or Not $aero Then
	If Not $bStartMin Then MsgBox(BitOR($MB_ICONWARNING, $MB_TOPMOST), $aTranslations[22][$iLang], $aTranslations[23][$iLang], 60)
	$icon_redo = 146
	$icon_jpg_qual = 161
	$icon_timestamp = 20
EndIf

ProcessSetPriority(@AutoItPID, 4)

;capture sound
;~ Global Const $SND_SYNC = 0, $SND_ASYNC = 1, $SND_NODEFAULT = 2, $SND_MEMORY = 4, $SND_NOWAIT = 0x2000
Global $binCapture_snd = Capture_Sound()
Global $ByteStruct = DllStructCreate("byte[" & BinaryLen($binCapture_snd) & "]")
DllStructSetData($ByteStruct, 1, $binCapture_snd)
$binCapture_snd = 0
Global Const $BytePtr = DllStructGetPtr($ByteStruct)
Global Const $fuSound = BitOR($SND_MEMORY, $SND_ASYNC, $SND_NODEFAULT, $SND_NOWAIT)
Global $silent = False

#Region GUI part
;~ Global Const $STM_SETIMAGE = 0x0172
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
;~ Global $hMouse_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
;~ Global $hM_Module = DllCall("kernel32.dll", "handle", "GetModuleHandle", "ptr", 0)
;~ Global $hM_Hook = DllCall($dll, "handle", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hMouse_Proc), "handle", $hM_Module[0], "dword", 0)

If $width = 0 Or $height = 0 Then
	$width = Int(@DesktopWidth * 0.80)
	$height = Int(@DesktopHeight * 0.85)
EndIf
$width = ($width < 850) ? 850 : ($width > 1600) ? 1600 : $width
$height = ($height < 600) ? 600 : ($height > 900) ? 900 : $height

Global Const $gdip_x = 264
Global Const $gdip_y = 80
Global Const $gdip_w = $width - 272
Global Const $gdip_h = $height - 190

Global $hGui_Slider, $Slider, $hSlider, $Slider_Label_Text, $Slider_Label_Value, $_msg, $aPos_SC, $Grab_x, $Grab_y, $Grab_w, $Grab_h

Global $_MDCodeBuffer, $_MDLoadOffset, $_MDGetOffset, $_MDFreeOffset, $_MDKernel32Dll, $F_DLL
Global $_MFHookPtr, $_MFHookBak, $_MFHookApi = "LocalCompact"

Global $cursor, $Avi_Handle, $Avi32_Dll, $rec_time, $compress_avi = True, $end_avi_cap = False
Global Const $OF_CREATE = 0x00001000
Global Const $ICMF_CHOOSE_KEYFRAME = 1, $ICMF_CHOOSE_DATARATE = 2
Global Const $AVIIF_KEYFRAME = 0x00000010
Global Const $AVIERR_UNSUPPORTED = 0x80044065
Global Const $AVIERR_BADPARAM = 0x80044066
Global Const $AVIERR_MEMORY = 0x80044067
Global Const $AVIERR_NOCOMPRESSOR = 0x80044071
Global Const $AVIERR_CANTCOMPRESS = 0x80044075
Global Const $AVIERR_ERROR = 0x800440C7
Global Const $AVIERR_OK = 0

;http://msdn.microsoft.com/en-us/library/dd183374(v=vs.85).aspx
Global Const $BITMAPFILEHEADER = "WORD bfType;DWORD bfSize;WORD bfReserved1;WORD bfReserved2;DWORD bfOffBits;"
;~ Global Const $BITMAPFILEHEADER = "align 2;char magic[2];int size;short res1;short res2;ptr offset;"

;http://msdn.microsoft.com/en-us/library/dd183376(v=vs.85).aspx
Global Const $BITMAPINFOHEADER = _
		"dword biSize;long biWidth;long biHeight;short biPlanes;short biBitCount;dword biCompression;" & _
		"dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;"

;http://msdn.microsoft.com/en-us/library/dd318180(v=VS.85).aspx
Global Const $AVIMAINHEADER = _
		"FOURCC fcc;DWORD cb;DWORD dwMicroSecPerFrame;DWORD dwMaxBytesPerSec;DWORD dwPaddingGranularity;" & _
		"DWORD dwFlags;DWORD dwTotalFrames;DWORD dwInitialFrames;DWORD dwStreams;DWORD dwSuggestedBufferSize;" & _
		"DWORD dwWidth;DWORD dwHeight;"

;http://msdn.microsoft.com/en-us/library/ms899423.aspx
Global Const $AVISTREAMINFO = _
		"dword fccType;dword fccHandler;dword dwFlags;dword dwCaps;short wPriority;short wLanguage;dword dwScale;" & _
		"dword dwRate;dword dwStart;dword dwLength;dword dwInitialFrames;dword dwSuggestedBufferSize;dword dwQuality;" & _
		"dword dwSampleSize;int rleft;int rtop;int rright;int rbottom;dword dwEditCount;dword dwFormatChangeCount;wchar[64];"

;http://msdn.microsoft.com/en-us/library/dd756791(v=VS.85).aspx
Global Const $AVICOMPRESSOPTIONS = _
		"DWORD fccType;DWORD fccHandler;DWORD dwKeyFrameEvery;DWORD dwQuality;DWORD dwBytesPerSecond;" & _
		"DWORD dwFlags;PTR lpFormat;DWORD cbFormat;PTR lpParms;DWORD cbParms;DWORD dwInterleaveEvery;"

Global Const $TBPF_NOPROGRESS = 0
Global Const $TBPF_INDETERMINATE = 0x1
Global Const $TBPF_NORMAL = 0x2
Global Const $TBPF_ERROR = 0x4
Global Const $TBPF_PAUSED = 0x8
Global $CLSID_TaskBarlist, $CLSID_TaskBarlist, $IID_ITaskbarList3, $pTB3, $oTB3
Global $tagInterface = _
						"HrInit hresult();" & _
						"AddTab hresult(hwnd);" & _
						"DeleteTab hresult(hwnd);" & _
						"ActivateTab hresult(hwnd);" & _
						"SetActiveAlt hresult(hwnd);" & _
						"MarkFullscreenWindow hresult(hwnd;bool);" & _
						"SetProgressValue hresult(hwnd;uint64;uint64);" & _
						"SetProgressState hresult(hwnd;int);" & _
						"RegisterTab hresult(hwnd;hwnd);" & _
						"UnregisterTab hresult(hwnd);" & _
						"SetTabOrder hresult(hwnd;hwnd);" & _
						"SetTabActive hresult(hwnd;hwnd;dword);" & _
						"ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _
						"ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _
						"ThumbBarSetImageList hresult(hwnd;ptr);" & _
						"SetOverlayIcon hresult(hwnd;ptr;wstr);" & _
						"SetThumbnailTooltip hresult(hwnd;wstr);" & _
						"SetThumbnailClip hresult(hwnd;ptr);" & _
						"SetTabProperties hresult(hwnd;int);"

Global Const $zmin = 5
Global Const $zmax = 15
Global Const $margin = 2
Global $hGUI_MarkArea, $hGUI_MarkArea_Child, $hGUI_Cross, $w_area, $h_area, $selected = False
Global $z = 10
Global $aWnd, $URL_Input, $cont = 1, $Grab_Button, $Dummy, $filename, $iWebsiteW = 1280, $web_sec
Global $f, $bW, $bH, $scroll_x, $scroll_y
Global Const $scroll_speedx = 10, $scroll_speedy = 10
Global $hGfx, $hCtxt, $hGUI_About, $hHBITMAP, $hBmp_A, $hImg_A, $tRectF, $hBrush, $hFormat, $aText, $tLayout, $speed, $About_End, $iScrollHeight
Global $vBitmap, $hBitmap_s, $undo, $undo_chk = False
Global Const $bubbles = 12, $max_speed = 3, $min_size = 50, $max_size = 70, $dh = 0
Global $aData[$bubbles][6] ;x,y,vx,vy,size,bmp

Global $hBackImage, $hImageContext, $hIA
Global $hBitmap2, $hClipboard_Bitmap, $hBmp, $hMemoryBMP
Global $hDC_Region, $hObj, $hMemDC, $memBitmap, $aFullScreen, $hFullScreen
$hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
$aFullScreen = WinGetPos($hFullScreen)

Global $hGUI = GUICreate($title & $ver, $width, $height, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST * $bTopmost))
GUISetFont(9 * $aDPI[0], 400, 0, "Times New Roman")
Global $bg_c = "BABDBA" ;"BABDBA" ;"A6ABB5" ;"989898" ;"D9D6DB"; "D4D9DB"; "BEC3D0"; "D8BFD8" ;"4682B4" ;"DBE3DE" ;"CFDDEB" ;"BFCDDB"
GUISetBkColor("0x" & $bg_c, $hGUI)

Global $hBrush_Clear = _GDIPlus_BrushCreateSolid("0xFF" & $bg_c)

Global Enum $id_ChkUpd = 0x400, $id_VisitWeb, $id_Ruler, $id_OpenMailClient, $id_Print, $id_ImageEditor, $id_About, $id_Exit, $id_Low, $id_Medium, $id_High, $id_Auto, $id_Reset, _
		$id_Gray, $id_BW, $id_Invert, $id_Undo, $id_Rotm90, $id_Rotp90, $id_ImgEditor, $id_Watermark, $id_Donate, $id_Lang_Eng, $id_Lang_Ger, $id_ImportClipboard

Global $hQMenu, $hQMenu_Sub, $hQMenu_Sub2, $hQMenu_Sub3, $hTmp, $hTmp2, $hQMenu_Capture, $bAuto = 1

$hQMenu_Sub = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub, 0, $aTranslations[24][$iLang], $id_Low)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub, 1, $aTranslations[25][$iLang], $id_Medium)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub, 2, $aTranslations[26][$iLang], $id_High)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub, 4, $aTranslations[262][$iLang], $id_Auto)
_GUICtrlMenu_CheckMenuItem($hQMenu_Sub, 4, True)

$hQMenu_Sub2 = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub2, 0, $aTranslations[27][$iLang], $id_Reset)

$hQMenu_Sub3 = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 0, $aTranslations[8][$iLang], $id_Gray)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 1, $aTranslations[9][$iLang], $id_BW)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 2, $aTranslations[10][$iLang], $id_Invert)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 3, $aTranslations[28][$iLang], $id_Rotm90)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 4, $aTranslations[29][$iLang], $id_Rotp90)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 5, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 6, $aTranslations[30][$iLang], $id_Undo)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 7, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 8, $aTranslations[31][$iLang], $id_ImgEditor)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 9, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu_Sub3, 10, $aTranslations[32][$iLang], $id_Watermark)
_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 2)
;~ _GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 8, 2)

$hQMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hQMenu, 0, $aTranslations[33][$iLang], 0, $hQMenu_Sub)
_GUICtrlMenu_InsertMenuItem($hQMenu, 1, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu, 2, $aTranslations[34][$iLang], 0, $hQMenu_Sub2)
_GUICtrlMenu_InsertMenuItem($hQMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hQMenu, 4, $aTranslations[35][$iLang], 0, $hQMenu_Sub3)

$hTmp = _GDIPlus_BitmapCreateFromMemory(Quality_Icon())
Global $hBMP_Quality = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hQMenu, 0, $hBMP_Quality)
Global $hBMP_Reset = _GDIPlus_BitmapCreateFromMemory(ResetView_Icon(), True)
_GUICtrlMenu_SetItemBmp($hQMenu, 2, $hBMP_Reset)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Reset_Icon())
Global $hBMP_Reset2 = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub2, 0, $hBMP_Reset2)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Editing_Icon())
Global $hBMP_ImageEdit = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu, 4, $hBMP_ImageEdit)
_GDIPlus_BitmapDispose($hTmp)
Global $hBMP_ImageEdit_Invert = _GDIPlus_BitmapCreateFromMemory(Invert_Icon(), True)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 2, $hBMP_ImageEdit_Invert)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Gray_Icon())
Global $hBMP_ImageEdit_Gray = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 0, $hBMP_ImageEdit_Gray)
$hTmp = _GDIPlus_BitmapCreateFromMemory(BW_Icon())
Global $hBMP_ImageEdit_BW = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 1, $hBMP_ImageEdit_BW)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Rotate_Icon())
Global $hBMP_ImageEdit_Rotp90 = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 3, $hBMP_ImageEdit_Rotp90)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Rotate_Icon())
Global $hBMP_ImageEdit_Rotm90 = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 4, $hBMP_ImageEdit_Rotm90)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Undo_Icon())
Global $hBMP_ImageEdit_Undo = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 6, $hBMP_ImageEdit_Undo)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Editor_Icon())
Global $hBMP_ImageEdit_Editor = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 8, $hBMP_ImageEdit_Editor)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Watermark_Icon())
Global $hBMP_Watermark = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hQMenu_Sub3, 10, $hBMP_Watermark)
_GDIPlus_BitmapDispose($hTmp)

Global $hMenu = _GUICtrlMenu_GetSystemMenu(HWnd($hGUI))
_GUICtrlMenu_AppendMenu($hMenu, $MF_SEPARATOR, 0, 0)
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_Ruler, $aTranslations[36][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_OpenMailClient, $aTranslations[37][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_Print, $aTranslations[38][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_ImportClipboard, $aTranslations[280][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_ImageEditor, $aTranslations[39][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_ChkUpd, $aTranslations[40][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_VisitWeb, $aTranslations[41][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_About, $aTranslations[42][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_SEPARATOR, 0, 0)
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_Donate, $aTranslations[43][$iLang])
_GUICtrlMenu_AppendMenu($hMenu, $MF_SEPARATOR, 0, 0)
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_Exit, $aTranslations[44][$iLang])

Global $hBMP_Ruler = _GDIPlus_BitmapCreateFromMemory(Ruler_Image(), True)
_GUICtrlMenu_SetItemBmp($hMenu, 8, $hBMP_Ruler)
$hTmp = _GDIPlus_BitmapCreateFromMemory(Envelope_Icon())
Global $hBMP_OpenMailClient = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Paypal())
Global $hBMP_Donate = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hMenu, 9, $hBMP_OpenMailClient)
Global $hBMP_Print = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 143)
_GUICtrlMenu_SetItemBmp($hMenu, 10, $hBMP_Print)
Global $hBMP_ImportClipboard = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 68)
_GUICtrlMenu_SetItemBmp($hMenu, 11, $hBMP_ImportClipboard)
Global $hBMP_ChkUpd = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 91)
_GUICtrlMenu_SetItemBmp($hMenu, 12, $hBMP_ImageEdit)
_GUICtrlMenu_SetItemBmp($hMenu, 13, $hBMP_ChkUpd)
Global $hBMP_VisitWeb = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 13)
_GUICtrlMenu_SetItemBmp($hMenu, 14, $hBMP_VisitWeb)
Global $hBMP_About = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 130)
_GUICtrlMenu_SetItemBmp($hMenu, 15, $hBMP_About)
Global $hBMP_Exit = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 27)
_GUICtrlMenu_SetItemBmp($hMenu, 17, $hBMP_Donate)
_GUICtrlMenu_SetItemBmp($hMenu, 19, $hBMP_Exit)

Global $List = GUICtrlCreateListView("", 4, 4, 250, $height - 40, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
;~ Global $List = GUICtrlCreateListView("", 4, 4, 250, 605, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))
Global $List_Tip = $aTranslations[45][$iLang]
If @OSBuild > 5999 And $aero Then $List_Tip &= @LF & @LF & $aTranslations[46][$iLang]
GUICtrlSetTip(-1, $List_Tip, "", 0, 1)
GUICtrlSetBkColor(-1, 0xFFFFFF)

Global $hBMP_Donate2 = _GDIPlus_BitmapCreateFromMemory(_Donate(), True)
Global $Pic_Donate = GUICtrlCreatePic("", 5, $height - 28, 61, 18)
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[47][$iLang], "", 0, 1)
_WinAPI_DeleteObject(GUICtrlSendMsg($Pic_Donate, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP_Donate2))
GUICtrlSetOnEvent($Pic_Donate, "Donate")

Global $hListView = GUICtrlGetHandle($List)
Global $Button_Refresh = GUICtrlCreateButton($aTranslations[48][$iLang], 70, $height - 33, 152, 27)
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[49][$iLang], "", 0, 1)

Global $Button_Lang = GUICtrlCreateButton("", 225, $height - 33, 30, 27, $BS_BITMAP)
GUICtrlSetTip(-1, $aTranslations[259][$iLang], "", 0, 1)
Global $hButton_Lang = GUICtrlGetHandle($Button_Lang)
GUICtrlSetOnEvent($Button_Lang, "Show_Lang_Menu")

For $i = 0 To UBound($aLanguages) - 1
	$hTmp = _GDIPlus_BitmapCreateFromMemory(Execute($aLanguages[$i] & "_flagpng()"))
	$aLanguagesFlags[$i][0] = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
	$hTmp2 = _GDIPlus_ImageResize2($hTmp, 14, 14)
	$aLanguagesFlags[$i][1] = _GDIPlus_Convert2HBitmap($hTmp2, $COLOR_MENU)
	_GDIPlus_BitmapDispose($hTmp2)
	_GDIPlus_BitmapDispose($hTmp)
Next

_WinAPI_DeleteObject(_SendMessage($hButton_Lang, $BM_SETIMAGE, $IMAGE_BITMAP, $aLanguagesFlags[$iLang][0]))

Global Const $txt = $aTranslations[79][$iLang]
Global $xPos_Btns = $gdip_x, $Button_Menu_GrabScreen, $Button_Menu_GrabScreen_Item, $Button_Menu_GrabScreen_Item2, $hHBITMAP_GrabScreen, $Button_GrabScreen, _
			  $hButton_GrabScreen, $biasw = $width / 900, $Btn_w = 99 * $width / 900, $xspace = $gdip_w / 6 + ($gdip_w - $Btn_w * 6) / 31.5
If @OSBuild < 6000 Then
	$Button_GrabScreen = GUICtrlCreateButton("", 264, $height - 90, $Btn_w, 82, $BS_BITMAP)
	GUICtrlSetCursor(-1, 0)
	$hTmp = _GDIPlus_ImageResize2(_GDIPlus_BitmapCreateFromMemory(Grab_Image()), 91, 73, 4)
	$hHBITMAP_GrabScreen = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_BTNFACE)
	_GDIPlus_BitmapDispose($hTmp)
	$hButton_GrabScreen = GUICtrlGetHandle($Button_GrabScreen)
	_WinAPI_DeleteObject(_SendMessage($hButton_GrabScreen, $BM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP_GrabScreen))
	_WinAPI_UpdateWindow($hButton_GrabScreen)
	GUICtrlSetOnEvent($Button_GrabScreen, "Grab_Screen")
	GUICtrlSetTip($Button_GrabScreen, $txt, "", 0, 1)
	$Button_Menu_GrabScreen = GUICtrlCreateContextMenu($Button_GrabScreen)
	$Button_Menu_GrabScreen_Item = GUICtrlCreateMenuItem($aTranslations[80][$iLang], $Button_Menu_GrabScreen)
	GUICtrlSetState($Button_Menu_GrabScreen_Item, $GUI_DISABLE)
Else
	$Button_GrabScreen = GUICtrlCreateButton($aTranslations[81][$iLang], 264, $height - 90, $Btn_w, 82, $BS_BITMAP)
	$hHBITMAP_GrabScreen = _GDIPlus_BitmapCreateFromMemory(Grab_Image(), True)
	$hButton_GrabScreen = GUICtrlGetHandle($Button_GrabScreen)
	_WinAPI_DeleteObject(_SendMessage($hButton_GrabScreen, $BM_SETIMAGE, 0, $hHBITMAP_GrabScreen))
	_WinAPI_UpdateWindow($hButton_GrabScreen)
	_WinAPI_DeleteObject($hHBITMAP_GrabScreen)
	GUICtrlSetCursor($Button_GrabScreen, 0)
	GUICtrlSetTip($Button_GrabScreen, $txt, "", 0, 1)
	GUICtrlSetOnEvent($Button_GrabScreen, "Grab_Screen")
	$Button_Menu_GrabScreen = GUICtrlCreateContextMenu($Button_GrabScreen)
	$Button_Menu_GrabScreen_Item = GUICtrlCreateMenuItem($aTranslations[80][$iLang], $Button_Menu_GrabScreen)
EndIf

Global $Button_WebGrab = GUICtrlCreateButton($aTranslations[61][$iLang], $xPos_Btns + $xspace, $height - 90, $Btn_w, 82, $BS_MULTILINE)
GUICtrlSetFont(-1, $biasw * 8.5 * $aDPI[0] - 0.5, 400, 0, "Times New Roman")
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[62][$iLang], "", 0, 1)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_ScreenshotaWebSitepng(), True)
_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($Button_WebGrab), $BM_SETIMAGE, $IMAGE_BITMAP, $hTmp))
_WinAPI_DeleteObject($hTmp)

Global $Button_Grab2AVI, $hImage_Btn_Grab2AVI
If @OSBuild < 6000 Then
	$Button_Grab2AVI = GUICtrlCreateButton("", $xPos_Btns + 2 * $xspace, $height - 90, $Btn_w, 82, $BS_BITMAP)
	Local $hButton_Grab2AVI = GUICtrlGetHandle($Button_Grab2AVI)
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_GrabScreentoAvipng())
	$hImage_Btn_Grab2AVI = _GDIPlus_CreateImageAndText($hTmp, $aTranslations[63][$iLang], $biasw * 8.0 * $aDPI[0] - 0.5)
	_WinAPI_DeleteObject(_SendMessage($hButton_Grab2AVI, $BM_SETIMAGE, $IMAGE_BITMAP, $hImage_Btn_Grab2AVI))
	_WinAPI_UpdateWindow($hButton_Grab2AVI)
	_GDIPlus_BitmapDispose($hTmp)
Else
	$Button_Grab2AVI = GUICtrlCreateButton($aTranslations[63][$iLang], $xPos_Btns + 2 * $xspace, $height - 90, $Btn_w, 82, $BS_MULTILINE)
	GUICtrlSetFont(-1, $biasw * 8.5 * $aDPI[0] - 0.5, 400, 0, "Times New Roman")
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_GrabScreentoAvipng(), True)
	_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($Button_Grab2AVI), $BM_SETIMAGE, $IMAGE_BITMAP, $hTmp))
	_WinAPI_DeleteObject($hTmp)
EndIf
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[64][$iLang], "", 0, 1)

Global $Button_Clipboard, $hImage_Btn_Clipboard
If @OSBuild < 6000 Then
	$Button_Clipboard = GUICtrlCreateButton("", $xPos_Btns + 3 * $xspace, $height - 90, $Btn_w, 82, $BS_BITMAP)
	Local $hButton_Clipboard = GUICtrlGetHandle($Button_Clipboard)
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_PuttoClipboardpng())
	$hImage_Btn_Clipboard = _GDIPlus_CreateImageAndText($hTmp, $aTranslations[56][$iLang], $biasw * 8.5 * $aDPI[0])
	_WinAPI_DeleteObject(_SendMessage($hButton_Clipboard, $BM_SETIMAGE, $IMAGE_BITMAP, $hImage_Btn_Clipboard))
	_WinAPI_UpdateWindow($hButton_Clipboard)
	_GDIPlus_BitmapDispose($hTmp)
Else
	$Button_Clipboard = GUICtrlCreateButton($aTranslations[56][$iLang], $xPos_Btns + 3 * $xspace, $height - 90, $Btn_w, 82, $BS_MULTILINE)
	GUICtrlSetFont(-1, $biasw * 8.5 * $aDPI[0], 400, 0, "Times New Roman")
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_PuttoClipboardpng(), True)
	_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($Button_Clipboard), $BM_SETIMAGE, $IMAGE_BITMAP, $hTmp))
	_WinAPI_DeleteObject($hTmp)
EndIf
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[57][$iLang], "", 0, 1)

Global $Button_Save, $hImage_Btn_Save
If @OSBuild < 6000 Then
	$Button_Save = GUICtrlCreateButton("", $xPos_Btns + 4 * $xspace, $height - 90, $Btn_w, 82, $BS_BITMAP)
	Local $hButton_Save = GUICtrlGetHandle($Button_Save)
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_SaveExitpng())
	$hImage_Btn_Save = _GDIPlus_CreateImageAndText($hTmp, $aTranslations[50][$iLang], $biasw * 8.5 * $aDPI[0])
	_WinAPI_DeleteObject(_SendMessage($hButton_Save, $BM_SETIMAGE, $IMAGE_BITMAP, $hImage_Btn_Save))
	_WinAPI_UpdateWindow($hButton_Save)
	_GDIPlus_BitmapDispose($hTmp)
Else
	$Button_Save = GUICtrlCreateButton($aTranslations[50][$iLang], $xPos_Btns + 4 * $xspace, $height - 90, $Btn_w, 82, $BS_MULTILINE)
	GUICtrlSetFont(-1, $biasw * 8.5 * $aDPI[0], 400, 0, "Times New Roman")
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_SaveExitpng(), True)
	_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($Button_Save), $BM_SETIMAGE, $IMAGE_BITMAP, $hTmp))
	_WinAPI_DeleteObject($hTmp)
EndIf
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, $aTranslations[51][$iLang] & $JPEG_Quality & "." & @LF & $aTranslations[52][$iLang], "", 0, 1)

Global $Button_Exit, $hImage_Btn_Exit
If @OSBuild < 6000 Then
	$Button_Exit = GUICtrlCreateButton("", $xPos_Btns + 5 * $xspace, $height - 90, $Btn_w, 82, $BS_BITMAP)
	Local $hButton_Exit = GUICtrlGetHandle($Button_Exit)
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_Exitpng())
	$hImage_Btn_Exit = _GDIPlus_CreateImageAndText($hTmp, $aTranslations[44][$iLang], $biasw * 10 * $aDPI[0])
	_WinAPI_DeleteObject(_SendMessage($hButton_Exit, $BM_SETIMAGE, $IMAGE_BITMAP, $hImage_Btn_Exit))
	_WinAPI_UpdateWindow($hButton_Exit)
	_GDIPlus_BitmapDispose($hTmp)
Else
	$Button_Exit = GUICtrlCreateButton(" " & $aTranslations[44][$iLang], $xPos_Btns + 5 * $xspace, $height - 90, $Btn_w, 82)
	GUICtrlSetFont(-1, $biasw * 11 * $aDPI[0], 400, 0, "Times New Roman")
	$hTmp = _GDIPlus_BitmapCreateFromMemory(_Exitpng(), True)
	_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($Button_Exit), $BM_SETIMAGE, $IMAGE_BITMAP, $hTmp))
	_WinAPI_DeleteObject($hTmp)
EndIf
GUICtrlSetCursor(-1, 0)

Global $Button_Menu = GUICtrlCreateContextMenu($Button_Save)
Global $hButton_Menu_Save = GUICtrlGetHandle($Button_Menu)
Global $Button_Menu_Item1 = GUICtrlCreateMenuItem($aTranslations[53][$iLang], $Button_Menu)
Global $Button_Menu_Item2 = GUICtrlCreateMenuItem($aTranslations[54][$iLang], $Button_Menu)
GUICtrlCreateMenuItem("", $Button_Menu)
Global $Button_Menu_Item3 = GUICtrlCreateMenuItem($aTranslations[55][$iLang], $Button_Menu)
Global $Button_Menu_Item4 = GUICtrlCreateMenuItem($aTranslations[267][$iLang], $Button_Menu)
If $bSave_Shadow Then GUICtrlSetState(-1, $GUI_CHECKED)

Global $hBMP_Menu_JPG_Qual = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", $icon_jpg_qual)
_GUICtrlMenu_SetItemBmp($hButton_Menu_Save, 0, $hBMP_Menu_JPG_Qual)

Global $bClipboard_PNG = False, $iFormat_PNG = _ClipBoard_RegisterFormat("PNG"), $hMemory_Clipboard
Global $Button_Clipboard_Menu = GUICtrlCreateContextMenu($Button_Clipboard)
Global $Button_Clipboard_Menu_Sub = GUICtrlCreateMenu($aTranslations[58][$iLang], $Button_Clipboard_Menu)
Global $Button_Clipboard_Menu_Sub_Item1 = GUICtrlCreateMenuItem($aTranslations[59][$iLang], $Button_Clipboard_Menu_Sub, 1)
Global $Button_Clipboard_Menu_Sub_Item2 = GUICtrlCreateMenuItem($aTranslations[60][$iLang], $Button_Clipboard_Menu_Sub, 2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateMenuItem("", $Button_Clipboard_Menu)
Global $Button_Clipboard_Menu_Sub2 = GUICtrlCreateMenuItem($aTranslations[268][$iLang], $Button_Clipboard_Menu)
GUICtrlCreateMenuItem("", $Button_Clipboard_Menu)
Global $Button_Clipboard_Menu_Sub3 = GUICtrlCreateMenuItem($aTranslations[277][$iLang], $Button_Clipboard_Menu)
If $bSave_Shadow Then GUICtrlSetState($Button_Clipboard_Menu_Sub3, $GUI_CHECKED)

Global $image2clipboard = False
Global $hButton_Clipboard_Menu = GUICtrlGetHandle($Button_Clipboard_Menu)
Global $hBMP_Button_Clipboard_Menu = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", 98)
_GUICtrlMenu_SetItemBmp($hButton_Clipboard_Menu, 0, $hBMP_Button_Clipboard_Menu)

Global $Button_Menu_AVI = GUICtrlCreateContextMenu($Button_Grab2AVI)
Global $hButton_Menu_AVI = GUICtrlGetHandle($Button_Menu_AVI)
Global $Button_Menu_AVI_Sub1 = GUICtrlCreateMenu($aTranslations[65][$iLang], $Button_Menu_AVI, 1)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Avi_Timepng())
Global $hBMP_Menu_AviRecTime = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hButton_Menu_AVI, 0, $hBMP_Menu_AviRecTime)
GUICtrlCreateMenuItem("", $Button_Menu_AVI)

Global $aButton_Menu_AVI_Sub1_Item[6], $AVI_ReqTime[6] = [5, 10, 30, 60, $aTranslations[66][$iLang], 0], $AVI_FPS[5] = [1, 5, 10, 15]

$aButton_Menu_AVI_Sub1_Item[0] = GUICtrlCreateMenuItem($AVI_ReqTime[0] & $aTranslations[67][$iLang], $Button_Menu_AVI_Sub1, 1)
$aButton_Menu_AVI_Sub1_Item[1] = GUICtrlCreateMenuItem($AVI_ReqTime[1] & $aTranslations[67][$iLang], $Button_Menu_AVI_Sub1, 2)
GUICtrlSetState(-1, $GUI_CHECKED)
$aButton_Menu_AVI_Sub1_Item[2] = GUICtrlCreateMenuItem($AVI_ReqTime[2] & $aTranslations[67][$iLang], $Button_Menu_AVI_Sub1, 3)
$aButton_Menu_AVI_Sub1_Item[3] = GUICtrlCreateMenuItem($AVI_ReqTime[3] & $aTranslations[67][$iLang], $Button_Menu_AVI_Sub1, 4)
$aButton_Menu_AVI_Sub1_Item[4] = GUICtrlCreateMenuItem($AVI_ReqTime[4], $Button_Menu_AVI_Sub1, 5)
GUICtrlCreateMenuItem("", $Button_Menu_AVI_Sub1)
$aButton_Menu_AVI_Sub1_Item[5] = GUICtrlCreateMenuItem($aTranslations[68][$iLang], $Button_Menu_AVI_Sub1, 6)

Global $Button_Menu_AVI_Sub2 = GUICtrlCreateMenu("AVI FPS", $Button_Menu_AVI, 2)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Avi_FPSpng())
Global $hBMP_Menu_AviFPS = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hButton_Menu_AVI, 2, $hBMP_Menu_AviFPS)
GUICtrlCreateMenuItem("", $Button_Menu_AVI)
Global $aButton_Menu_AVI_Sub2_Item[6]
$aButton_Menu_AVI_Sub2_Item[0] = GUICtrlCreateMenuItem($AVI_FPS[0] & $aTranslations[70][$iLang], $Button_Menu_AVI_Sub2, 1)
$aButton_Menu_AVI_Sub2_Item[1] = GUICtrlCreateMenuItem($AVI_FPS[1] & $aTranslations[70][$iLang], $Button_Menu_AVI_Sub2, 2)
$aButton_Menu_AVI_Sub2_Item[2] = GUICtrlCreateMenuItem($AVI_FPS[2] & $aTranslations[70][$iLang], $Button_Menu_AVI_Sub2, 3)
GUICtrlSetState(-1, $GUI_CHECKED)
$aButton_Menu_AVI_Sub2_Item[3] = GUICtrlCreateMenuItem($AVI_FPS[3] & $aTranslations[70][$iLang], $Button_Menu_AVI_Sub2, 4)
GUICtrlCreateMenuItem("", $Button_Menu_AVI_Sub2)
$aButton_Menu_AVI_Sub2_Item[4] = GUICtrlCreateMenuItem($aTranslations[68][$iLang], $Button_Menu_AVI_Sub2, 5)

GUICtrlCreateMenuItem("", $Button_Menu_AVI)
Global Const $Button_Menu_AVI_Sub3 = GUICtrlCreateMenu($aTranslations[71][$iLang], $Button_Menu_AVI, 4)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Avi_Timestamppng())
Global $hBMP_Menu_AviTimeStamp = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hButton_Menu_AVI, 4, $hBMP_Menu_AviTimeStamp)
Global Const $mButton_Menu_AVI_Sub3_Item1 = GUICtrlCreateMenuItem($aTranslations[72][$iLang], $Button_Menu_AVI_Sub3, 1, 1)
Global Const $mButton_Menu_AVI_Sub3_Item2 = GUICtrlCreateMenuItem($aTranslations[73][$iLang], $Button_Menu_AVI_Sub3, 2, 1)
GUICtrlSetState($mButton_Menu_AVI_Sub3_Item2, $GUI_CHECKED)

GUICtrlCreateMenuItem("", $Button_Menu_AVI)
Global Const $Button_Menu_AVI_Sub4 = GUICtrlCreateMenu($aTranslations[74][$iLang], $Button_Menu_AVI, 6)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Avi_Compresspng())
Global $hBMP_Menu_AviCompress = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hButton_Menu_AVI, 6, $hBMP_Menu_AviCompress)
Global Const $mButton_Menu_AVI_Sub4_Item1 = GUICtrlCreateMenuItem($aTranslations[72][$iLang], $Button_Menu_AVI_Sub4, 1, 1)
Global Const $mButton_Menu_AVI_Sub4_Item2 = GUICtrlCreateMenuItem($aTranslations[73][$iLang], $Button_Menu_AVI_Sub4, 2, 1)
GUICtrlSetState($mButton_Menu_AVI_Sub4_Item1, $GUI_CHECKED)

Global Const $Button_Menu_AVI_Sub5 = GUICtrlCreateMenu($aTranslations[75][$iLang], $Button_Menu_AVI, 8)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_Avi_Mousepng())
Global $hBMP_Menu_AviMouse = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp($hButton_Menu_AVI, 8, $hBMP_Menu_AviMouse)
Global Const $mButton_Menu_AVI_Sub5_Item1 = GUICtrlCreateMenuItem($aTranslations[72][$iLang], $Button_Menu_AVI_Sub5, 1, 1)
Global Const $mButton_Menu_AVI_Sub5_Item2 = GUICtrlCreateMenuItem($aTranslations[73][$iLang], $Button_Menu_AVI_Sub5, 2, 1)
GUICtrlSetState($mButton_Menu_AVI_Sub5_Item1, $GUI_CHECKED)

Global Const $Button_Menu_Web = GUICtrlCreateContextMenu($Button_WebGrab)
Global Const $Button_Menu_Web_Item1 = GUICtrlCreateMenuItem($aTranslations[76][$iLang], $Button_Menu_Web)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateMenuItem("", $Button_Menu_Web)
Global Const $Button_Menu_Web_Item2 = GUICtrlCreateMenu($aTranslations[77][$iLang], $Button_Menu_Web)
$hTmp = _GDIPlus_BitmapCreateFromMemory(_WebWidthpng())
Global $hBMP_Menu_WebWitdh = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GDIPlus_BitmapDispose($hTmp)
_GUICtrlMenu_SetItemBmp(GUICtrlGetHandle($Button_Menu_Web), 2, $hBMP_Menu_WebWitdh)
Global $Button_Menu_Web_Item2_Sub[4], $Button_Menu_Web_Item2_Sub_Items[4] = [800, 1024, 1280, @DesktopWidth]
$Button_Menu_Web_Item2_Sub[0] = GUICtrlCreateMenuItem($Button_Menu_Web_Item2_Sub_Items[0] & $aTranslations[78][$iLang], $Button_Menu_Web_Item2)
$Button_Menu_Web_Item2_Sub[1] = GUICtrlCreateMenuItem($Button_Menu_Web_Item2_Sub_Items[1] & $aTranslations[78][$iLang], $Button_Menu_Web_Item2)
$Button_Menu_Web_Item2_Sub[2] = GUICtrlCreateMenuItem($Button_Menu_Web_Item2_Sub_Items[2] & $aTranslations[78][$iLang], $Button_Menu_Web_Item2)
GUICtrlSetState(-1, $GUI_CHECKED)
$Button_Menu_Web_Item2_Sub[3] = GUICtrlCreateMenuItem($Button_Menu_Web_Item2_Sub_Items[3] & $aTranslations[78][$iLang], $Button_Menu_Web_Item2)

If @OSBuild < 6000 And Not $aero Then GUICtrlSetState($Button_WebGrab, $GUI_DISABLE)
$tChkAero = 0

Global Const $Button_Lang_Dummy = GUICtrlCreateDummy()
Global Const $Button_Menu_Lang = GUICtrlCreateContextMenu($Button_Lang_Dummy)
Global Const $hButton_Menu_Lang = GUICtrlGetHandle($Button_Menu_Lang)
Global $aButton_Menu_Lang_Items[UBound($aLanguages)]

For $i = 0 To UBound($aButton_Menu_Lang_Items) - 1
	$aButton_Menu_Lang_Items[$i] = GUICtrlCreateMenuItem(" " & $aLanguages[$i], $Button_Menu_Lang)
	_GUICtrlMenu_SetItemBmp($hButton_Menu_Lang, $i, $aLanguagesFlags[$i][1])
Next

Global $hButton_Menu_GrabScreen = GUICtrlGetHandle($Button_Menu_GrabScreen)

Global $hTmp2 = _GUICtrlMenu_CreateBitmap(@SystemDir & "\Shell32.dll", $icon_redo)
$hTmp = _GDIPlus_BitmapCreateFromHBITMAP($hTmp2)
Global $hBMP_Menu_GrabScreen_Redo = _GDIPlus_Convert2HBitmap($hTmp, $COLOR_MENU)
_GUICtrlMenu_SetItemBmp($hButton_Menu_GrabScreen, 0, $hBMP_Menu_GrabScreen_Redo)
_GDIPlus_BitmapDispose($hTmp)
_WinAPI_DeleteObject($hTmp2)

Global $Button_JPG_Quality = GUICtrlCreateButton("", -10, -10, 1, 1)
GUICtrlSetOnEvent($Button_JPG_Quality, "JPG_Quality")

Global $Group = GUICtrlCreateGroup("UEZ 2010 - 2021", 259, 0, $gdip_w + 9, 70, BitOR($GUI_SS_DEFAULT_GROUP, $BS_RIGHT))
GUICtrlSetFont(-1, 8 * $aDPI[0], 200, 0, "Times New Roman")

Global $hImage_logo = _GDIPlus_BitmapCreateFromMemory(_Logo())
;~ Global $hImage_logo = _GDIPlus_ImageLoadFromFile("Files\Windows Screenshooter43.1.1.png")
Global $hImage_logo_w = _GDIPlus_ImageGetWidth($hImage_logo), $hImage_logo_h = _GDIPlus_ImageGetHeight($hImage_logo)
Global $f1 = $gdip_w / $hImage_logo_w - 0.025
Global $Logo_w = $hImage_logo_w * $f1, $Logo_h = $hImage_logo_h * $f1
Global $hImage_logo_resized = _GDIPlus_ImageResize($hImage_logo, $Logo_w, $Logo_h)
Global $hHBITMAP_Logo = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage_logo_resized)
_GDIPlus_ImageDispose($hImage_logo)
_GDIPlus_ImageDispose($hImage_logo_resized)

Global $Pic_Logo = GUICtrlCreatePic("", 259 + (($gdip_w - $Logo_w) / 2), Round((70 - $Logo_h) / 2, 0) + 1 , $Logo_w, $Logo_h)
_WinAPI_DeleteObject(GUICtrlSendMsg($Pic_Logo, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP_Logo))
GUICtrlCreateGroup("", -99, -99, 1, 1)

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND(HWnd($hGUI))
Global $hBuffer_Bmp = _GDIPlus_BitmapCreateFromGraphics($gdip_w, $gdip_h, $hGraphic)
Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBuffer_Bmp)
_GDIPlus_GraphicsSetPixelOffsetMode($hContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
_GDIPlus_GraphicsSetInterpolationMode($hContext, 7) ; set interpolation quality (5 -> 0, 0 -> 1, 7 -> 2)
_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 2)

Global $hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $gdip_w / 2, $gdip_h / 2)

Global $Gfx = GUICtrlCreateGraphic($gdip_x - 2, $gdip_y - 2, $gdip_w + 4, $gdip_h + 4)
If @OSBuild >= 6000 Then GUICtrlSetBkColor($Gfx, 0xFFFFFF)
GUICtrlSetColor($Gfx, 0x000060)

Global $label3 = GUICtrlCreateLabel($aTranslations[82][$iLang], $gdip_x + 2, $height - 107.5, 120, 18)
GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman", 5)
GUICtrlSetBkColor(-1, -2)
Global $aTmp = GetStringSize($aTranslations[82][$iLang], "Times New Roman", 9.75 * $aDPI[0])
Global $label4 = GUICtrlCreateLabel("", $gdip_x + $aTmp[0] - 1, $height - 107, 200, 16)
GUICtrlSetFont(-1, 8.75 * $aDPI[0], 500, 0, "Times New Roman", 5)
GUICtrlSetBkColor(-1, -2)

_GUICtrlListView_InsertColumn($List, 0, $aTranslations[1][$iLang], 165)
_GUICtrlListView_InsertColumn($List, 1, $aTranslations[2][$iLang], 80)
Refresh_Wnd_List()

GUICtrlSetOnEvent($Button_Refresh, "Refresh_Wnd_List")
GUICtrlSetOnEvent($Button_WebGrab, "WebGrab")
GUICtrlSetOnEvent($Button_Grab2AVI, "Grab2AVI")
GUICtrlSetOnEvent($Button_Clipboard, "Pic2Clipboard")
GUICtrlSetOnEvent($Button_Save, "Save_Bitmap")
GUICtrlSetOnEvent($Button_Exit, "_Exit")
#EndRegion GUI part

;~ Global Const $GDIP_FRAMEDIMENSION_TIME = "{6AEFBD6D-3FB5-418A-83A6-7F45229DC872}"
Global Const $iPropID_FrameDelay = 0x5100
Global Const $tagGDIPPROPERTYITEM = "uint id;ulong length;dword type;ptr value"
Global $pGUID, $tGUID, $hImage_Anim, $iFrame_Anim, $iFrameCount_Anim, $iW_Anim, $iH_Anim
$tGUID = DllStructCreate($tagGUID)
$pGUID = DllStructGetPtr($tGUID)

Global $iGUI_IE_BGColor = 0x808080, $IE_tmp, $IE_Bmp_Undo, $skip_display, $hWnd_GUI = $hGUI, $IE_Pix_Size = 8, $pixel_color, $iLabelZoom_iColor
Global Enum $idSave_IE = 1500, $idCopy_IE, $idSend_IE, $idUndo_IE, $idPen_IE, $idHighlighter_IE, $idRectangle_IE, $idEllipse_IE, $idArrow_IE, $idColor_IE, $idText_IE, $idText_Conf_IE, $idFX_IE, _
		$idFX_IE_GS, $idFX_IE_BW, $idFX_IE_INV, $idFX_IE_BLUR, $idFX_IE_Pix, $idFX_IE_Rast, $idFX_IE_Resize, $idFX_IE_Crop
Global $hGUI_ImageEditor, $hGUI_ImageEditor_Child, $hGUI_ImageEditor_Blur, $idInput_IE_Blur, $hSlider_IE_Blur, $hGUI_ImageEditor_GS, $hSlider_IE_GS, $idInput_IE_GS, $hGUI_ImageEditor_BW, $hSlider_IE_BW, $idInput_IE_BW, $hGUI_IE_Crop = 0, $iLable_CropMove
Global $idPic_ImageEditor, $hCtx_IE_BMP, $hToolbar_IE, $IE_iItem, $TB_Button_Chk, $TB_Menu_Chk, $hPen_IE, $hPenArrow_IE, $hPenArrowShadow_IE, $hCursor_IE, $hCursor_System
Global $IE_Brush_Col, $IE_Brush_w, $IE_Brush_h, $IE_Pen_Col, $IE_PenSize, $IE_HL_Col, $IE_HL_Col_BGR, $IE_HLSize, $IE_offset_x, $IE_offset_y, $IE_Tool_Selected, $iPosX_Crop, $iPosY_Crop, $iDeltaX_Crop, $iDeltaY_Crop
Global $idInput_IE_H, $idInput_IE_HP, $idInput_IE_W, $idInput_IE_WP, $idChkBox_IE_AR, $idLabel_IE_SizeN
Global Enum $idIEPen_Size = 1600, $idIEPen_Size_1px, $idIEPen_Size_2px, $idIEPen_Size_4px, $idIEPen_Size_8px, $idIEPen_Size_16px
Global $IE_ScrollbarH = False, $IE_ScrollbarV = False, $Undo_IE = False, $bLocked_IE = False, $bCropWinActive = False, $bMove_Crop = True
Global $IE_Dummy_Ras, $IE_Dummy_Pix, $IE_Dummy_Blur, $IE_Dummy_BW, $IE_Dummy_Res, $IE_Dummy_Crop, $iSliderBlur_Min, $iSliderBlur_Max, $iInputBlur
Global Const $hFont_IE_Color = _WinAPI_CreateFont(14.5, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, $OUT_TT_PRECIS, $CLIP_DEFAULT_PRECIS, BitOR($PROOF_QUALITY, $ANTIALIASED_QUALITY), BitOR($DEFAULT_PITCH, $FF_DONTCARE), "Arial")
Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;hwnd HDC;int Rect[4];long_ptr ItemSpec;uint ItemState;long_ptr ItemParam"
Global Const $tagNMTBCUSTOMDRAW = $tagNMCUSTOMDRAWINFO & ";hwnd hbrMonoDither;hwnd hbrLines;hwnd hpenLines;dword clrText;dword clrMark;dword clrTextHighlight;dword clrBtnFace;dword clrBtnHighlight;dword clrHighlightHotTrack;int rcText[4];int nStringBkMode;int nHLStringBkMode;int iListGap"
Global Const $TBCDRF_USECDCOLORS = 0x00800000; Vista+

Global $iGUI_MinW, $iGUI_MinH, $hGUI_WM
Global Const $iW_Grp_WM = 722, $iH_Grp_WM = 468, $iGUI_W = 953, $iGUI_H = 703, $iRTOP = BitOR($SRCCOPY, $CAPTUREBLT)
Global Const $iW_Pic_WM = $iW_Grp_WM - 20, $iH_Pic_WM = $iH_Grp_WM - 30, $iMinFontSize_WM = 4, $iMaxFontSize_WM = 256, $iRadius_Max_WM = 500, $iRadius_Min_WM = 8
Global $hBitmap_WM, $hBitmapUndo_WM, $hBmp_Preview_WM, $hBitmapStamp_WM, $hBitmap_Stamp_w, $hBitmap_Stamp_h, $hBitmapStampPreview_WM, $iColorFont_WM = 0xFF0000, $sText_WM, $sFont_WM, $fAlpha_WM, $iFontSize_WM
Global $iPos_WM, $iRadius_WM, $iRotation_WM, $idInputText_WM, $idComboFont_WM, $hComboFont_WM, $idInputOpaque_WM, $idInputFSize_WM, $idInputRadius_WM, $idInputDegree_WM, $idPicPreview_WM
Global $idCheckboxCircular_WM, $idLabelRadius_WM, $idSliderRadius_WM, $idRadioUpperLeft_WM, $idRadioUpperMid_WM, $idRadioUpperRight_WM, $idRadioMidLeft_WM, $idRadioCenter_WM, $idUpdown_WM
Global $hUpdown_WM, $idRadioMidRight_WM, $idRadioButtomLeft_WM, $idRadioButtomMid_WM, $idRadioButtomRight_WM, $idSliderDegree_WM, $hSliderDegree_WM, $idSliderOpaque_WM, $iGUI_WM_color = 0xF0F0F0
Global $hSliderOpaque_WM, $hSliderRadius_WM, $idRadioImagePreview_WM, $idRadioColor_WM, $bStamp_WM = False, $hBitmap_Preview_WM, $hDC_WM, $hDC_backbuffer_WM, $DC_obj_WM, $hGraphic_WM
Global $idCheckboxFill_WM, $sFileImage_WM
Global $idSliderAdjX_WM, $idSliderAdjY_WM, $hSliderAdjX_WM, $hSliderAdjY_WM, $idRadioTxtFXDefault_WM, $idButtonLoadFont_WM, $idButtonTPColor_WM, $iColorImgTP_WM = 0x000000
Global $bUpdate_WM = False, $sFX_WM = "Default", $bDnD = False, $bResize = False, $__Enum
Global $idButtonColor_WM, $idRadioTxtFXOutline_WM, $idRadioTxtFXEmbossed_WM, $idLabelImgDimSize
Global $iGUI_WM_color = 0xF0F0F0, $red, $green, $blue

If Not $aero Then
	$iGUI_WM_color = _WinAPI_GetSysColor($COLOR_BTNFACE)
	$blue = Hex(BitShift($iGUI_WM_color, 16), 2)
	$green = Hex(BitAND(BitShift($iGUI_WM_color, 8), 0xFF), 2)
	$red = Hex(BitAND($iGUI_WM_color, 0xFF), 2)
	$iGUI_WM_color = "0x" & $red & $green & $blue ;converted from BGR to RGB format
EndIf
Global $idLabel_WM_SizeC, $idLabel_WM_SizeN, $idInput_WM_W, $idInput_WM_H, $idInput_WM_WP, $idInput_WM_HP, $idChkBox_WM_AR, $bFill = False
Global $iPos_WM = 9, $sSaveType = "jpg", $iJPGQual_WM, $iColorFont_Embossed_WM = 0x000000, $iManPosX = 0, $iManPosY = 0, $iAdjX_WM = 0, $iAdjY_WM = 0
Global Const $fRad = 180 / ACos(-1), $sFXs = "Default;Outlined;Embossed;"

Global Const $tagTT_OFFSET_TABLE = "USHORT uMajorVersion;USHORT uMinorVersion;USHORT uNumOfTables;USHORT uSearchRange;USHORT uEntrySelector;USHORT uRangeShift"
Global Const $tagTT_TABLE_DIRECTORY = "char szTag[4];ULONG uCheckSum;ULONG uOffset;ULONG uLength"
Global Const $tagTT_NAME_TABLE_HEADER = "USHORT uFSelector;USHORT uNRCount;USHORT uStorageOffset"
Global Const $tagTT_NAME_RECORD = "USHORT uPlatformID;USHORT uEncodingID;USHORT uLanguageID;USHORT uNameID;USHORT uStringLength;USHORT uStringOffset"

Global Const $GDIP_LF_FACESIZE = 32
Global $hFontCollection = _GDIPlus_FontCollectionCreate()
Global $aFontFamilies = _GDIPlus_FontCollectionGetFamilyList($hFontCollection), $hFontFamily, $sFonts
For $i = 1 To UBound($aFontFamilies) - 1
	$hFontFamily = $aFontFamilies[$i]
	$sFonts &= _GDIPlus_FontFamilyGetFamilyName($hFontFamily) & "|"
Next
$sFonts = StringTrimRight($sFonts, 1)

Global $bFontMan = False, $hCollection_WM, $sFileFont, $sFileFontName, $sAddFonts = ""

$hCollection_WM = _GDIPlus_NewPrivateFontCollection()

Global Const $hMenu_IE_PS = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu_IE_PS, $aTranslations[3][$iLang], $idIEPen_Size_1px)
_GUICtrlMenu_AddMenuItem($hMenu_IE_PS, $aTranslations[4][$iLang], $idIEPen_Size_2px)
_GUICtrlMenu_AddMenuItem($hMenu_IE_PS, $aTranslations[5][$iLang], $idIEPen_Size_4px)
_GUICtrlMenu_AddMenuItem($hMenu_IE_PS, $aTranslations[6][$iLang], $idIEPen_Size_8px)
_GUICtrlMenu_AddMenuItem($hMenu_IE_PS, $aTranslations[7][$iLang], $idIEPen_Size_16px)
_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 2)

Global Const $hMenu_IE_FX = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 0, $aTranslations[8][$iLang], $idFX_IE_GS)
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 1, $aTranslations[9][$iLang], $idFX_IE_BW)
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 2, $aTranslations[10][$iLang], $idFX_IE_INV)
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 3, $aTranslations[11][$iLang], $idFX_IE_BLUR)
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 4, $aTranslations[12][$iLang], $idFX_IE_Pix)
_GUICtrlMenu_InsertMenuItem($hMenu_IE_FX, 5, $aTranslations[13][$iLang], $idFX_IE_Rast)


Global $hBMP_ImageEdit_FXGray = _GDIPlus_BitmapCreateFromMemory(_GreyscaleImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 0, $hBMP_ImageEdit_FXGray)
Global $hBMP_ImageEdit_FXBW = _GDIPlus_BitmapCreateFromMemory(_BlackWhiteImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 1, $hBMP_ImageEdit_FXBW)
Global $hBMP_ImageEdit_FXInvert = _GDIPlus_BitmapCreateFromMemory(_NegImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 2, $hBMP_ImageEdit_FXInvert)
Global $hBMP_ImageEdit_FXBlur = _GDIPlus_BitmapCreateFromMemory(_BlurImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 3, $hBMP_ImageEdit_FXBlur)
Global $hBMP_ImageEdit_FXPixelize = _GDIPlus_BitmapCreateFromMemory(_PixelizeImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 4, $hBMP_ImageEdit_FXPixelize)
Global $hBMP_ImageEdit_FXRasterize = _GDIPlus_BitmapCreateFromMemory(_RasterizeImage(), True)
_GUICtrlMenu_SetItemBmp($hMenu_IE_FX, 5, $hBMP_ImageEdit_FXRasterize)


Global $iButtonIE_Dummy = GUICtrlCreateButton("", -2, -2, 1, 1)
GUICtrlSetOnEvent($iButtonIE_Dummy, "Call_ImageEditor")
Global $iButtonWM_Dummy = GUICtrlCreateButton("", -3, -3, 1, 1)
GUICtrlSetOnEvent($iButtonWM_Dummy, "Call_Watermark")

Global Const $iButton_Numpad8 = GUICtrlCreateButton("", -100, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Numpad8, "Numpad8_Scroll")
Global Const $iButton_Numpad2 = GUICtrlCreateButton("", -102, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Numpad2, "Numpad2_Scroll")
Global Const $iButton_Numpad4 = GUICtrlCreateButton("", -104, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Numpad4, "Numpad4_Scroll")
Global Const $iButton_Numpad6 = GUICtrlCreateButton("", -106, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Numpad6, "Numpad6_Scroll")
Global Const $iButton_NumpadAdd = GUICtrlCreateButton("", -108, -100, 1, 1)
GUICtrlSetOnEvent($iButton_NumpadAdd, "NumpadAdd_Scroll")
Global Const $iButton_NumpadSub = GUICtrlCreateButton("", -110, -100, 1, 1)
GUICtrlSetOnEvent($iButton_NumpadSub, "NumpadSub_Scroll")

Global Const $iButton_Ruler = GUICtrlCreateButton("", -112, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Ruler, "Call_Ruler")

Global Const $iButton_Undo = GUICtrlCreateButton("", -114, -100, 1, 1)
GUICtrlSetOnEvent($iButton_Undo, "Call_Undo")

If $aero Then
	Global $AccelKeys[13][2] = [["^s", $Button_Save],["^x", $Button_Exit],["^i", $iButtonIE_Dummy],["^m", $iButtonWM_Dummy],["^w", $Button_WebGrab], ["^r", $iButton_Ruler], ["^z", $iButton_Undo], _
			["{NUMPAD8}", $iButton_Numpad8],["{NUMPAD2}", $iButton_Numpad2],["{NUMPAD4}", $iButton_Numpad4], _
			["{NUMPAD6}", $iButton_Numpad6],["{NUMPADADD}", $iButton_NumpadAdd],["{NUMPADSUB}", $iButton_NumpadSub]]
Else
	Global $AccelKeys[12][2] = [["^s", $Button_Save],["^x", $Button_Exit],["^i", $iButtonIE_Dummy],["^m", $iButtonWM_Dummy], ["^r", $iButton_Ruler], ["^z", $iButton_Undo], _
			["{NUMPAD8}", $iButton_Numpad8],["{NUMPAD2}", $iButton_Numpad2],["{NUMPAD4}", $iButton_Numpad4], _
			["{NUMPAD6}", $iButton_Numpad6],["{NUMPADADD}", $iButton_NumpadAdd],["{NUMPADSUB}", $iButton_NumpadSub]]
EndIf

Global $bReset = False
Global $KeyLayout = RegRead("HKCU\Keyboard Layout\Preload", 1)
If Not @error And $KeyLayout = 00000419 Then
	_WinAPI_LoadKeyboardLayout(0x0409)
	$bReset = True
EndIf

GUISetAccelerators($AccelKeys, $hGUI)

If $bReset Then _WinAPI_LoadKeyboardLayout(Dec($KeyLayout))


Global Const $hMainGUI_Image = _GDIPlus_BitmapCreateFromMemory(_MainGUI_Icon())
Local Const $hMainGUI_Icon = _WinAPI_SetWindowTitleIcon($hMainGUI_Image, $hGUI)
_GDIPlus_ImageDispose($hMainGUI_Image)


If $bStartMin Then
	GUISetState(@SW_SHOWMINIMIZED, $hGUI)
Else
	GUISetState(@SW_SHOW, $hGUI)
EndIf

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")

Global $NCPaint = False, $fade_speed = 0.15, $bRepaintXP = True
If @OSBuild < 6000 Then
	GUIRegisterMsg($WM_PAINT, "Redraw_XP")
	$fade_speed = 0.075
Else
	GUIRegisterMsg($WM_NCPAINT, "Redraw")
EndIf

;activate random window
Refresh_Wnd_List()
Global $random
If _GUICtrlListView_GetItemCount($List) - 1 > 0 Then
	$random = Random(0, _GUICtrlListView_GetItemCount($List) - 1, 1)
	_GUICtrlListView_SetItemSelected($List, $random)
	Capture_Window(HWnd(_GUICtrlListView_GetItemText($List, $random, 1)), $aWnd[$random][2], $aWnd[$random][3])
	_GUICtrlListView_SetItemSelected($List, $random)
EndIf

Global Const $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")
Global $hGUI_Freehand, $hBmp_Freehand, $hGraphic_Freehand, $hCP_old
Global $mc, $mc2, $mc3, $sx, $sy, $mpointer
Global $zx, $zy, $up, $zwm, $hGUI_Zoom, $hDC_Zoom, $hGUI_ZoomDC
Global $dirx = 1, $drx = 0, $diry = 1, $dry = 0, $lower_border, $right_border, $aLastPos[2]
Global Const $radius = 180
Global Const $zw = 256
Global Const $zh = 256
Global Const $zoom_level_default = 6
Global $zoom_level = $zoom_level_default
Global $zoomW = Int($zw / $zoom_level)
Global $zoomH = Int($zh / $zoom_level)
Global Const $zoom_min = 2, $zoom_max = 24
Global $red, $green, $blue

Global $iXMSeconds = 1000, $iXSeconds_Duration = 30, $sCapture_FilenameExt = "jpg", $bCaptureXSeconds = False, $bGIFAnim, $iDither

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Global Const $iFrameH = _WinAPI_GetSystemMetrics(31) + _WinAPI_GetSystemMetrics(33)
Global $hNext = _ClipBoard_SetViewer(HWnd($hGUI)), $bCBChanged = False

Global Const $tagCURSORINFO = "dword Size;dword Flags;handle hCursor;" & $tagPOINT

GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")

HotKeySet("^!{F9}", "Grab_Screen") ;call grab screen function
HotKeySet("^!{F12}", "Grab_Active_Window") ;Ctrl+Alt+F12 to take a screenshot of active window

If $iStateAnim Then _WinAPI_SetGUIMinMaxAnim(0)

_AutoItObject_StartUp()

While Sleep(10)
	If $NCPaint Then
		_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBuffer_Bmp, $gdip_x, $gdip_y, $gdip_w, $gdip_h)
		$NCPaint = False
	EndIf
	If WinActive(HWnd($hGUI)) Then
		If _IsPressed("70", $dll) Then ;F1 - Capture again on last position
			Recapture()
			While _IsPressed("70", $dll)
				Sleep(250)
			WEnd
		EndIf
		If _IsPressed("79", $dll) And $undo_chk Then ;F10
			Undo()
			Zoom(2)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 2)
			_WinAPI_UpdateWindow(HWnd($hGUI))
		EndIf
		If _IsPressed("74", $dll) Then ;F5
			Refresh_Wnd_List()
			While _IsPressed("74", $dll)
				Sleep(250)
			WEnd
		EndIf
		If _IsPressed("7A", $dll) Then ;F11
			GUISetState(@SW_MINIMIZE, $hGUI)
			Sleep(250)
			Grab_Region($aFullScreen[0], $aFullScreen[1], $aFullScreen[2], $aFullScreen[3], True)
			sndPlaySound($BytePtr, $fuSound)
			GUISetState(@SW_RESTORE, $hGUI)
			While _IsPressed("7A", $dll)
				Sleep(250)
			WEnd
		EndIf
		If _IsPressed("7B", $dll) Then ;F12
			GUISetState(@SW_MINIMIZE, $hGUI)
			Sleep(250)
			Grab_Region($aFullScreen[0], $aFullScreen[1], $aFullScreen[2], $aFullScreen[3])
			sndPlaySound($BytePtr, $fuSound)
			GUISetState(@SW_RESTORE, $hGUI)
			While _IsPressed("7B", $dll)
				Sleep(250)
			WEnd
		EndIf

		$mc = GUIGetCursorInfo(HWnd($hGUI))
		If Not @error Then
			If _IsPressed("01", $dll) And $mc[4] = $Gfx Then ;move preview image
				$mpointer = MouseGetCursor()
				GUICtrlSetCursor($Gfx, 9)
				$mc2 = MouseGetPos()
				While _IsPressed("01", $dll)
					$mc3 = MouseGetPos()
					If $mc2[0] <> $mc3[0] Or $mc2[1] <> $mc3[1] Then
						$scroll_x = ($sx + ($mc3[0] - $mc2[0]) / ($z ^ 2 / 80))
						$scroll_y = ($sy + ($mc3[1] - $mc2[1]) / ($z ^ 2 / 80))
						Draw2Graphic($hBmp)
						Zoom(2)
					EndIf
					Sleep(20)
				WEnd
				GUICtrlSetCursor($Gfx, $mpointer)
			EndIf
			If _IsPressed("02", $dll) And $mc[4] = $Pic_Donate Then
				MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $aTranslations[84][$iLang] & @TAB & "Cuong Nguyen" & @CRLF & @CRLF & @CRLF & _
						$aTranslations[85][$iLang], 30, $hGUI)
			EndIf
		EndIf
		$sx = $scroll_x
		$sy = $scroll_y
	EndIf
;~ 	If _IsPressed("11", $dll) And _IsPressed("77", $dll) Then GrabPrintScreenClipboard() ;Ctrl + F8 -> Printscreen
;~ 	If _IsPressed("11", $dll) And _IsPressed("78", $dll) Then GrabPrintScreenClipboard(True) ;Ctrl + F9 -> Alt+Printscreen
	If _IsPressed("2C", $dll) Then ;capture Printscreen key press
		GrabPrintScreenClipboard()
		While _IsPressed("2C", $dll)
			Sleep(250)
		WEnd
	EndIf
WEnd

Func _Exit()
	_AutoItObject_Shutdown()
	HotKeySet("^!{F9}")
	_ClipBoard_ChangeChain(HWnd($hGUI), $hNext)
	GUIRegisterMsg($WM_DRAWCLIPBOARD, "")
	GUIRegisterMsg($WM_COMMAND, "")
	GUIRegisterMsg($WM_CONTEXTMENU, "")
	GUIRegisterMsg($WM_NOTIFY, "")
	GUIRegisterMsg($WM_SYSCOMMAND, "")
	GUIRegisterMsg($WM_TIMER, "")
	GUIRegisterMsg($WM_HSCROLL, "")
	GUIRegisterMsg($WM_MOUSEWHEEL, "")
;~ 	DllCall($dll, "bool", "UnhookWindowsHookEx", "handle", $hM_Hook[0])
;~ 	$hM_Hook[0] = 0
;~ 	DllCallbackFree($hMouse_Proc)
;~ 	$hMouse_Proc = 0
	GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
	_GDIPlus_DeletePrivateFontCollection($hCollection_WM)
	_WinAPI_DestroyIcon($hMainGUI_Icon)
	_WinAPI_DeleteObject($hFont_IE_Color)
	_WinAPI_DeleteObject($hHBITMAP_Logo)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXBlur)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXBW)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXGray)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXInvert)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXPixelize)
	_WinAPI_DeleteObject($hBMP_ImageEdit_FXRasterize)
	_WinAPI_DeleteObject($hBMP_Quality)
	_WinAPI_DeleteObject($hBMP_Reset)
	_WinAPI_DeleteObject($hBMP_Reset2)
	_WinAPI_DeleteObject($hBMP_ImageEdit)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Gray)
	_WinAPI_DeleteObject($hBMP_ImageEdit_BW)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Invert)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Rotm90)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Rotp90)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Undo)
	_WinAPI_DeleteObject($hBMP_ImageEdit_Editor)
	_WinAPI_DeleteObject($hBMP_Watermark)
	_WinAPI_DeleteObject($hBMP_ChkUpd)
	_WinAPI_DeleteObject($hBMP_VisitWeb)
	_WinAPI_DeleteObject($hBMP_Print)
	_WinAPI_DeleteObject($hBMP_ImportClipboard)
	_WinAPI_DeleteObject($hBMP_About)
	_WinAPI_DeleteObject($hBMP_OpenMailClient)
	_WinAPI_DeleteObject($hBMP_Donate)
	_WinAPI_DeleteObject($hBMP_Donate2)
	_WinAPI_DeleteObject($hBMP_Exit)
	_WinAPI_DeleteObject($hBitmap_s)
	_WinAPI_DeleteObject($hBMP_Menu_GrabScreen_Redo)
	_WinAPI_DeleteObject($hBMP_Menu_JPG_Qual)
	_WinAPI_DeleteObject($hBMP_Button_Clipboard_Menu)
	_WinAPI_DeleteObject($hBMP_Menu_AviCompress)
	_WinAPI_DeleteObject($hBMP_Menu_AviFPS)
	_WinAPI_DeleteObject($hBMP_Menu_AviMouse)
	_WinAPI_DeleteObject($hBMP_Menu_AviRecTime)
	_WinAPI_DeleteObject($hBMP_Menu_AviTimeStamp)
	_WinAPI_DeleteObject($hBMP_Menu_WebWitdh)
	If @OSBuild < 6000 Then
		_WinAPI_DeleteObject($hImage_Btn_Exit)
		_WinAPI_DeleteObject($hImage_Btn_Save)
		_WinAPI_DeleteObject($hImage_Btn_Clipboard)
		_WinAPI_DeleteObject($hImage_Btn_Grab2AVI)
	EndIf
	For $i = 0 To UBound($aLanguages) - 1
		_WinAPI_DeleteObject($aLanguagesFlags[$i][0])
		_WinAPI_DeleteObject($aLanguagesFlags[$i][1])
	Next
	_WinAPI_DeleteDC($hMemDC)
	_WinAPI_DeleteObject($memBitmap)
	_WinAPI_ReleaseDC(0, $hDC_Region)
	_WinAPI_DeleteDC($hDC_Region)
	_GDIPlus_PenDispose($hPen_Border)
	_GDIPlus_MatrixDispose($hMatrix)
	_GDIPlus_BrushDispose($hBrush_Clear)
	_GDIPlus_GraphicsDispose($hImageContext)
	_GDIPlus_GraphicsDispose($hContext)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_BitmapDispose($hBackImage)
	_GDIPlus_BitmapDispose($undo)

	_GDIPlus_BitmapDispose($hBuffer_Bmp)
	_GDIPlus_BitmapDispose($hBmp)
	_GDIPlus_Shutdown()

	If $iStateAnim Then _WinAPI_SetGUIMinMaxAnim(1)
	GUIDelete(HWnd($hGUI))

	DllClose($dll)
	DllClose($g32_dll)
	DllClose($hDwmApiDll)

	Exit
EndFunc   ;==>_Exit

Func Change_Language($iLang)
	Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION, $MB_ICONQUESTION), $aTranslations[97][$iLang], $aTranslations[260][$iLang], 0, $hGUI)
	If $iRet = 6 Then
		IniWrite($sLangIni, "Language", "Lang", $iLang)
		If @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[261][$iLang], 0, $hGUI)
		IniWrite($sLangIni, "Settings", "Border", $bBorder)
		IniWrite($sLangIni, "Settings", "BorderColor", "0x" & Hex($iBorderColor, 8))
		IniWrite($sLangIni, "Settings", "ShadowSave", $bSave_Shadow)
		IniWrite($sLangIni, "Settings", "ShadowClipboard", $bClipboard_Shadow)
;~ 		IniWrite($sLangIni, "Settings", "Width", $width)
;~ 		IniWrite($sLangIni, "Settings", "Height", $height)
		IniWrite($sLangIni, "Settings", "ListMoreWindows", $bSearchForChildren)
		_ScriptRestart()
	EndIf
EndFunc   ;==>Change_Language

#Region Some parts for displaying preview GDI+ screen

Func Show_Lang_Menu()
	_GUICtrlMenu_TrackPopupMenu($hButton_Menu_Lang, $hGUI)
EndFunc

Func Call_Ruler()
	HotKeySet("^!{F9}")
	HotKeySet("^!{F12}")
	Ruler()
	HotKeySet("^!{F9}", "Grab_Screen")
	HotKeySet("^!{F12}", "Grab_Active_Window")
	WinActivate(HWnd($hGUI))
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")
EndFunc

Func Call_Undo()
	If $undo_chk Then
		Undo()
		Zoom(2)
		_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 2)
		$undo_chk = False
	EndIf
EndFunc

Func Numpad8_Scroll()
	$scroll_y += $scroll_speedy
	Draw2Graphic($hBmp)
	Zoom(2)
EndFunc   ;==>Numpad8_Scroll

Func Numpad2_Scroll()
	$scroll_y -= $scroll_speedy
	Draw2Graphic($hBmp)
	Zoom(2)
EndFunc   ;==>Numpad2_Scroll

Func Numpad4_Scroll()
	$scroll_x += $scroll_speedx
	Draw2Graphic($hBmp)
	Zoom(2)
EndFunc   ;==>Numpad4_Scroll

Func Numpad6_Scroll()
	$scroll_x -= $scroll_speedx
	Draw2Graphic($hBmp)
	Zoom(2)
EndFunc   ;==>Numpad6_Scroll

Func NumpadAdd_Scroll()
	Zoom(1)
EndFunc   ;==>NumpadAdd_Scroll

Func NumpadSub_Scroll()
	Zoom(0)
EndFunc   ;==>NumpadSub_Scroll

Func Redraw($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	_WinAPI_RedrawWindow(HWnd($hGUI), 0, 0, BitOR($RDW_UPDATENOW, $RDW_NOINTERNALPAINT))
	_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBuffer_Bmp, $gdip_x, $gdip_y, $gdip_w, $gdip_h)
	$NCPaint = True
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>Redraw

Func Redraw_XP($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	If $bRepaintXP Then
		_WinAPI_RedrawWindow(HWnd($hGUI), "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))
		Draw2Graphic($hBmp)
		Zoom(2)
		$NCPaint = True
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>Redraw_XP

Func Zoom($zoom_dir)
	Switch $zoom_dir
		Case -1
			_GDIPlus_MatrixDispose($hMatrix)
			$hMatrix = _GDIPlus_MatrixCreate()
			_GDIPlus_MatrixTranslate($hMatrix, $gdip_w / 2, $gdip_h / 2)
			_GDIPlus_MatrixScale($hMatrix, 1 / $f, 1 / $f)
			$scroll_x = 0
			$scroll_y = 0
		Case 0
			If $z > $zmin Then
				_GDIPlus_MatrixScale($hMatrix, 0.95, 0.95)
				$z -= 0.05
			EndIf
		Case 1
			If $z <= $zmax Then
				_GDIPlus_MatrixScale($hMatrix, 1.05, 1.05)
				$z += 0.05
			EndIf
		Case 2
			_GDIPlus_MatrixScale($hMatrix, 1, 1)
	EndSwitch
	_GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
	_GDIPlus_GraphicsClear($hContext, "0xFF" & $bg_c)
	_GDIPlus_GraphicsDrawImageRect($hContext, $hBmp, -$bW / 2 + $scroll_x, -$bH / 2 + $scroll_y, $bW, $bH)
	_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBuffer_Bmp, $gdip_x, $gdip_y, $gdip_w, $gdip_h)
EndFunc   ;==>Zoom

Func Draw2Graphic($hImage)
	AutoDisplaySettings()
	Local $w, $h
	_GDIPlus_GraphicsClear($hContext, "0xFF" & $bg_c)

	If $bW <= $gdip_w And $bH <= $gdip_h Then
		$f = 1
		_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, $gdip_w / 2 - $bW / 2 - $scroll_x, $gdip_h / 2 - $bH / 2 - $scroll_y, $bW, $bH)
	Else
		If $bW >= $bH Then
			$f = $bW / $gdip_w
		Else
			$f = $bH / $gdip_h
		EndIf

		$w = Floor($bW / $f)
		$h = Floor($bH / $f)
		If $w > $gdip_w Then
			$f = $bW / $gdip_w
		ElseIf $h > $gdip_h Then
			$f = $bH / $gdip_h
		EndIf
		_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, $gdip_w / 2 - $w / 2 - $scroll_x, $gdip_h / 2 - $h / 2 - $scroll_y, $w, $h)
	EndIf

	If BitAND(GUICtrlRead($Button_Menu_Item2), $GUI_CHECKED) = $GUI_CHECKED Then
		Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
		Local $tParams = _GDIPlus_ParamInit(1)
		Local $tData = DllStructCreate("int Quality")
		DllStructSetData($tData, "Quality", $JPEG_Quality)
		Local $pData = DllStructGetPtr($tData)
		_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
		Local $pParams = DllStructGetPtr($tParams)
		If Not FileExists(@ScriptDir & "\AutoSave") Then DirCreate(@ScriptDir & "\AutoSave\")
		If BitAND(GUICtrlRead($Button_Menu_Item3), $GUI_CHECKED) Then
			Local $hBmp_tmp = _GDIPlus_BitmapClone($hImage, $bW, $bH)
			Local $hBmp_AutoSave_Ts = _GDIPlus_WTOB($hBmp_tmp, _Now())
			_GDIPlus_ImageSaveToFileEx($hBmp_AutoSave_Ts, @ScriptDir & "\AutoSave\AutoSave_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & ".jpg", $sCLSID, $pParams)
			_GDIPlus_BitmapDispose($hBmp_AutoSave_Ts)
			_GDIPlus_BitmapDispose($hBmp_tmp)
		Else
			_GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\AutoSave\AutoSave_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & ".jpg", $sCLSID, $pParams)
		EndIf
	EndIf
EndFunc   ;==>Draw2Graphic

Func Undo()
	_GDIPlus_BitmapDispose($hBmp)
	$hBmp = _GDIPlus_BitmapClone($undo, _GDIPlus_ImageGetWidth($undo), _GDIPlus_ImageGetHeight($undo))
	Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
	_WinAPI_DeleteObject($hHBmp)
	$bW = _GDIPlus_ImageGetWidth($hBmp)
	$bH = _GDIPlus_ImageGetHeight($hBmp)
	$z = 10
	Draw2Graphic($hBmp)
	Zoom(-1)
	Update_Resolution_Info($hBmp)
EndFunc   ;==>Undo

Func JPG_Quality()
	GUIRegisterMsg($WM_COMMAND, "")
	HotKeySet("^!{F9}")
	AutoItSetOption("GUICloseOnESC", 1)
	AutoItSetOption("GUIOnEventMode", 0)
	AutoItSetOption("MouseCoordMode", 2)
	GUISetOnEvent($GUI_EVENT_CLOSE, "")
	Local $mp = MouseGetPos()
	$hGui_Slider = GUICreate($aTranslations[232][$iLang], 306, 150, $mp[0] - 153, $mp[1] - 100, $WS_SYSMENU, BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)
	GUISetBkColor(0x6060A0)
	$Slider = GUICtrlCreateSlider(10, 10, 280, 50, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_BOTH, $TBS_ENABLESELRANGE, $WS_TABSTOP))
	GUICtrlSetLimit($Slider, 100, 0)
	GUICtrlSetData($Slider, $JPEG_Quality)
	GUICtrlSetBkColor($Slider, 0xA0A0F0)
	$hSlider = GUICtrlGetHandle($Slider)
	$Slider_Label_Text = GUICtrlCreateLabel($aTranslations[233][$iLang], 10, 80, 85, 30)
	GUICtrlSetColor($Slider_Label_Text, 0xF0F0FF)
	GUICtrlSetFont($Slider_Label_Text, 18 * $aDPI[0])
	$Slider_Label_Value = GUICtrlCreateLabel($JPEG_Quality, 105, 80, 45, 30, $SS_CENTER)
	GUICtrlSetFont($Slider_Label_Value, 18 * $aDPI[0])
	Local $Slider_Button = GUICtrlCreateButton($aTranslations[173][$iLang], 225, 80, 60, 30)
	GUICtrlSetBkColor($Slider_Button, 0xF0F050)
	Slider_Label_Color($JPEG_Quality)
	GUISetState(@SW_SHOW, $hGui_Slider)
	GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
	Local $aRect = _GUICtrlSlider_GetThumbRect($hSlider) ;get slider button position
	MouseMove($aRect[2] + 4, $aRect[3], 10)
	While 1
		$_msg = GUIGetMsg()
		Switch $_msg
			Case $GUI_EVENT_CLOSE
				ExitLoop
			Case $Slider_Button
				$JPEG_Quality = _GUICtrlSlider_GetPos($hSlider)
				ExitLoop
		EndSwitch
	WEnd
	GUIDelete($hGui_Slider)
	GUIRegisterMsg($WM_HSCROLL, "")
	AutoItSetOption("GUIOnEventMode", 1)
	AutoItSetOption("GUICloseOnESC", 0)
	AutoItSetOption("MouseCoordMode", 1)
	GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
	HotKeySet("^!{F9}", "Grab_Screen")
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
EndFunc   ;==>JPG_Quality

Func _GDIPlus_BitmapClone($hBitmap, $bW, $bH)
	Local $hBitmap_new, $hCtx_Bitmap_new, $aResult
	$hBitmap_new = _GDIPlus_BitmapCreateFromScan0($bW, $bH)
	$hCtx_Bitmap_new = _GDIPlus_ImageGetGraphicsContext($hBitmap_new)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_Bitmap_new, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsDrawImageRect($hCtx_Bitmap_new, $hBitmap, 0, 0, $bW, $bH)
	_GDIPlus_GraphicsDispose($hCtx_Bitmap_new)
	Return $hBitmap_new
EndFunc   ;==>_GDIPlus_BitmapClone

Func FlipImage($iRotateFlipType)
	Local $iWidth = _GDIPlus_ImageGetWidth($hBmp)
	Local $iHeight = _GDIPlus_ImageGetHeight($hBmp)
	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $iWidth, $iHeight)
	If Not $undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 30, WinGetHandle(AutoItWinGetTitle()))
	$undo_chk = True
	_GDIPlus_ImageRotateFlip($hBmp, $iRotateFlipType)
	Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
	_WinAPI_DeleteObject($hHBmp)
	Local $tmp = $bW
	$bW = $bH
	$bH = $tmp
	Draw2Graphic($hBmp)
EndFunc   ;==>FlipImage

Func AutoDisplaySettings()
	If $bAuto Then
		If $bW > $gdip_w Or $bH > $gdip_h Then
			_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 2)
			_GDIPlus_GraphicsSetInterpolationMode($hContext, 7)
		Else
			_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 0)
			_GDIPlus_GraphicsSetInterpolationMode($hContext, 5)
		EndIf
;~ 		Zoom(2)
	EndIf
EndFunc   ;==>AutoDisplaySettings

Func LoadFileToGUI($sFileName)
	Local $hImage_File = _GDIPlus_ImageLoadFromFile($sFileName)
	If $hImage_File Then
		$undo_chk = False
		If $hBitmap_s Then _WinAPI_DeleteObject($hBitmap_s)
		$hBitmap_s = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage_File)
		_GDIPlus_ImageDispose($hBmp)
		$hBmp = _GDIPlus_BitmapCloneArea($hImage_File, 0, 0, _GDIPlus_ImageGetWidth($hImage_File), _GDIPlus_ImageGetHeight($hImage_File), $GDIP_PXF32ARGB)
		_GDIPlus_ImageDispose($hImage_File)
		Update_Resolution_Info($hBmp)
		If $bBorder Then
			$hGfx_border = _GDIPlus_ImageGetGraphicsContext($hBmp)
			_GDIPlus_GraphicsDrawRect($hGfx_border, $iBorderWidth - 1, $iBorderWidth - 1, _GDIPlus_ImageGetWidth($hBmp) - $iBorderWidth , _GDIPlus_ImageGetHeight($hBmp) - $iBorderWidth, $hPen_Border)
			_GDIPlus_GraphicsDispose($hGfx_border)
		EndIf
		Draw2Graphic($hBmp)
		_WinAPI_DeleteObject($hClipboard_Bitmap)
		$hClipboard_Bitmap = $hBitmap_s
		$z = 10
		Zoom(-1)
		If $image2clipboard Then
			$silent = True
			Pic2Clipboard()
			$silent = False
		EndIf
	EndIf
	WinActivate($hGUI)
EndFunc
#EndRegion Some parts for displaying preview GDI+ screen

#Region Grab2AVI
Func Grab2AVI()
	HotKeySet("^!{F9}")
	GUISetState(@SW_HIDE, $hGUI)
	Local Const $hGUI_AU3 = WinGetHandle(AutoItWinGetTitle())

	Local Const $hGUI_Cross_AVI = GUICreate("", 30, 30, 0, 0, $WS_POPUP, BitOR($WS_DISABLED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $hGUI_AU3)
	WinSetTrans($hGUI_Cross_AVI, "", 1)
	GUISetState(@SW_HIDE, $hGUI_Cross_AVI)

	Local Const $hGUI_Grab2AVI = GUICreate("", 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), $hGUI_AU3)
	GUISetBkColor(0xFF0000, $hGUI_Grab2AVI)
	GUISetState(@SW_SHOW, $hGUI_Grab2AVI)
	Local $aMPos, $hWin, $hWnd, $aRet_prev, $aPos, $q, $fps, $hBmp_AVI
	Local Const $frame_size = 3
	Local $tPoint = DllStructCreate($tagPOINT)
	Local $esc = True, $rem1 = 0, $rem2 = 0
	$aLastPos[0] = -1
	$aLastPos[1] = -1

	Local $m_startx, $m_starty

	Local Const $hGUI_AVI_Mark = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $hGUI_AU3)
	GUISetBkColor(0x0000B0)
	WinSetTrans($hGUI_AVI_Mark, "", 0x90)
	GUISetState(@SW_HIDE, $hGUI_AVI_Mark)
	Local $w, $h, $size = 1
	Local $label, $label_text = ""
	$label = GUICtrlCreateLabel($label_text, $size, $size, 0, 0)
	GUICtrlSetFont($label, 6 * $aDPI[0])
	GUICtrlSetBkColor($label, 0xFFFFC8)

	Local $iX1, $iY1

	While Not _IsPressed("1B", $dll) * Sleep(20) ;ESC
		If Not $rem1 Then
			GUISetState(@SW_HIDE, $hGUI_AVI_Mark)
			GUISetState(@SW_HIDE, $hGUI_Cross_AVI)
			GUISetState(@SW_SHOW, $hGUI_Grab2AVI)
			$rem1 = 1
			$rem2 = 0
			$aLastPos[0] = -1
			$aLastPos[1] = -1
			$w = 0
			$h = 0
		EndIf
		$aMPos = MouseGetPos()
		DllStructSetData($tPoint, 1, $aMPos[0])
		DllStructSetData($tPoint, 2, $aMPos[1])
		$hWin = _WinAPI_WindowFromPoint($tPoint)

;~ 		$hWinAncestor = _WinAPI_GetAncestor($hWin, 2)
;~ 		$hWnd = HWnd($hWinAncestor)
		$hWnd = HWnd($hWin)
		$aRet_prev = -1
		$aPos = WinGetPos($hWnd)
		If $hWnd <> $hGUI_Grab2AVI And $hWnd <> $aRet_prev And $hWnd <> $hGUI_Cross_AVI And $hWnd <> $hGUI_AVI_Mark Then
			$aRet_prev = $hWnd
			If $aMPos[0] <> $aLastPos[0] Or $aMPos[1] <> $aLastPos[1] Then
				If _WinAPI_GetClassName($hWin) <> "tooltips_class32" Then
					WinMove($hGUI_Grab2AVI, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3])
					_GuiHole($hGUI_Grab2AVI, $frame_size, $frame_size, $aPos[2] - 2 * $frame_size, $aPos[3] - 2 * $frame_size, $aPos[2], $aPos[3])
					WinSetOnTop($hGUI_Grab2AVI, 0, 1)
				EndIf
				ToolTip($aTranslations[18][$iLang] & $aPos[2] & " x " & $aPos[3], $aMPos[0] + 20, $aMPos[1] + 20)
				$aLastPos = $aMPos
			EndIf
		EndIf

		While _IsPressed("10", $dll) * Sleep(20) ;shift key
			If Not $rem2 Then
				GUISetState(@SW_HIDE, $hGUI_Grab2AVI)
				GUISetState(@SW_SHOW, $hGUI_AVI_Mark)
				GUISetState(@SW_SHOW, $hGUI_Cross_AVI)
				$rem2 = 1
				$rem1 = 0
				$aLastPos[0] = -1
				$aLastPos[1] = -1
			EndIf
			$aMPos = MouseGetPos()
			If $aMPos[0] <> $aLastPos[0] Or $aMPos[1] <> $aLastPos[1] Then
				ToolTip($aTranslations[19][$iLang])
				WinMove($hGUI_Cross_AVI, "", $aMPos[0] - 15, $aMPos[1] - 15, 30, 30)
				$aLastPos = $aMPos
			EndIf
			GUISetCursor(3, 1, $hGUI_Cross_AVI)
			$m_startx = $aMPos[0]
			$m_starty = $aMPos[1]
			While _IsPressed("01", $dll) * Sleep(10) ;LMB
				GUISetCursor(3, 1, $hGUI_Cross_AVI)
				$aMPos = MouseGetPos()
				If $aMPos[0] <> $aLastPos[0] Or $aMPos[1] <> $aLastPos[1] Then
					$w = Abs($aMPos[0] - $m_startx) + 1
					$h = Abs($aMPos[1] - $m_starty) + 1
					If $aMPos[0] < $m_startx Then
						$iX1 = $aMPos[0]
					Else
						$iX1 = $m_startx
					EndIf
					If $aMPos[1] < $m_starty Then
						$iY1 = $aMPos[1]
					Else
						$iY1 = $m_starty
					EndIf
					WinMove($hGUI_Cross_AVI, "", $aMPos[0] - 15, $aMPos[1] - 15, 30, 30)
					WinMove($hGUI_AVI_Mark, "", $iX1, $iY1, $w, $h)
					$aLastPos = $aMPos
					ToolTip($aTranslations[86][$iLang] & $w & "x" & $h & @CRLF & $aTranslations[87][$iLang] & $aMPos[0] & "," & $aMPos[1], $aMPos[0] + 10, $aMPos[1] + 10)
					GUICtrlSetPos($label, $size, $size, $w - $size * 2, $h - $size * 2)
				EndIf
			WEnd
			If $w > 1 And $h > 1 Then
				$esc = False
				$aPos = WinGetPos($hGUI_AVI_Mark)
				ExitLoop 2
			EndIf
		WEnd

		If _IsPressed("11", $dll) Then ;CTRL
			$esc = False
			ExitLoop
		EndIf
	WEnd
	ToolTip("")
	$tPoint = 0
	GUIDelete($hGUI_AVI_Mark)
	GUIDelete($hGUI_Grab2AVI)
	GUIDelete($hGUI_Cross_AVI)

	If Not $esc Then
		For $q = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
			If BitAND(GUICtrlRead($aButton_Menu_AVI_Sub1_Item[$q]), $GUI_CHECKED) = $GUI_CHECKED Then
				$rec_time = $AVI_ReqTime[$q]
				ExitLoop
			EndIf
		Next
		For $q = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
			If BitAND(GUICtrlRead($aButton_Menu_AVI_Sub2_Item[$q]), $GUI_CHECKED) = $GUI_CHECKED Then
				$fps = $AVI_FPS[$q]
				ExitLoop
			EndIf
		Next
	EndIf

	If $esc Then Return GUISetState(@SW_SHOW, $hGUI)
	Local $timestamp = @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & "_"
	Local $WinTitle = StringRegExpReplace(WinGetTitle(_WinAPI_GetAncestor($hWnd, $GA_ROOT)), '(\?|\*|\<|\>|\"|\:|\\|\/|\|)', "")

	Local $add_ts = False
	If BitAND(GUICtrlRead($mButton_Menu_AVI_Sub3_Item1), $GUI_CHECKED) = $GUI_CHECKED Then $add_ts = True
	If BitAND(GUICtrlRead($mButton_Menu_AVI_Sub4_Item2), $GUI_CHECKED) = $GUI_CHECKED Then
		$compress_avi = False
	Else
		$compress_avi = True
	EndIf
	_StartAviLibrary()
	Local Const $AVI_Filename = @ScriptDir & "\" & $timestamp & $WinTitle & ".avi"
	Local $AVI_File = _CreateAvi($AVI_Filename, $fps, $aPos[2], $aPos[3])
	If @error Then
		_CloseAvi($AVI_File)
		_StopAviLibrary()
		FileDelete($AVI_Filename)
		GUISetState(@SW_SHOW, $hGUI)
		Return MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $aTranslations[88][$iLang], 15, $hGUI)
	EndIf

	Local $hBitmap_AVI, $hBitmap_AVI_TS, $hBmp_AVI_TS, $OldBMP
	Local $iLeft, $iRight, $iTop, $iBottom
	Local $hIcon, $aIcon
	Local $tCursor, $tInfo, $iCursor, $aCursor[5], $aIcon[6]
	Local $total_FPS = $rec_time * $fps, $fps_c = 1
	Local $bInfinity = False
	If $rec_time = $aTranslations[66][$iLang] Then
		$bInfinity = True
		$total_FPS = 0xFFFFFF
	EndIf

	Local Const $fc = 1000 / $fps

	Local Const $k32_dll = DllOpen("kernel32.dll")
	Local Const $u32_dll = DllOpen("user32.dll")
	Local Const $DC = _WinAPI_GetDC(0)
	Local Const $hDC = _WinAPI_CreateCompatibleDC($DC)

	Local $bits = DllStructCreate("byte[" & DllStructGetData($AVI_File[3], "biSizeImage") & "]")
	Local Const $pBits = DllStructGetPtr($bits), $iLines = Abs(DllStructGetData($AVI_File[3], "biHeight"))
	Local Const $pHeader = DllStructGetPtr($AVI_File[3]), $iSize = DllStructGetSize($bits)

	$iLeft = $aPos[0]
	$iRight = $aPos[0] + $aPos[2]
	$iTop = $aPos[1]
	$iBottom = $aPos[1] + $aPos[3]
	If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
	If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)
	Local $iW = $aPos[2]
	Local $iH = $aPos[3]
	_WinAPI_DeleteObject($hBmp_AVI)
	$hBmp_AVI = _WinAPI_CreateCompatibleBitmap($DC, $iW, $iH)

	If BitAND(GUICtrlRead($mButton_Menu_AVI_Sub5_Item1), $GUI_CHECKED) = $GUI_CHECKED Then
		$cursor = True
	Else
		$cursor = False
	EndIf

	HotKeySet("{ESC}", "End_Avi_Cap")
	Local $t, $td
	$end_avi_cap = False
	Local $rec_timer = TimerInit()
	If $add_ts Then
		Do
			$t = TimerInit()
			$OldBMP = DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $hBmp_AVI) ;_WinAPI_SelectObject()
			DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "handle", $DC, "int", $iLeft, "int", $iTop, "dword", $iRTOP) ;_WinAPI_BitBlt()

			If $cursor Then
				$tCursor = DllStructCreate($tagCURSORINFO)
				DllStructSetData($tCursor, "Size", DllStructGetSize($tCursor))
				DllCall($u32_dll, "bool", "GetCursorInfo", "struct*", $tCursor)
				$aCursor[1] = DllStructGetData($tCursor, "Flags") <> 0
				$aCursor[2] = DllStructGetData($tCursor, "hCursor")
				$aCursor[3] = DllStructGetData($tCursor, "X")
				$aCursor[4] = DllStructGetData($tCursor, "Y")
				If $aCursor[1] Then
					$hIcon = DllCall($u32_dll, "handle", "CopyIcon", "handle", $aCursor[2])
					$tInfo = DllStructCreate($tagICONINFO)
					DllCall($u32_dll, "bool", "GetIconInfo", "handle", $hIcon[0], "struct*", $tInfo)
					$aIcon[2] = DllStructGetData($tInfo, "XHotSpot")
					$aIcon[3] = DllStructGetData($tInfo, "YHotSpot")
					$aIcon[4] = DllStructGetData($tInfo, "hMask")
					DllCall($g32_dll, "bool", "DeleteObject", "handle", $aIcon[4])
					DllCall($u32_dll, "bool", "DrawIcon", "handle", $hDC, "int", $aCursor[3] - $aIcon[2] - $iLeft, "int", $aCursor[4] - $aIcon[3] - $iTop, "handle", $hIcon[0])
					DllCall($u32_dll, "bool", "DestroyIcon", "handle", $hIcon[0])
				EndIf
			EndIf

			$hBitmap_AVI = DllCall($__g_hGDIPDll, "int", "GdipCreateBitmapFromHBITMAP", "handle", $hBmp_AVI, "handle", 0, "ptr*", 0) ;_GDIPlus_BitmapCreateFromHBITMAP()
			$hBitmap_AVI_TS = _GDIPlus_WTOB($hBitmap_AVI[3], _Now())
			$hBmp_AVI_TS = DllCall($__g_hGDIPDll, "int", "GdipCreateHBITMAPFromBitmap", "handle", $hBitmap_AVI_TS, "ptr*", 0, "dword", 0xFF000000) ;_GDIPlus_BitmapCreateHBITMAPFromBitmap()

			DllCall($g32_dll, "int", "GetDIBits", "handle", $hDC, "handle", $hBmp_AVI_TS[2], "uint", 0, "uint", $iLines, "ptr", $pBits, "ptr", $pHeader, "uint", 0) ;_WinAPI_GetDIBits()
			DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $OldBMP[0]) ;_WinAPI_SelectObject()
			DllCall($Avi32_Dll, "int", "AVIStreamWrite", "ptr", $AVI_File[1], "long", $AVI_File[2], "long", 1, "ptr", $pBits, "long", $iSize, "long", $AVIIF_KEYFRAME, "ptr*", 0, "ptr*", 0)
			$AVI_File[2] += 1

			DllCall($k32_dll, "none", "Sleep", "dword", $fc)

			DllCall($g32_dll, "bool", "DeleteObject", "handle", $hBmp_AVI_TS[2]) ;_WinAPI_DeleteObject()
			DllCall($__g_hGDIPDll, "int", "GdipDisposeImage", "handle", $hBitmap_AVI[3]) ;_GDIPlus_BitmapDispose()
			DllCall($__g_hGDIPDll, "int", "GdipDisposeImage", "handle", $hBitmap_AVI_TS) ;_GDIPlus_BitmapDispose()

			If Not $bInfinity Then
				$fps_c += 1
			EndIf

			$td = $fc - TimerDiff($t)
			If $td > 0 Then
				DllCall($k32_dll, "none", "Sleep", "dword", $td)
			EndIf

			If $fps_c > $total_FPS Or $end_avi_cap Then
				ExitLoop
			EndIf
		Until False
	Else
		Do
			$t = TimerInit()
			;_ScreenCapture_Capture() reduced
			$OldBMP = DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $hBmp_AVI) ;_WinAPI_SelectObject()
			DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "handle", $DC, "int", $iLeft, "int", $iTop, "dword", $iRTOP) ;_WinAPI_BitBlt()
			If $cursor Then
				$tCursor = DllStructCreate($tagCURSORINFO)
				DllStructSetData($tCursor, "Size", DllStructGetSize($tCursor))
				Local $aRet = DllCall($u32_dll, "bool", "GetCursorInfo", "struct*", $tCursor)
				$aCursor[1] = DllStructGetData($tCursor, "Flags") <> 0
				$aCursor[2] = DllStructGetData($tCursor, "hCursor")
				$aCursor[3] = DllStructGetData($tCursor, "X")
				$aCursor[4] = DllStructGetData($tCursor, "Y")
				If $aCursor[1] Then
					$hIcon = DllCall($u32_dll, "handle", "CopyIcon", "handle", $aCursor[2])
					$tInfo = DllStructCreate($tagICONINFO)
					DllCall($u32_dll, "bool", "GetIconInfo", "handle", $hIcon[0], "struct*", $tInfo)
					$aIcon[2] = DllStructGetData($tInfo, "XHotSpot")
					$aIcon[3] = DllStructGetData($tInfo, "YHotSpot")
					$aIcon[4] = DllStructGetData($tInfo, "hMask")
					DllCall($g32_dll, "bool", "DeleteObject", "handle", $aIcon[4])
					DllCall($u32_dll, "bool", "DrawIcon", "handle", $hDC, "int", $aCursor[3] - $aIcon[2] - $iLeft, "int", $aCursor[4] - $aIcon[3] - $iTop, "handle", $hIcon[0])
					DllCall($u32_dll, "bool", "DestroyIcon", "handle", $hIcon[0])
				EndIf
			EndIf
			DllCall($g32_dll, "int", "GetDIBits", "handle", $hDC, "handle", $hBmp_AVI, "uint", 0, "uint", $iLines, "ptr", $pBits, "ptr", $pHeader, "uint", 0) ;_WinAPI_GetDIBits()
			DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $OldBMP[0]) ;_WinAPI_SelectObject()

			DllCall($Avi32_Dll, "int", "AVIStreamWrite", "ptr", $AVI_File[1], "long", $AVI_File[2], "long", 1, "ptr", $pBits, "long", $iSize, "dword", $AVIIF_KEYFRAME, "ptr*", 0, "ptr*", 0)

			$AVI_File[2] += 1

			If Not $bInfinity Then
				$fps_c += 1
			EndIf

			$td = $fc - TimerDiff($t)
			If $td > 0 Then
				DllCall($k32_dll, "none", "Sleep", "dword", $td)
			EndIf

			If $fps_c > $total_FPS Or $end_avi_cap Then
				ExitLoop
			EndIf
		Until False
	EndIf
	Local $rec_dur = Round(TimerDiff($rec_timer) / 1000, 2)
	HotKeySet("{ESC}")
	_GDIPlus_BitmapDispose($hBmp)
	$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hBmp_AVI)
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = $hBmp_AVI
	$z = 10
	Zoom(-1)
	_WinAPI_SelectObject($DC, $OldBMP[0])
	_WinAPI_ReleaseDC(0, $DC)
	_WinAPI_DeleteDC($hDC)

	_CloseAvi($AVI_File)
	_StopAviLibrary()
	DllClose($k32_dll)
	DllClose($u32_dll)
	$bits = 0
	$tInfo = 0
	$tCursor = 0

	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
	MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], _
			$aTranslations[89][$iLang] & @LF & @LF & _
			$aTranslations[90][$iLang] & $AVI_Filename & @LF & _
			$aTranslations[91][$iLang] & Round(FileGetSize($AVI_Filename) / 1024 ^ 2, 2) & " MB" & @LF & _
			$aTranslations[92][$iLang] & $rec_time & $aTranslations[96][$iLang] & @LF & _
			$aTranslations[93][$iLang] & $fps & @LF & _
			$aTranslations[94][$iLang] & $aPos[2] & " x " & $aPos[3] & @LF & _
			$aTranslations[95][$iLang] & $rec_dur & $aTranslations[96][$iLang], 30, $hGUI)
	GUISetState(@SW_SHOW, $hGUI)

	Local $show_avi = MsgBox(BitOR($MB_YESNO, $MB_ICONWARNING, $MB_DEFBUTTON2, $MB_TOPMOST), $aTranslations[97][$iLang], $aTranslations[98][$iLang], 15, $hGUI)
	If $show_avi = 6 Then ShellExecute($AVI_Filename)
	HotKeySet("^!{F9}", "Grab_Screen")
EndFunc   ;==>Grab2AVI

Func End_Avi_Cap()
	$end_avi_cap = True
EndFunc   ;==>End_Avi_Cap
#EndRegion Grab2AVI

#Region Screen Grab
Func Mark_Area($disable_aero = False)
	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "")
	Else
		GUIRegisterMsg($WM_NCPAINT, "")
	EndIf
	GUIRegisterMsg($WM_COMMAND, "")
	GUIRegisterMsg($WM_CONTEXTMENU, "")

	GUIRegisterMsg($WM_NOTIFY, "")
	GUIRegisterMsg($WM_WINDOWPOSCHANGING, "")
	GUIRegisterMsg($WM_SYSCOMMAND, "")

	Local $hGUI_AU3 = HWnd(WinGetHandle(AutoItWinGetTitle()))
	Local Const $hDwmApiDll = DllOpen("dwmapi.dll")
	Local $tChkAero = DllStructCreate("int;")
	DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($tChkAero)) ;http://msdn.microsoft.com/en-us/library/aa969510%28VS.85%29.aspx
	Local $aero_on = DllStructGetData($tChkAero, 1)
	If $aero_on And $disable_aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", False)
	$tChkAero = 0

	Local $hGUI_MarkArea_BG = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], $WS_POPUP, Default, $hGUI_AU3)
	WinSetTrans(HWnd($hGUI_MarkArea_BG), "", 0x01)
;~ 	If @OSBuild > 9000 Or (Not $aero) Then GUISetState(@SW_SHOW, $hGUI_MarkArea_BG)
	GUISetState(@SW_SHOW, $hGUI_MarkArea_BG)

	Local $mpos = MouseGetPos(), $iCrosshair_size = 1, $aM_Mask, $aMask

	$hGUI_Cross = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), $hGUI_AU3)
;~ 	GUISetBkColor(0xFF0000, $hGUI_Cross)

	$aM_Mask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
	$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $mpos[0] + $aFullScreen[0] * -1 + 1 - $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
	DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
	$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", 0, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $mpos[1] + $aFullScreen[1] * -1 + 1 - $iCrosshair_size)
	DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
	$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1 + $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $aFullScreen[2], "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
	DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
	$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", $mpos[1] + $aFullScreen[1] * -1 + $iCrosshair_size, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $aFullScreen[3])
	DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
	DllCall($dll, "long", "SetWindowRgn", "hwnd", $hGUI_Cross, "long", $aM_Mask[0], "int", 1)

	GUISetCursor(2, 1, $hGUI_MarkArea_BG)
	GUISetCursor(2, 1, $hGUI_Cross)

	Local $zl
	$hGUI_Zoom = GUICreate("", $zw, $zh + 20, $zx, $zx, BitOR($WS_POPUP, $DS_MODALFRAME), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE, $WS_EX_TOOLWINDOW), $hGUI_AU3)
	$iLabelZoom_iColor = GUICtrlCreateLabel($aTranslations[100][$iLang], 0, $zh + 3, $zw, 16)
	GUICtrlSetBkColor(-1, 0)
	GUICtrlSetColor(-1, 0xFFFFFF)
	GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial", 5)
	GUISetState(@SW_SHOW, $hGUI_Zoom)


	$hDC_Zoom = _WinAPI_GetDC(0)
	$hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Zoom)
	$zx = 0
	$zy = 0
	$up = 1

	Local $esc = False, $freehand = False, $area = False
	Local Const $dist_x = 24, $dist_y = 24

	Local $aRet, $aRet_prev, $ctrl_handle, $ctrl_id, $Style, $v
	Local $hGUI_MarkCtrl = GUICreate("", 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), $hGUI_AU3)
	GUISetBkColor(0xFF0000, $hGUI_MarkCtrl)

	Local Const $frame_size = 3
	$hGUI_Freehand = GUICreate("", 1, 1, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), $hGUI_AU3)
	GUISetBkColor(0xABCDEF, $hGUI_Freehand)
	_WinAPI_SetLayeredWindowAttributes($hGUI_Freehand, 0xABCDEF, 0xFF)
	WinMove($hGUI_Freehand, "", $aFullScreen[0], $aFullScreen[1], $aFullScreen[2], $aFullScreen[3])

	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")

	;create Capture x seconds GUI but hide it
	Local $hGUI_CaptureXSec = GUICreate($aTranslations[106][$iLang], 362, 230, -1, -1, Default, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE), $hGUI_MarkArea_BG)
	GUISetFont(12 * $aDPI[0], 400, 0, "Times New Roman")
	GUISetBkColor(0xB9D1EA)
	Local $iLabelCapture_XSec1 = GUICtrlCreateLabel($aTranslations[107][$iLang], 0, 10, 178, 30, $SS_RIGHT)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	Local $iInputCapture_XSec = GUICtrlCreateInput($iXMSeconds, 184, 8, 41, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
	GUICtrlSetLimit(-1, 6, 3)
	Local $iLabelCapture_XSec2 = GUICtrlCreateLabel($aTranslations[273][$iLang], 232, 10, 123, 23)
	Local $iButtonCapture_Start = GUICtrlCreateButton($aTranslations[109][$iLang], 296, 73, 59, 25)
	Local $iButtonCapture_Cancel = GUICtrlCreateButton($aTranslations[110][$iLang], 296, 40, 59, 25)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	Local $iLabel_CaptureXDur = GUICtrlCreateLabel($aTranslations[111][$iLang], 0, 40, 180, 23, $SS_RIGHT)
	Local $iInputCapture_Duration = GUICtrlCreateInput($iXSeconds_Duration, 184, 38, 41, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
	GUICtrlSetLimit(-1, 3, 1)
	Local $iLabelCapture_Seconds1 = GUICtrlCreateLabel($aTranslations[108][$iLang], 232, 40, 53, 23)
	Local $iLabelCapture_Filename = GUICtrlCreateLabel($aTranslations[90][$iLang], 4, 74, 71, 23, $SS_RIGHT)
	GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
	Local $iInputCapture_Filename = GUICtrlCreateInput("[AppDir]\Captured\[YYYY-MM-DD_HMS]_captured.[Ext]", 72, 72, 217, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY, $ES_AUTOVSCROLL))
	Local $iRadioCapture_JPG = GUICtrlCreateRadio("JPG", 100, 120, 58, 17)
	Local $iLabelCapture_Format = GUICtrlCreateLabel($aTranslations[112][$iLang], 8, 118, 86, 17)
	GUICtrlSetTip(-1, $aTranslations[113][$iLang])
	Local $iRadioCapture_PNG = GUICtrlCreateRadio("PNG", 160, 120, 58, 17)
	Local $iRadioCapture_BMP = GUICtrlCreateRadio("BMP", 220, 120, 58, 17)
	Local $iRadioCapture_GIF = GUICtrlCreateRadio("GIF", 280, 120, 58, 17)

	Local $iGroup = GUICtrlCreateGroup($aTranslations[276][$iLang], 2, 150, 358, 75)

	GUICtrlSetFont(-1, 7 * $aDPI[0], 400, 0, "Times New Roman")
	Local $iCheckbox_GIF = GUICtrlCreateCheckbox($aTranslations[271][$iLang], 8, 180, 180, 20)
	GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[272][$iLang])
	Local $iCheckbox_Dither = GUICtrlCreateCheckbox($aTranslations[274][$iLang], 240, 180, 116, 20)
	GUICtrlSetState(-1, $GUI_CHECKED)
	GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[272][$iLang])
	GUISetState(@SW_HIDE, $hGUI_CaptureXSec)

	Local $ws, $tdiff = TimerInit()
	Do
		If _IsPressed("11", $dll) Then ;control capturing
			ToolTip("")
			GUISetState(@SW_HIDE, $hGUI_MarkArea_BG)
			GUISetState(@SW_HIDE, $hGUI_MarkArea)
			GUISetState(@SW_HIDE, $hGUI_Zoom)
			GUISetState(@SW_HIDE, $hGUI_Cross)
			GUISetState(@SW_SHOW, $hGUI_MarkCtrl)
			$mpos = MouseGetPos()
			$aRet = DllCall($dll, "int", "WindowFromPoint", "long", $mpos[0], "long", $mpos[1])
			$aPos_SC = WinGetPos(HWnd($aRet[0]))
			If $aRet[0] <> $hGUI_MarkCtrl And $aRet[0] <> 0 And $aRet[0] <> $aRet_prev Then
				$aRet_prev = $aRet[0]
				$ws = BitAND($WIN_STATE_MAXIMIZED, WinGetState(HWnd($aRet[0]), ""))
				If $ws = $WIN_STATE_MAXIMIZED Then
					$aPos_SC[0] += 8
					$aPos_SC[1] += 8
					$aPos_SC[2] -= 16
					$aPos_SC[3] -= 16
				EndIf
				WinMove($hGUI_MarkCtrl, "", $aPos_SC[0], $aPos_SC[1], $aPos_SC[2], $aPos_SC[3])
				_GuiHole($hGUI_MarkCtrl, $frame_size, $frame_size, $aPos_SC[2] - 2 * $frame_size, $aPos_SC[3] - 2 * $frame_size, $aPos_SC[2], $aPos_SC[3])
				WinSetOnTop($hGUI_MarkCtrl, 0, 1)
			EndIf
			$area = True
			If _IsPressed("10", $dll) Then ;shift
				GUISetState(@SW_HIDE, $hGUI_MarkCtrl)
				ExitLoop ;shift to make the screenshot
			EndIf
			If _IsPressed("02", $dll) And TimerDiff($tdiff) > 500 Then ;rmb to send lmb click to activate a GUI menu which can be capture afterwards
				If _IsPressed("12", $dll) Then ;if additionally alt key is pressed then lmb click will be sent
					While _IsPressed("12", $dll)
						Sleep(10)
					WEnd
					MouseClick("left")
				EndIf
				$tdiff = TimerInit()
			EndIf
		ElseIf _IsPressed("10", $dll) Then ;freehand screen capturing with shift key
			$zl = $zoom_level
			ToolTip("")
			$area = False
			$freehand = True
			$esc = True
			GUISetState(@SW_HIDE, $hGUI_Cross)
			GUISetState(@SW_HIDE, $hGUI_Zoom)
			GUISetState(@SW_HIDE, $hGUI_MarkCtrl)
			GUISetState(@SW_HIDE, $hGUI_MarkArea)

			Local $hHBITMAP_Freehand = __ScreenCapture_Capture($aFullScreen[0], $aFullScreen[1], $aFullScreen[2], $aFullScreen[3])
			$hBmp_Freehand = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP_Freehand)
			_WinAPI_DeleteObject($hHBITMAP_Freehand)

			GUISetState(@SW_SHOW, $hGUI_MarkArea_BG)
			GUISetState(@SW_SHOW, $hGUI_Freehand)
			GUISetState(@SW_SHOW, $hGUI_Zoom)


			$hGraphic_Freehand = _GDIPlus_GraphicsCreateFromHWND($hGUI_Freehand)
			_GDIPlus_GraphicsSetPixelOffsetMode($hGraphic_Freehand, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
			_GDIPlus_GraphicsSetSmoothingMode($hGraphic_Freehand, 0)
			Local $hPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

			Local $min_x = $aFullScreen[2]
			Local $min_y = $aFullScreen[3]
			Local $max_x = $aFullScreen[0]
			Local $max_y = $aFullScreen[1]
			Local $aPoints[10000][2], $mxo, $myo, $mx, $my
			Local $p = 1, $hide = False
			Local $mo = MouseGetCursor()

			$zoom_level = 4
			If Not $aero Then WinSetTrans($hGUI_Freehand, "", 0x50)
			GUISetCursor(14, 1, $hGUI_MarkArea_BG)
			GUISetCursor(14, 1, $hGUI_Freehand)
			$mpos = MouseGetPos()
			$mxo = $mpos[0] + Abs($aFullScreen[0]) + 1
			$myo = $mpos[1] + Abs($aFullScreen[1])
			Do
				Draw_Zoom_Preview($mpos[0], $mpos[1])
				$mpos = MouseGetPos()
				If $mpos[0] + Abs($aFullScreen[0]) <> $mxo Or $mpos[1] + Abs($aFullScreen[1]) <> $myo Then
					ToolTip($aTranslations[269][$iLang] & @LF & $aTranslations[270][$iLang], $mxo + 35, $myo + 35 + $aFullScreen[1])
				EndIf
				$mxo = $mpos[0] + Abs($aFullScreen[0])
				$myo = $mpos[1] + Abs($aFullScreen[1])
				While _IsPressed("01", $dll) * Sleep(10)
					$mpos = MouseGetPos()
					$mx = $mpos[0] + Abs($aFullScreen[0])
					$my = $mpos[1] + Abs($aFullScreen[1])
					If $mx <> $mxo Or $my <> $myo Then ToolTip($aTranslations[269][$iLang] & @LF & $aTranslations[270][$iLang], $mx + 35, $my + 35 + $aFullScreen[1])
					If Not $hide Then
						GUISetState(@SW_HIDE, $hGUI_Cross)
						DllCall($dll, "bool", "BringWindowToTop", "hwnd", HWnd($hGUI_Zoom))
						$hide = True
					EndIf
					_GDIPlus_GraphicsDrawLine($hGraphic_Freehand, $mx, $my, $mxo, $myo, $hPen)
					$mxo = $mx
					$myo = $my
					If $aPoints[$p - 1][0] <> $mx And $aPoints[$p - 1][1] <> $my Then
						$aPoints[$p][0] = $mx
						$aPoints[$p][1] = $my
						$p += 1
					EndIf
					$min_x = Min($min_x, $mx) - 1
					$min_y = Min($min_y, $my) - 1
					$max_x = Max($max_x, $mx)
					$max_y = Max($max_y, $my)
					If $p = UBound($aPoints) Then ExitLoop
					Draw_Zoom_Preview($mpos[0], $mpos[1])
				WEnd
				If _IsPressed("1B", $dll) Then ;ESC key
					$p = 1
					ExitLoop
				EndIf
			Until _IsPressed("10", $dll) * Sleep(10) ;shift key
			ReDim $aPoints[$p][2]
			$aPoints[0][0] = $p - 1
			GUISetCursor($mo, 1, $hGUI_MarkArea_BG)
			_GDIPlus_GraphicsDispose($hGraphic_Freehand)
			_GDIPlus_PenDispose($hPen)
			GUISetState(@SW_HIDE, $hGUI_MarkArea_BG)
			GUISetState(@SW_HIDE, $hGUI_Freehand)
			GUISetState(@SW_HIDE, $hGUI_Zoom)
			GUISetState(@SW_HIDE, $hGUI_Cross)
			If $aPoints[0][0] > 2 Then
				Local Const $hTextureBrush = _GDIPlus_TextureCreate($hBmp_Freehand)
				Local Const $hBitmap_Hidden = _GDIPlus_BitmapCreateFromScan0($aFullScreen[2], $aFullScreen[3])
				Local $hContext_Freehand = _GDIPlus_ImageGetGraphicsContext($hBitmap_Hidden)
				_GDIPlus_GraphicsSetPixelOffsetMode($hContext_Freehand, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
				_GDIPlus_GraphicsSetSmoothingMode($hContext_Freehand, 4)
;~ 				_GDIPlus_GraphicsClear($hContext_Freehand, 0xFFFFFFFF)
				Local Const $hPath_Freehand = _GDIPlus_PathCreate()
				_GDIPlus_PathAddClosedCurve($hPath_Freehand, $aPoints)
				_GDIPlus_GraphicsFillPath($hContext_Freehand, $hPath_Freehand, $hTextureBrush)
				If $bBorder Then _GDIPlus_GraphicsDrawPath($hContext_Freehand, $hPath_Freehand, $hPen_Border)
				Local $aWBounds = _GDIPlus_PathGetWorldBounds($hPath_Freehand)
				$aWBounds[0] = $aWBounds[0] < 0 ? 0 : $aWBounds[0]
				$aWBounds[1] = $aWBounds[1] < 0 ? 0 : $aWBounds[1]
				$aWBounds[2] = $aWBounds[2] + $aWBounds[0] > $aFullScreen[2] ? ($aFullScreen[2] - $aWBounds[0]) - 1 : $aWBounds[2]
				$aWBounds[3] = $aWBounds[3] + $aWBounds[1] > $aFullScreen[3] ? ($aFullScreen[3] - $aWBounds[1]) - 1 : $aWBounds[3]
				_GDIPlus_BitmapDispose($hBmp)
				$hBmp = _GDIPlus_BitmapCloneArea($hBitmap_Hidden, $aWBounds[0], $aWBounds[1], $aWBounds[2], $aWBounds[3], $GDIP_PXF32ARGB)
				_GDIPlus_GraphicsDispose($hContext_Freehand)
				_GDIPlus_BitmapDispose($hBmp_Freehand)
				_GDIPlus_BitmapDispose($hBitmap_Hidden)
				_GDIPlus_BrushDispose($hTextureBrush)
				_GDIPlus_PathDispose($hPath_Freehand)
				Update_Resolution_Info($hBmp)
				Draw2Graphic($hBmp)
				$z = 10
				Zoom(-1)
				sndPlaySound($BytePtr, $fuSound)
				$aPoints = 0
				$zoom_level = $zl
				If $image2clipboard Then
					$silent = True
					Pic2Clipboard()
					$silent = False
				EndIf
				ExitLoop
			EndIf
			$zoom_level = $zl
			_GDIPlus_BitmapDispose($hBmp_Freehand)
		Else
			$area = False
			$freehand = False
			If _WinAPI_IsWindowVisible($hGUI_MarkCtrl) Then
				GUISetState(@SW_HIDE, $hGUI_MarkCtrl)
			ElseIf Not _WinAPI_IsWindowVisible($hGUI_Cross) Then
				GUISetState(@SW_SHOW, $hGUI_Cross)
			ElseIf Not _WinAPI_IsWindowVisible($hGUI_Zoom) Then
				GUISetState(@SW_SHOW, $hGUI_Zoom)
			EndIf
			$red = Hex(Int(0xFF * (Cos($v * 1.10) + 1) / 2), 2)
			$green = Hex(Int(0xFF * (Sin($v * 1.00) + 1) / 2), 2)
			$blue = Hex(Int(0xFF * (Sin($v * 1.20) + 1) / 2), 2)
			GUISetBkColor("0x" & $red & $green & $blue, $hGUI_Cross)
			$v += $fade_speed
			$mpos = MouseGetPos()
			If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then

				$aM_Mask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
				$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $mpos[0] + $aFullScreen[0] * -1 + 1 - $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
				DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
				$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", 0, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $mpos[1] + $aFullScreen[1] * -1 + 1 - $iCrosshair_size)
				DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
				$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1 + $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $aFullScreen[2], "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
				DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
				$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", $mpos[1] + $aFullScreen[1] * -1 + $iCrosshair_size, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $aFullScreen[3])
				DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
				DllCall($dll, "long", "SetWindowRgn", "hwnd", $hGUI_Cross, "long", $aM_Mask[0], "int", 1)

				$aLastPos = $mpos

				$pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)

				ToolTip($aTranslations[99][$iLang] & @CRLF & @CRLF & _
						$aTranslations[87][$iLang] & $mpos[0] & "," & $mpos[1], $drx + $mpos[0] + $dirx * ($dist_x + $zoomW / 3), $dry + $mpos[1] + $diry * ($dist_y + $zoomH / 3))

				$right_border = Pixel_Distance($mpos[0], $mpos[1], @DesktopWidth, $mpos[1])
				If $right_border < $radius Then
					$dirx = -1
					$drx = -$radius
				Else
					$dirx = 1
					$drx = 0
				EndIf
				$lower_border = Pixel_Distance($mpos[0], $mpos[1], $mpos[0], @DesktopHeight)
				If $lower_border < $radius Then
					$diry = -1
					$dry = -$radius
				Else
					$diry = 1
					$dry = 0
				EndIf
			EndIf
			Draw_Zoom_Preview($mpos[0], $mpos[1])
			If _IsPressed("1B", $dll) Then ;ESC to exit
				$esc = True
				ExitLoop
			EndIf
			If _IsPressed("02", $dll) Then ;copy pixel color to clipboard
				ToolTip("")
				GUISetState(@SW_HIDE, $hGUI_Zoom)
				GUISetState(@SW_HIDE, $hGUI_Cross)
				If _ClipBoard_SetData($pixel_color) Then
					MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $aTranslations[101][$iLang] & $pixel_color & $aTranslations[102][$iLang], 30, $hGUI)
				Else
					MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[103][$iLang], 30, $hGUI)
				EndIf
				GUISetState(@SW_SHOW, $hGUI_Zoom)
				GUISetState(@SW_SHOW, $hGUI_Cross)
			EndIf
		EndIf
	Until _IsPressed("01", $dll) * Sleep(10)
	ToolTip("")

	GUIDelete($hGUI_MarkCtrl)
	GUIDelete($hGUI_Freehand)

	If Not $esc Then
		If $area Then
			GUIDelete($hGUI_Cross)
			GUIDelete($hGUI_MarkArea)
			GUIDelete($hGUI_MarkArea_BG)
			GUISetState(@SW_HIDE, $hGUI_Zoom)
			$Grab_x = $aPos_SC[0]
			$Grab_y = $aPos_SC[1]
			$Grab_w = $aPos_SC[2]
			$Grab_h = $aPos_SC[3]
			Sleep(75)
			Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h)
		ElseIf Not $freehand Then
;~ 			If (@OSBuild < 6000) Or (Not $aero) Then GUISetState(@SW_HIDE, $hGUI_MarkArea_BG) ;otherwise cursor will go crazy
			GUISetState(@SW_HIDE, $hGUI_MarkArea_BG) ;otherwise cursor will go crazy
			$mpos = MouseGetPos()
			Local $m_startx = $mpos[0]
			Local $m_starty = $mpos[1]

			$hGUI_MarkArea = GUICreate("", 0, 0, $m_startx, $m_starty, BitOR(0, $WS_POPUP), $WS_EX_TOPMOST, $hGUI_AU3)
			GUISetBkColor(0x0000A0, $hGUI_MarkArea)
			$hGUI_MarkArea_Child = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, $WS_EX_MDICHILD, $hGUI_MarkArea)
			GUISetBkColor(0xD0D0FF, $hGUI_MarkArea_Child)

			WinSetTrans($hGUI_MarkArea, "", 0x80)
			WinSetTrans($hGUI_MarkArea_Child, "", 0x50)

			GUISetState(@SW_SHOW, $hGUI_MarkArea_Child)
			GUISetState(@SW_SHOW, $hGUI_MarkArea)

			GUISetState(@SW_SHOW, $hGUI_Cross)
			Local $iX1, $iY1, $aGUI_pos
			$selected = False
			GUISetCursor(9, 0, $hGUI_MarkArea_Child)

			GUIRegisterMsg($WM_MOUSEMOVE, "SetCursor")
			GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")

			ToolTip("")

			$w_area = 0
			$h_area = 0
			AutoItSetOption("GUIOnEventMode", 0)
			Do
				If Not WinActive($hGUI_MarkArea) Then
					WinActivate($hGUI_MarkArea)
				EndIf
				$red = Hex(Int(0xFF * (Cos($v * 1.10) + 1) / 2), 2)
				$green = Hex(Int(0xFF * (Sin($v * 1.00) + 1) / 2), 2)
				$blue = Hex(Int(0xFF * (Sin($v * 1.20) + 1) / 2), 2)
				GUISetBkColor("0x" & $red & $green & $blue, $hGUI_Cross)
				$v += $fade_speed
				$mpos = MouseGetPos()
				If $mpos[0] <> $aLastPos[0] Or $mpos[1] <> $aLastPos[1] Then
					$pixel_color = Hex(PixelGetColor($mpos[0], $mpos[1]), 6)
					$aM_Mask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
					$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", 0, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $mpos[0] + $aFullScreen[0] * -1 + 1 - $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
					DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
					$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", 0, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $mpos[1] + $aFullScreen[1] * -1 + 1 - $iCrosshair_size)
					DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
					$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1 + $iCrosshair_size, "long", $mpos[1] + $aFullScreen[1] * -1, "long", $aFullScreen[2], "long", $mpos[1] + $aFullScreen[1] * -1 + 1)
					DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
					$aMask = DllCall($g32_dll, "long", "CreateRectRgn", "long", $mpos[0] + $aFullScreen[0] * -1, "long", $mpos[1] + $aFullScreen[1] * -1 + $iCrosshair_size, "long", $mpos[0] + $aFullScreen[0] * -1 + 1, "long", $aFullScreen[3])
					DllCall($g32_dll, "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
					DllCall($dll, "long", "SetWindowRgn", "hwnd", $hGUI_Cross, "long", $aM_Mask[0], "int", 1)
					If Not $selected Then
						$w_area = Abs($mpos[0] - $m_startx) + 1
						$h_area = Abs($mpos[1] - $m_starty) + 1
					EndIf
					If $mpos[0] < $m_startx Then
						$iX1 = $mpos[0]
					Else
						$iX1 = $m_startx
					EndIf
					If $mpos[1] < $m_starty Then
						$iY1 = $mpos[1]
					Else
						$iY1 = $m_starty
					EndIf

					$right_border = Pixel_Distance($mpos[0], $mpos[1], @DesktopWidth, $mpos[1])
					If $right_border < $radius Then
						$drx = -$radius
					Else
						$drx = $radius / 4
					EndIf
					$lower_border = Pixel_Distance($mpos[0], $mpos[1], $mpos[0], @DesktopHeight)
					If $lower_border < $radius Then
						$dry = -$radius
					Else
						$dry = $radius / 4
					EndIf

					If Not $selected Then
						WinMove($hGUI_MarkArea, "", $iX1, $iY1, $w_area, $h_area)
						$aGUI_pos = WinGetPos($hGUI_MarkArea)
						_GuiHole($hGUI_MarkArea, $margin, $margin, $w_area - 2 * $margin, $h_area - 2 * $margin, $w_area, $h_area)
						WinMove($hGUI_MarkArea_Child, "", $aGUI_pos[0] + $margin, $aGUI_pos[1] + $margin, $aGUI_pos[2] - 2 * $margin, $aGUI_pos[3] - 2 * $margin)
					EndIf
					$aLastPos = $mpos
					ToolTip($aTranslations[86][$iLang] & $w_area & "x" & $h_area & @CRLF & $aTranslations[87][$iLang] & $mpos[0] & "," & $mpos[1] & @LF & $aTranslations[104][$iLang] & @LF & $aTranslations[105][$iLang], $drx + $mpos[0], $dry + $mpos[1])
				EndIf
				Draw_Zoom_Preview($mpos[0], $mpos[1])
				If Not _IsPressed("01", $dll) Then ;LMB was released
					If $w_area > 0 And $h_area > 0 Then
						$selected = True
						GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINMOVE")
						GUIRegisterMsg($WM_SIZE, "WM_SIZE")
						GUIDelete($hGUI_Cross)
					EndIf
				ElseIf _IsPressed("01", $dll) Then
					ToolTip($aTranslations[86][$iLang] & $w_area & "x" & $h_area & @CRLF & $aTranslations[87][$iLang] & MouseGetPos(0) & "," & MouseGetPos(1) & @LF & $aTranslations[104][$iLang] & @LF & $aTranslations[105][$iLang], $drx + MouseGetPos(0), $dry + MouseGetPos(1))
				EndIf
				If _IsPressed("1B", $dll) Then ;ESC was pressed
					$esc = True
					ExitLoop
				EndIf
				If _IsPressed("02", $dll) Then
					ToolTip("")
					GUIRegisterMsg($WM_WINDOWPOSCHANGING, "")
					GUIRegisterMsg($WM_SIZE, "")
					AutoItSetOption("GUICloseOnESC", 1)
					If @OSBuild < 6000 Then
						GUICtrlSetState($iCheckbox_GIF, $GUI_DISABLE)
						GUICtrlSetState($iCheckbox_Dither, $GUI_DISABLE)
					EndIf
					GUICtrlCreateGroup("", -99, -99, 1, 1)
					Switch $sCapture_FilenameExt
						Case "bmp"
							GUICtrlSetState($iRadioCapture_BMP, $GUI_CHECKED)
						Case "gif"
							GUICtrlSetState($iRadioCapture_GIF, $GUI_CHECKED)
						Case "jpg"
							GUICtrlSetState($iRadioCapture_JPG, $GUI_CHECKED)
						Case "png"
							GUICtrlSetState($iRadioCapture_PNG, $GUI_CHECKED)
					EndSwitch
					ControlFocus($hGUI_CaptureXSec, "", $iButtonCapture_Start)

					GUISetState(@SW_SHOW, $hGUI_CaptureXSec)
					$bGIFAnim = False
					$iDither = $GDIP_DitherTypeSolid
					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE, $iButtonCapture_Cancel
								GUISetState(@SW_HIDE, $hGUI_CaptureXSec)
								$bCaptureXSeconds = False
								AutoItSetOption("GUICloseOnESC", 0)
								GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINMOVE")
								GUIRegisterMsg($WM_SIZE, "WM_SIZE")
								ExitLoop
							Case $iButtonCapture_Start
								If BitAND(GUICtrlRead($iRadioCapture_BMP), $GUI_CHECKED) Then
									$sCapture_FilenameExt = "bmp"
								ElseIf BitAND(GUICtrlRead($iRadioCapture_GIF), $GUI_CHECKED) Then
									$sCapture_FilenameExt = "gif"
								ElseIf BitAND(GUICtrlRead($iRadioCapture_JPG), $GUI_CHECKED) Then
									$sCapture_FilenameExt = "jpg"
								ElseIf BitAND(GUICtrlRead($iRadioCapture_PNG), $GUI_CHECKED) Then
									$sCapture_FilenameExt = "png"
								EndIf
								$iXMSeconds = GUICtrlRead($iInputCapture_XSec)
								$iXMSeconds = $iXMSeconds < 50 ? 50 : ($iXMSeconds / 1000) > $iInputCapture_Duration ? $iInputCapture_Duration * 1000 : $iXMSeconds  ;minimim 50ms / max $iInputCapture_Duration
								$iXSeconds_Duration = GUICtrlRead($iInputCapture_Duration)
								$iXSeconds_Duration = ($iXSeconds_Duration = "") ? 30 : $iXSeconds_Duration
								$bGIFAnim = BitAND(GUICtrlRead($iCheckbox_GIF), $GUI_CHECKED)
								If BitAND(GUICtrlRead($iCheckbox_Dither), $GUI_CHECKED) Then $iDither = $GDIP_DitherTypeDualSpiral8x8
								GUIDelete($hGUI_CaptureXSec)
								GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINMOVE")
								GUIRegisterMsg($WM_SIZE, "WM_SIZE")
								$bCaptureXSeconds = True
								ExitLoop 2
						EndSwitch
					WEnd
				EndIf
			Until (_IsPressed("11", $dll) Or _IsPressed("04", $dll)) ;* Sleep(10) ;ctrl key or middle mouse click
			GUIRegisterMsg($WM_WINDOWPOSCHANGING, "")
			GUIRegisterMsg($WM_SIZE, "")
			GUIRegisterMsg($WM_LBUTTONDOWN, "")
			GUIRegisterMsg($WM_MOUSEMOVE, "")
			Local $Win_Coord = WinGetPos($hGUI_MarkArea)
			GUISetState(@SW_HIDE, $hGUI_Zoom)
			GUIDelete($hGUI_MarkArea_Child)
			GUIDelete($hGUI_MarkArea)
			GUIDelete($hGUI_MarkArea_BG)
			GUIDelete($hGUI_CaptureXSec)
			ToolTip("")
			Sleep(100)
			If Not $esc And ($Win_Coord[2] > 0 And $Win_Coord[3] > 0) Then
				$Grab_x = $Win_Coord[0]
				$Grab_y = $Win_Coord[1]
				$Grab_w = $Win_Coord[2]
				$Grab_h = $Win_Coord[3]
				Switch $bCaptureXSeconds
					Case False
						Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h)
					Case True
						If Not FileExists(@ScriptDir & "\Captured\") Then DirCreate(@ScriptDir & "\Captured\")
						Local $iFrames_GIF = Int($iXSeconds_Duration / ($iXMSeconds / 1000))
						Local $hHBmp_tmp, $bError = False, $aFilesname[$iFrames_GIF + 5], $aImage_Gif[$iFrames_GIF + 5], $g = 0
						$hHBmp_tmp = Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h, False, True)
						Local $iTimerDur = TimerInit()
						$aFilesname[$g] = @ScriptDir & "\Captured\" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC & "_" & StringFormat("%04i", TimerDiff($iTimerDur)) & "_captured." & $sCapture_FilenameExt
						If Not Save_Captured_Area($hHBmp_tmp, $aFilesname[$g]) Then $bError = True
						_WinAPI_DeleteObject($hHBmp_tmp)
						$g += 1
						Local $iTimerCaptX = TimerInit()
						While $iFrames_GIF > 1
							If TimerDiff($iTimerCaptX) >= ($iXMSeconds) Then
								$hHBmp_tmp = Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h, False, True)
								$aFilesname[$g] = @ScriptDir & "\Captured\" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC & "_" & StringFormat("%04i", TimerDiff($iTimerDur)) & "_captured." & $sCapture_FilenameExt
								If Not Save_Captured_Area($hHBmp_tmp, $aFilesname[$g]) Then $bError = True
								$g += 1
								_WinAPI_DeleteObject($hHBmp_tmp)
								$iFrames_GIF -= 1
								$iTimerCaptX = TimerInit()
							EndIf
;~ 							If _IsPressed("1B", $dll) Then
;~ 								$bError = "Aborted"
;~ 								ExitLoop
;~ 							EndIf
							Sleep(10)
							If TimerDiff($iTimerDur) > 999 Then $iTimerDur = TimerInit()
						WEnd
						Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h)
						Local $iMode = 64
						If $bError Then $iMode = 48
				EndSwitch
			EndIf
		EndIf
		If $bGIFAnim Then
			ReDim $aFilesname[$g]
			ReDim $aImage_Gif[$g + 1]
			$aImage_Gif[0] = $g
			Local $fTimer = TimerInit()
			For $g = 0 To UBound($aFilesname) - 1
				$aImage_Gif[$g + 1] = _GDIPlus_ImageLoadFromFile($aFilesname[$g])
				_GDIPlus_BitmapConvertTo8Bit($aImage_Gif[$g + 1], 255, $iDither)
			Next
			ConsoleWrite("Images converted to 8-bit images in " & TimerDiff($fTimer) & " ms." & @CRLF)
			$fTimer = TimerInit()
			_GDIPlus_GIFAnimCreateFile($aImage_Gif, @ScriptDir & "\Captured\" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC & "_captured.gif", $iXMSeconds)
			ConsoleWrite("Created GIF animation in " & TimerDiff($fTimer) & " ms." & @CRLF)
			For $g = 1 To $aImage_Gif[0]
				_GDIPlus_ImageDispose($aImage_Gif[$g])
			Next
		EndIf
		GUICtrlSetState($Button_Menu_GrabScreen_Item, $GUI_ENABLE)
	EndIf
	GUIRegisterMsg($WM_MOUSEWHEEL, "")
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")
	$zoom_level = $zoom_level_default
	_WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
	_WinAPI_ReleaseDC(0, $hDC_Zoom)
;~ 	_WinAPI_DeleteDC($hGUI_ZoomDC)
;~ 	_WinAPI_DeleteDC ($hDC_Zoom)

	AutoItSetOption("GUICloseOnESC", 0)
	AutoItSetOption("GUIOnEventMode", 1)

	ToolTip("")
	GUIDelete($hGUI_MarkArea_BG)
	GUIDelete($hGUI_MarkArea_Child)
	GUIDelete($hGUI_MarkArea)
	GUIDelete($hGUI_Cross)
	GUIDelete($hGUI_Zoom)
	GUIDelete($hGUI_ZoomDC)
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
	GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
	GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
	GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "Redraw_XP")
	Else
		GUIRegisterMsg($WM_NCPAINT, "Redraw")
	EndIf
	If $aero_on Then
		DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", True)
	EndIf
	DllClose($hDwmApiDll)
	$undo_chk = False
	WinActivate(HWnd($hGUI))
	If $bCaptureXSeconds Then
		Local $iChoice = MsgBox(BitOR($iMode, $MB_YESNO, $MB_TOPMOST), $aTranslations[83][$iLang], _
				$aTranslations[114][$iLang] & @LF & @LF & @LF & _
				$aTranslations[115][$iLang] & $bError & @LF & @LF & @LF & _
				$aTranslations[116][$iLang] & @ScriptDir & "\Captured\" & $aTranslations[117][$iLang] & @LF & @LF & _
				$aTranslations[118][$iLang], 30, $hGUI)
		If $iChoice = 6 Then ShellExecute(@ScriptDir & "\Captured\")
	EndIf
	$selected = False
EndFunc   ;==>Mark_Area

Func Save_Captured_Area($hHBITMAP, $sFile)
	Local $hBmp_tmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP), $iR
	Switch StringRight($sFile, 4)
		Case ".jpg"
			Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
			Local $tParams = _GDIPlus_ParamInit(1)
			Local $tData = DllStructCreate("int Quality")
			Local $pData = DllStructGetPtr($tData)
			Local $pParams = DllStructGetPtr($tParams)
			DllStructSetData($tData, "Quality", $JPEG_Quality)
			_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
			$iR = _GDIPlus_ImageSaveToFileEx($hBmp_tmp, $sFile, $sCLSID, $pParams)
			$tData = ""
			$tParams = ""
		Case Else
			$iR = _GDIPlus_ImageSaveToFile($hBmp_tmp, $sFile)
	EndSwitch
	_GDIPlus_BitmapDispose($hBmp_tmp)
	Return $iR
EndFunc   ;==>Save_Captured_Area

Func SetCursor() ;thanks to martin
	Local $curs
	Switch GetMousePosType()
		Case 0
			$curs = 2
		Case 1, 2
			$curs = 13
		Case 3, 6
			$curs = 11
		Case 5, 7
			$curs = 10
		Case 4, 8
			$curs = 12
	EndSwitch
	GUISetCursor($curs, 1, HWnd($hGUI_MarkArea))
EndFunc   ;==>SetCursor

Func GetMousePosType() ;thanks to martin
	Local $cp = GUIGetCursorInfo($hGUI_MarkArea)
	Local $wp = WinGetPos($hGUI_MarkArea)
	If @error Then Return 0
	Local $side = 0
	Local $TopBot = 0
	If $cp[0] < $margin Then $side = 1
	If $cp[0] > $wp[2] - $margin Then $side = 2
	If $cp[1] < $margin Then $TopBot = 3
	If $cp[1] > $wp[3] - $margin Then $TopBot = 6
	Return $side + $TopBot
EndFunc   ;==>GetMousePosType

Func Capture_Window($hWnd, $w, $h)

	_GDIPlus_BitmapDispose($hBmp) ;otherwise memory leak
	_WinAPI_DeleteObject($hBitmap_s)
	$undo_chk = False
	Local $hDC_Capture = _WinAPI_GetDC(HWnd($hWnd))
	Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
	$hBitmap_s = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h)
	Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hBitmap_s)
	DllCall($g32_dll, "int", "SetStretchBltMode", "hwnd", $hDC_Capture, "uint", $STRETCH_HALFTONE)
	Local $at = DllCall($dll, "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0)

	_WinAPI_SelectObject($hMemDC, $hObjectOld)
	_WinAPI_DeleteDC($hMemDC)
	_WinAPI_ReleaseDC($hWnd, $hDC_Capture)

	Local $c1 = $aFullScreen[2] - @DesktopWidth, $c2 = $aFullScreen[3] - @DesktopHeight
	Local $wc1 = $w - $c1, $hc2 = $h - $c2

	If (($wc1 > 1 And $wc1 < $w) Or ($w - @DesktopWidth > 1) Or ($hc2 > 7 And $hc2 < $h) Or ($h - @DesktopHeight > 1)) And (BitAND(WinGetState(HWnd($hWnd)), 32) = 32) Then
		Local $hBmp_t = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap_s)
		Local $dc = 8, $dcw = 2 * $dc
		$hBmp = _GDIPlus_BitmapCloneArea($hBmp_t, $dc, $dc, $w - $dcw, $h - $dcw, $GDIP_PXF32ARGB)
;~ 		$hBmp = _GDIPlus_BitmapCloneArea($hBmp_t, ($w - @DesktopWidth) / 2, ($w - @DesktopWidth) / 2, $w - ($w - @DesktopWidth), $h - ($w - @DesktopWidth))
;~ 		ConsoleWrite($w & "x" & @DesktopWidth & ": " & ($w - @DesktopWidth) / 2 & @LF)
		_GDIPlus_BitmapDispose($hBmp_t)
	Else
		$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap_s)
	EndIf
	Update_Resolution_Info($hBmp)
	If $bBorder Then
		$hGfx_border = _GDIPlus_ImageGetGraphicsContext($hBmp)
		_GDIPlus_GraphicsDrawRect($hGfx_border, $iBorderWidth - 1, $iBorderWidth - 1, _GDIPlus_ImageGetWidth($hBmp) - $iBorderWidth , _GDIPlus_ImageGetHeight($hBmp) - $iBorderWidth, $hPen_Border)
		_GDIPlus_GraphicsDispose($hGfx_border)
	EndIf
	Draw2Graphic($hBmp)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = $hBitmap_s
	$z = 10
	Zoom(-1)
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
EndFunc   ;==>Capture_Window

Func Capture_Window2($hWnd, $2front = True)
	_GDIPlus_BitmapDispose($hBmp) ;otherwise memory leak
	_WinAPI_DeleteObject($hBitmap_s)
	$undo_chk = False
	Local $mini = False
	Local $ws = WinGetState(HWnd($hWnd), "")
	If BitAND($ws, 0x10) Then
		_WinAPI_ShowWindow($hWnd, @SW_RESTORE)
		Sleep(250)
		$mini = True
		$ws = WinGetState(HWnd($hWnd), "")
	Else
		WinActivate(HWnd($hWnd))
	EndIf
	Sleep(666)
	_WinAPI_DeleteObject($hBitmap_s)
	$hBitmap_s = __ScreenCapture_CaptureWnd("", HWnd($hWnd), 0, 0, -1, -1, $ws)
	$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap_s)
	If $bBorder Then
		$hGfx_border = _GDIPlus_ImageGetGraphicsContext($hBmp)
		_GDIPlus_GraphicsDrawRect($hGfx_border, $iBorderWidth - 1, $iBorderWidth - 1, _GDIPlus_ImageGetWidth($hBmp) - $iBorderWidth, _GDIPlus_ImageGetHeight($hBmp) - $iBorderWidth, $hPen_Border)
		_GDIPlus_GraphicsDispose($hGfx_border)
	EndIf
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = $hBitmap_s
	$z = 10
	Zoom(-1)
	If $2front Then WinActivate(WinGetHandle(HWnd($hGUI)))
	If $mini Then _WinAPI_ShowWindow(HWnd($hWnd), @SW_MINIMIZE)
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
EndFunc   ;==>Capture_Window2

Func __ScreenCapture_CaptureWnd($sFileName, $hWnd, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $maximized = False)
	Local $dex = 0, $dey = 0
	Local $tRect = _WinAPI_GetWindowRect($hWnd)
	If BitAND($maximized, 32 Or 15) Then
		$dex = 8
		$dey = 8
	EndIf

	$iLeft += DllStructGetData($tRect, "Left")
	$iTop += DllStructGetData($tRect, "Top")
	If $iRight = -1 Then $iRight = DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left")
	If $iBottom = -1 Then $iBottom = DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top")
	$iRight += DllStructGetData($tRect, "Left")
	$iBottom += DllStructGetData($tRect, "Top")
	If $iLeft > DllStructGetData($tRect, "Right") Then $iLeft = DllStructGetData($tRect, "Left")
	If $iTop > DllStructGetData($tRect, "Bottom") Then $iTop = DllStructGetData($tRect, "Top")
	If $iRight > DllStructGetData($tRect, "Right") Then $iRight = DllStructGetData($tRect, "Right")
	If $iBottom > DllStructGetData($tRect, "Bottom") Then $iBottom = DllStructGetData($tRect, "Bottom")

	Return __ScreenCapture_Capture($iLeft + $dex, $iTop + $dey, $iRight - $dex - 1, $iBottom - $dey - 1)
EndFunc   ;==>__ScreenCapture_CaptureWnd

Func __ScreenCapture_Capture($iLeft = 0, $iTop = 0, $iRight = Null, $iBottom = Null)
	If $iRight = Null Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
	If $iBottom = Null Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)

	Local $iW = ($iRight - $iLeft) + 1
	Local $iH = ($iBottom - $iTop) + 1
	Local $hWnd = _WinAPI_GetDesktopWindow()
	Local $hDDC = _WinAPI_GetDC($hWnd)
	Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
	Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
	_WinAPI_SelectObject($hCDC, $hBmp)
	_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $iRTOP) ;$__SCREENCAPTURECONSTANT_SRCCOPY)

	_WinAPI_ReleaseDC($hWnd, $hDDC)
	_WinAPI_DeleteDC($hCDC)
	Return $hBmp
EndFunc   ;==>__ScreenCapture_Capture

Func Grab_Active_Window()
	Capture_Window2(HWnd(WinGetHandle(WinGetTitle(""))), False)
	Return 1
EndFunc   ;==>Grab_Active_Window

Func Grab_Screen()
	HotKeySet("^!{F9}")
	While _IsPressed("01", $dll)
		Sleep(10)
	WEnd
	GUISetState(@SW_HIDE, $hGUI)
	Sleep(333)
	Mark_Area()
	GUISetState(@SW_SHOW, $hGUI)
	HotKeySet("^!{F9}", "Grab_Screen")
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")
EndFunc   ;==>Grab_Screen

Func Grab_Region($x, $y, $w, $h, $fCursor = False, $capture_only = False)
	_GDIPlus_BitmapDispose($hBmp) ;otherwise memory leak
	_WinAPI_DeleteObject($memBitmap)
	$hDC_Region = _WinAPI_GetDC(0)
	$hMemDC = _WinAPI_CreateCompatibleDC($hDC_Region)
	$memBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Region, $w, $h)
	$hObj = _WinAPI_SelectObject($hMemDC, $memBitmap)
	_WinAPI_BitBlt($hMemDC, 0, 0, $w, $h, $hDC_Region, $x, $y, $iRTOP)
	If $fCursor Then
		Local $aCursor = _WinAPI_GetCursorInfo()
		If $aCursor[1] Then
			Local $hIcon = _WinAPI_CopyIcon($aCursor[2])
			Local $aIcon = _WinAPI_GetIconInfo($hIcon)
			_WinAPI_DeleteObject($aIcon[4])
			_WinAPI_DrawIcon($hMemDC, $aCursor[3] - $aIcon[2], $aCursor[4] - $aIcon[3], $hIcon)
			_WinAPI_DestroyIcon($hIcon)
		EndIf
	EndIf
	_WinAPI_SelectObject($hMemDC, $hObj)
	_WinAPI_DeleteDC($hMemDC)
	_WinAPI_ReleaseDC(0, $hDC_Region)
	If $capture_only Then Return $memBitmap
	$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($memBitmap)
	If @error Then Return SetError(1, @extended, _WinAPI_ShowError($aTranslations[119][$iLang], False))
	If $bBorder Then
		$hGfx_border = _GDIPlus_ImageGetGraphicsContext($hBmp)
		_GDIPlus_GraphicsDrawRect($hGfx_border, $iBorderWidth - 1, $iBorderWidth - 1, $w - $iBorderWidth, $h - $iBorderWidth, $hPen_Border)
		_GDIPlus_GraphicsDispose($hGfx_border)
	EndIf
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = $memBitmap
	Update_Resolution_Info($hBmp)
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
	$z = 10
	Zoom(-1)
	sndPlaySound($BytePtr, $fuSound)
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
EndFunc   ;==>Grab_Region

Func GrabPrintScreenClipboard($alt = False, $skip = True)
	If Not $skip Then
		If Not $alt Then
			Send("{PRINTSCREEN}")
		Else
			Send("!{PRINTSCREEN}")
		EndIf
	EndIf
	Sleep(100) ;wait for the bitmap to be copied to the clipboard
	If Not _ClipBoard_Open(HWnd($hGUI)) Then Return _WinAPI_ShowError($aTranslations[120][$iLang], False)
	_WinAPI_DeleteObject($hMemoryBMP)
	$hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP)
	If Not $hMemoryBMP Then
		_ClipBoard_Close()
		Return _WinAPI_ShowError($aTranslations[121][$iLang], False)
	EndIf
	_GDIPlus_BitmapDispose($hBmp) ;otherwise memory leak
	$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP)
	If $bBorder Then
		$hGfx_border = _GDIPlus_ImageGetGraphicsContext($hBmp)
		_GDIPlus_GraphicsDrawRect($hGfx_border, $iBorderWidth - 1, $iBorderWidth - 1, _GDIPlus_ImageGetWidth($hBmp) - $iBorderWidth, _GDIPlus_ImageGetHeight($hBmp) - $iBorderWidth, $hPen_Border)
		_GDIPlus_GraphicsDispose($hGfx_border)
	EndIf
	_ClipBoard_Close()
	Update_Resolution_Info($hBmp)
	$z = 10
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
	Zoom(-1)
	sndPlaySound($BytePtr, $fuSound)
;~ 	GUICtrlSetState($Button_Clipboard, $GUI_DISABLE)
EndFunc   ;==>GrabPrintScreenClipboard

Func Recapture()
	If (($Grab_x + $Grab_y > 0) Or ($Grab_w + $Grab_h > 0)) And BitAND(GUICtrlGetState($Button_Menu_GrabScreen_Item), $GUI_ENABLE) Then
		GUISetState(@SW_HIDE, $hGUI)
		Sleep(450)
		Grab_Region($Grab_x, $Grab_y, $Grab_w, $Grab_h)
		GUISetState(@SW_SHOW, $hGUI)
	EndIf
EndFunc   ;==>Recapture

Func Update_Resolution_Info($hImg)
	$bW = _GDIPlus_ImageGetWidth($hImg)
	$bH = _GDIPlus_ImageGetHeight($hImg)
	GUICtrlSetData($label4, $bW & " x " & $bH)
EndFunc   ;==>Update_Resolution_Info

Func Draw_Zoom_Preview($mposX, $mposY, $cl_p1 = 0.4)
	Local Const $lW = 40, $lH = 40, $dw = 10, $cl_p2 = 1 - $cl_p1
	If CheckRectCollision($zx - $lW, $zy - $lH, $zx + $zw + $lW, $zy + $zh + $lH, $mposX, $mposY) Then
		If $up = -1 Then
			$zx = @DesktopWidth - $zw - 4
			$zy = 0
			WinMove($hGUI_Zoom, "", $zx, $zy)
		Else
			$zy = 0
			$zx = 0
			WinMove($hGUI_Zoom, "", $zx, $zy)
		EndIf
		$up *= -1
	EndIf
	$zoomW = Int($zw / $zoom_level)
	$zoomH = Int($zh / $zoom_level)

	_WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $zw, $zh, $hDC_Zoom, $mposX - $zoomW / 2, $mposY - $zoomH / 2, $zoomW, $zoomH, $iRTOP)
	Local Const $hPen = _WinAPI_CreatePen($PS_SOLID, $zoom_level / 2, "0x" & $red & $green & $blue)
	Local Const $obj_orig = _WinAPI_SelectObject($hGUI_ZoomDC, $hPen)
	If (@OSBuild < 6000 Or (Not $aero)) Then
		_WinAPI_DrawLine($hGUI_ZoomDC, 0, $zh / 2 + $zoom_level / 2, $zw, $zh / 2 + $zoom_level / 2)
		_WinAPI_DrawLine($hGUI_ZoomDC, $zw / 2 + $zoom_level / 2, 0, $zw / 2 + $zoom_level / 2, $zh)
	ElseIf $selected Then
		_WinAPI_DrawLine($hGUI_ZoomDC, 0, $zh / 2 + $zoom_level / 2, $zw, $zh / 2 + $zoom_level / 2)
		_WinAPI_DrawLine($hGUI_ZoomDC, $zw / 2 + $zoom_level / 2, 0, $zw / 2 + $zoom_level / 2, $zh)
	EndIf
	_WinAPI_SelectObject($hGUI_ZoomDC, $obj_orig)
	_WinAPI_DeleteObject($hPen)
	$pixel_color = Hex(PixelGetColor(MouseGetPos(0), MouseGetPos(1)), 6)
	GUICtrlSetData($iLabelZoom_iColor, $aTranslations[100][$iLang] & $pixel_color)
EndFunc   ;==>Draw_Zoom_Preview

Func CheckRectCollision($iLeft, $iTop, $iRight, $iBottom, $iX, $iY)
	Local $tagRECT = "int Left;int Top;int Right;int Bottom"
	Local $tRect = DllStructCreate($tagRECT)
	DllStructSetData($tRect, 1, $iLeft)
	DllStructSetData($tRect, 2, $iTop)
	DllStructSetData($tRect, 3, $iRight)
	DllStructSetData($tRect, 4, $iBottom)
	Local $aResult = DllCall($dll, "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
	$tRect = 0
	Return $aResult[0]
EndFunc   ;==>CheckRectCollision

Func _GuiHole($hWnd, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $height)
	Local $outer_rgn, $inner_rgn, $combined_rgn
	$outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $height)
	$inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
	$combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
	_WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
	_WinAPI_DeleteObject($outer_rgn)
	_WinAPI_DeleteObject($inner_rgn)
	_WinAPI_SetWindowRgn($hWnd, $combined_rgn)
EndFunc   ;==>_GuiHole
#EndRegion Screen Grab

#Region Web Grab
Func WebGrab()
	HotKeySet("^!{F9}")
	GUIRegisterMsg($WM_NCPAINT, "")
	AutoItSetOption("GUIOnEventMode", 0)
	Local $break = False, $aWin, $mouse, $k, $e, $button_pos = $gdip_w - 75, $steps = Int(255 / 27), $aTextSize
	GUICtrlSetState($Button_WebGrab, $GUI_DISABLE)
	GUICtrlSetState($Button_Exit, $GUI_DISABLE)
	GUICtrlSetState($Button_Save, $GUI_DISABLE)
	GUICtrlSetState($Button_Clipboard, $GUI_DISABLE)
	GUICtrlSetState($Button_Refresh, $GUI_DISABLE)
	GUICtrlSetState($Button_Grab2AVI, $GUI_DISABLE)
	GUICtrlSetState($Button_GrabScreen, $GUI_DISABLE)
	GUICtrlSetState($List, $GUI_DISABLE)
	;Local $hGUI_URL = GUICreate("",  526, 26, 264, $height - 114, $WS_POPUP,  $WS_EX_LAYERED + $WS_EX_MDICHILD, $hGUI)
	Local $hGUI_URL = GUICreate("", $gdip_w, 26, 264, $height - 114, BitOR($WS_POPUP, $WS_OVERLAPPED), BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)
	WinSetTrans($hGUI_URL, "", 0)
	GUISetBkColor(0xBFCDDB, $hGUI_URL)
	$URL_Input = GUICtrlCreateInput("https://", 1, 27, $gdip_w - 77, 23)
	GUICtrlSetTip(-1, $aTranslations[122][$iLang], "", 0, 1)
	GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
	$Grab_Button = GUICtrlCreateButton("Grab &Web", $button_pos, 27, 75, 25)
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUISetState(@SW_DISABLE, $hGUI)
	GUISetState(@SW_SHOW, $hGUI_URL)
	;_WinAPI_SetLayeredWindowAttributes($hGUI_URL, 0xBFCDDB)
	$e = 1
	For $k = 27 To 1 Step -1
		Sleep(10)
		GUICtrlSetPos($URL_Input, 1, $k)
		GUICtrlSetPos($Grab_Button, $button_pos, $k - 1)
		WinSetTrans($hGUI_URL, "", $steps * $e)
		$e += 1
	Next
	ControlClick($hGUI_URL, "", $URL_Input)
	$Dummy = GUICtrlCreateDummy()
	GUIRegisterMsg($WM_COMMAND, "Check_URL_Input")
	While Sleep(30)
		Switch GUIGetMsg()
			Case $Grab_Button
				ExitLoop
			Case $Dummy
				ExitLoop
		EndSwitch
		If _IsPressed("1B", $dll) Then
			$break = True
			ExitLoop
		EndIf
	WEnd
	GUIRegisterMsg($WM_COMMAND, "")
	$Dummy = ""
	If Not $break Then
		GUICtrlSetState($Grab_Button, $GUI_DISABLE)
		GUICtrlSetState($URL_Input, $GUI_DISABLE)
		$aWin = WinGetPos(HWnd($hGUI))
		$aTextSize = GetStringSize($aTranslations[124][$iLang] & "(999) ————" & ChrW(8250), "Lucida Console", 12)
		SplashTextOn($aTranslations[123][$iLang], $aTranslations[124][$iLang], $aTextSize[0] + 24, 40, $aWin[0] + ($aWin[2] - $aTextSize[0]) / 2, $aWin[1] + $aWin[3] / 2 - 20, 39, "Lucida Console", 12, 400)
		AdlibRegister("Wait", 250)
		$web_sec = TimerInit()
		$mouse = MouseGetCursor()
		GUISetCursor(15, 0, HWnd($hGUI))
		For $k = 0 To UBound($Button_Menu_Web_Item2_Sub)
			If BitAND(GUICtrlRead($Button_Menu_Web_Item2_Sub[$k]), $GUI_CHECKED) = $GUI_CHECKED Then
				$iWebsiteW = $Button_Menu_Web_Item2_Sub_Items[$k]
				ExitLoop
			EndIf
		Next
		;Web_Screenshot(GUICtrlRead($URL_Input), $iWebsiteW)
		WebCapture(GUICtrlRead($URL_Input), $iWebsiteW)
		GUISetCursor($mouse, 0, HWnd($hGUI))
		AdlibUnRegister("Wait")
		SplashOff()
	EndIf
	For $k = 0 To 27
		Sleep(10)
		GUICtrlSetPos($URL_Input, 1, $k + 1)
		GUICtrlSetPos($Grab_Button, $button_pos, $k)
		WinSetTrans($hGUI_URL, "", 0xFF - ($steps * $k))
	Next
	GUISetState(@SW_ENABLE, $hGUI)
	GUIDelete($hGUI_URL)
	GUICtrlSetState($Button_WebGrab, $GUI_ENABLE)
	GUICtrlSetState($Button_Exit, $GUI_ENABLE)
	GUICtrlSetState($Button_Save, $GUI_ENABLE)
	GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
	GUICtrlSetState($Button_Refresh, $GUI_ENABLE)
	GUICtrlSetState($Button_Grab2AVI, $GUI_ENABLE)
	GUICtrlSetState($Button_GrabScreen, $GUI_ENABLE)
	GUICtrlSetState($List, $GUI_ENABLE)
	AutoItSetOption("GUIOnEventMode", 1)
	GUIRegisterMsg($WM_NCPAINT, "Redraw")
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
	$undo_chk = False
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
	HotKeySet("^!{F9}", "Grab_Screen")
	;WinActivate($hGUI)
EndFunc   ;==>WebGrab

Func Check_URL_Input($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	Local $input, $chk, $chk2, $go = False
	If BitAND($wParam, 0x0000FFFF) = $URL_Input Then
		$input = GUICtrlRead($URL_Input)
		$chk2 = StringReplace($input, "://", "://")
		$chk2 = @extended
		$chk = StringRegExp($input, "\A(?i:http://.+|https://.+|ftp://.+)", 3)
		If Not @error And $chk2 = 1 Then
			GUICtrlSetState($Grab_Button, $GUI_ENABLE)
			$go = True
		Else
			GUICtrlSetState($Grab_Button, $GUI_DISABLE)
			$go = False
		EndIf
	EndIf
	If Not BitAND($wParam, 0xFFFF0000) And $go Then GUICtrlSendToDummy($Dummy)
EndFunc   ;==>Check_URL_Input

Func WebCapture($Url, $WebWidth = 1280, $timeout = 60 * 1000) ;by Ward
    Local Const $DVASPECT_CONTENT = 1
    Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}")
    Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);"
    Local $oIE = ObjCreate("Shell.Explorer.2")

    Local $hGUI_WebGrab = GUICreate("", $WebWidth, 768, -1, -1)
    GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 768)

    ;_IENavigateEx($oIE, $url, $timeout)

	Local Const $BrowserNavConstant = BitOR(2, 128, 256, 512, 4096, 32768)
	Local $timer = TimerInit()
	With $oIE
		.Silent = True
		.FullScreen = True
		.Resizable = False
		.Visible = False
		.StatusBar = False
		.AddressBar = False
		.Navigate($url, $BrowserNavConstant, "_top")
		Do
			If TimerDiff($timer) > $timeout Then ExitLoop
			Sleep(500)
		Until .ReadyState = 4
		.Stop
	EndWith

    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement

    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = "hidden"
	$oBody.Style.border = "0px"

    Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2)
    If @Error Then Return SetError(1, 0, 0)

    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight

    Local $Width = $WebWidth ;$BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight

    $oIE.width = $Width
    $oIE.height = $Height

    Local Const $hDC = _WinAPI_GetDC(0)
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local Const $hBmp_Web = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDc, $hBmp_Web)

    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)

    $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Ptr($hDC), Ptr($hMemDC), DllStructGetPtr($sRECT), 0, 0, 0)

	_GDIPlus_BitmapDispose($hBmp) ;otherwise memory leak
	$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hBmp_Web)
	If BitAND(GUICtrlRead($Button_Menu_Web_Item1), $GUI_CHECKED) = $GUI_CHECKED Then
		Local Const $hCtx_Web = _GDIPlus_ImageGetGraphicsContext($hBmp)
		_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_Web, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
		Local Const $width_web = _GDIPlus_ImageGetWidth($hBmp)
		Local Const $height_web = _GDIPlus_ImageGetHeight($hBmp)
		Local Const $hBrushBG_Web = _GDIPlus_LineBrushCreate(0, 0, $width_web + 16, 16, 0xE0FFFFF0, 0x08FFFFF0)
		_GDIPlus_GraphicsFillRect($hCtx_Web, 2, $height_web - 18, $width_web - 4, 16, $hBrushBG_Web)
		_GDIPlus_GraphicsDrawString($hCtx_Web, "URL: " & $url, 3, $height_web - 18, "Times New Roman", 10)
		_GDIPlus_BrushDispose($hBrushBG_Web)
		_GDIPlus_GraphicsDispose($hCtx_Web)
	EndIf
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
	$z = 10
	Zoom(-1)
	_WinAPI_DeleteObject($hClipboard_Bitmap)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)
	$hClipboard_Bitmap = $hBmp_Web
	GUIDelete($hGUI_WebGrab)
	sndPlaySound($BytePtr, $fuSound)
EndFunc

Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False)
    If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID)

    If Not IsObj($Obj) Then Return SetError(1, 0, 0)

    Local $pObj = _AutoItObject_IDispatchToPtr($Obj)
    If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0)
    Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown)
    Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0)
    If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0)

    Local $pInterface = $aCall[2]
    Return _AutoItObject_WrapperCreate($pInterface, $Tag)
EndFunc

Func Min($a, $b)
	If $a < $b Then Return $a
	Return $b
EndFunc   ;==>Min

Func Max($a, $b)
	If $a > $b Then Return $a
	Return $b
EndFunc   ;==>Max

Func Wait()
	Local $web_ellapsed = StringFormat("%i" ,TimerDiff($web_sec) / 1000)
	Switch Mod($i, 5)
		Case 0
			ControlSetText($aTranslations[123][$iLang], "", "Static1", $aTranslations[124][$iLang] & " (" & $web_ellapsed & ")" & ChrW(8250))
		Case 1
			ControlSetText($aTranslations[123][$iLang], "", "Static1", $aTranslations[124][$iLang] & " (" & $web_ellapsed & ") —" & ChrW(8250))
		Case 2
			ControlSetText($aTranslations[123][$iLang], "", "Static1", $aTranslations[124][$iLang] & " (" & $web_ellapsed & ") ——" & ChrW(8250))
		Case 3
			ControlSetText($aTranslations[123][$iLang], "", "Static1", $aTranslations[124][$iLang] & " (" & $web_ellapsed & ") ———" & ChrW(8250))
		Case 4
			ControlSetText($aTranslations[123][$iLang], "", "Static1", $aTranslations[124][$iLang] & " (" & $web_ellapsed & ") ————" & ChrW(8250))
	EndSwitch
	$i += 1
EndFunc   ;==>Wait

Func ObjErrorHandler()
	ConsoleWrite("A COM Error has occured!" & @CRLF & @CRLF & _
			"err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _
			"err.windescription:" & @TAB & $oErrorHandler & @CRLF & _
			"err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _
			"err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _
			"err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _
			"err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _
			"err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _
			"err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _
			)
EndFunc   ;==>ObjErrorHandler
#EndRegion WebGrab

#Region Save Bitmap
Func Save_Bitmap()
	HotKeySet("^!{F9}")
	Local $m, $save, $hBmp_tmp, $ok = True, $iExt = 0
	$filename = FileSaveDialog($aTranslations[126][$iLang], @ScriptDir, $aTranslations[127][$iLang] & " (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf)", 18, "", $hWnd_GUI)
	If Not @error Then
		$hBmp_tmp = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
		If BitAND(GUICtrlRead($Button_Menu_Item3), $GUI_CHECKED) Then
			$hBmp = _GDIPlus_WTOB($hBmp, _Now())
			Zoom(-1)
		EndIf
		Local $bSave_Shadow = 0
		If BitAND(GUICtrlRead($Button_Menu_Item4), $GUI_CHECKED) Then $bSave_Shadow = True

		If StringMid($filename, StringLen($filename) - 3, 1) <> "." Then
			$filename &= ".png"
			If FileExists($filename) Then
				$m = MsgBox(BitOR($MB_YESNO, $MB_ICONWARNING, $MB_TOPMOST), $aTranslations[128][$iLang], $filename & $aTranslations[129][$iLang] & @CRLF & $aTranslations[130][$iLang], 0, $hGUI)
				If $m = 7 Then $ok = False
			EndIf
		EndIf
		If $ok Then
			Switch StringRight($filename, 4)
				Case ".jpg"
					Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
					Local $tParams = _GDIPlus_ParamInit(1)
					Local $tData = DllStructCreate("int Quality")
					DllStructSetData($tData, "Quality", $JPEG_Quality)
					Local $pData = DllStructGetPtr($tData)
					_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
					Local $pParams = DllStructGetPtr($tParams)
					If $bSave_Shadow Then
						Local $hBmp_Shadow = _GDIPlus_BitmapAddShadow($hBmp, True)
						$save = _GDIPlus_ImageSaveToFileEx($hBmp_Shadow, $filename, $sCLSID, $pParams)
						_GDIPlus_BitmapDispose($hBmp_Shadow)
					Else
						$save = _GDIPlus_ImageSaveToFileEx($hBmp, $filename, $sCLSID, $pParams)
					EndIf
					$tData = ""
					$tParams = ""
				Case ".pdf"
					$save = Save2PDF($filename)
					$iExt = @extended
				Case Else
					If $bSave_Shadow Then
						Local $hBmp_Shadow = _GDIPlus_BitmapAddShadow($hBmp, $bSave_BgColor)
						$save = _GDIPlus_ImageSaveToFile($hBmp_Shadow, $filename)
						_GDIPlus_BitmapDispose($hBmp_Shadow)
					Else
						$save = _GDIPlus_ImageSaveToFile($hBmp, $filename)
					EndIf
			EndSwitch
			$hBmp = _GDIPlus_BitmapClone($hBmp_tmp, $bW, $bH)
			If Not BitAND(GUICtrlRead($Button_Menu_Item3), $GUI_CHECKED) Then Zoom(-1)
		EndIf
		_GDIPlus_BitmapDispose($hBmp_tmp)

		If $save Then
			Local $sTxt_MsgBox1 = $aTranslations[131][$iLang], $sTxt_MsgBox2 = $aTranslations[132][$iLang]
			If $iExt Then
				$sTxt_MsgBox1 = $aTranslations[264][$iLang]
				$sTxt_MsgBox2 = $aTranslations[265][$iLang]
			EndIf
			If Not $skip_display Then
				Local $c = MsgBox(BitOr($MB_YESNO, $MB_ICONINFORMATION, $MB_DEFBUTTON2, $MB_TOPMOST), $aTranslations[83][$iLang], $sTxt_MsgBox1 & @CRLF & @CRLF & $filename & @CRLF & @CRLF & @CRLF & _
						$sTxt_MsgBox2, 20, $hWnd_GUI)
				If $c = 6 Then ShellExecute($filename)
			Else
				MsgBox(BitOr($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $sTxt_MsgBox1 & @CRLF & @CRLF & $filename, 20, $hWnd_GUI)
			EndIf
		Else
			If $iExt Then
				MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[263][$iLang], 30, $hWnd_GUI)
			Else
				MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[133][$iLang], 20, $hWnd_GUI)
			EndIf
		EndIf
		$skip_display = False
		$hWnd_GUI = $hGUI
	EndIf
	HotKeySet("^!{F9}", "Grab_Screen")
EndFunc   ;==>Save_Bitmap

Func Save2PDF($filename)
	If BitAND(GUICtrlRead($Button_Menu_Item3), $GUI_CHECKED) = $GUI_CHECKED Then
		$hBmp = _GDIPlus_WTOB($hBmp, _Now())
		Zoom(0)
	EndIf
	Local $iDegree = 90
	_SetTitle("Image2PDF")
	_SetSubject("Converted by Windows Screenshooter")
	_SetKeywords("pdf, AutoIt, Windows Screenshooter")
	_SetUnit($PDF_UNIT_PT) ;pixel
	_SetZoomMode($PDF_ZOOM_CUSTOM, 66)
	If $bW > $bH Then
		_SetPaperSize("CUSTOM", 841.890, 595.276) ; A4 landscape
		_SetOrientation($PDF_ORIENTATION_LANDSCAPE)
		$iDegree = 0
	Else
		_SetPaperSize("CUSTOM", 595.276, 841.890) ; A4 portrait
		_SetOrientation($PDF_ORIENTATION_PORTRAIT)
	EndIf
	_SetLayoutMode($PDF_LAYOUT_SINGLE)
	_InitPDF($filename)
	_LoadFontTT("_Arial", $PDF_FONT_ARIAL)
	If $bSave_Shadow Then
		Local $hBmp_Shadow = _GDIPlus_BitmapAddShadow($hBmp, $bSave_BgColor)
		_LoadResImageMem("UEZ", Bitmap2String($hBmp_Shadow), _GDIPlus_ImageGetWidth($hBmp_Shadow) , _GDIPlus_ImageGetHeight($hBmp_Shadow))
		_GDIPlus_BitmapDispose($hBmp_Shadow)
	Else
		_LoadResImageMem("UEZ", Bitmap2String($hBmp), $bW, $bH)
	EndIf
	_BeginPage()
	Local $x, $y
	Local $pW = _GetPageWidth() ;595
	Local $pH = _GetPageHeight() ;841
	If $bW < $pW And $bH < $pH Then
		$x = ($pW - $bW) / 2
		$y = ($pH - $bH) / 2
		_InsertImage("UEZ", $x, $y, $bW, $bH)
	ElseIf $bW > $pW And $bH < $pH Then
		$x = 0
		$y = ($pH - ($pW / $bW) * $bH) / 2
		_InsertImage("UEZ", $x, $y, $pW, ($pW / $bW) * $bH)
	ElseIf $bW < $pW And $bH > $pH Then
		$x = ($pW - $bW) / 2
		$y = 0
		_InsertImage("UEZ", $x, $y, $bW, $pH)
	ElseIf $bW > $pW And $bH > $pH Then
		If $bW < $bH Then
			$x = 0
			$y = ($pH - ($pW / $bW) * $bH) / 2
			_InsertImage("UEZ", $x, $y, $pW, ($pW / $bW) * $bH)
		Else ;$bW > $bH
			$x = 0
			$y = ($pH - ($pW / $bW) * $bH) / 2
			_InsertImage("UEZ", $x, $y, ($pW / $bW) * $bW, ($pW / $bW) * $bH)
		EndIf
	Else
		_InsertImage("UEZ", 0, 0, $pW, $pH)
	EndIf
	_SetTextRenderingMode(2)
;~ 	_SetColourFill(0xA08080) ;has no effect
	_DrawText(7, 2, "Created by Windows Screenshooter", "_Arial", 8, $PDF_ALIGN_LEFT, $iDegree)
	_SetTextRenderingMode(0)
	_SetColourFill(0xE8A0A0)
	_DrawText(7, 2, "Created by Windows Screenshooter", "_Arial", 8, $PDF_ALIGN_LEFT, $iDegree)
	_EndPage()
	If Not _ClosePDFFile() Then Return SetError(1, 1, 0)
	Return SetExtended(1, 1)
EndFunc   ;==>Save2PDF

Func Bitmap2String($Bitmap)
	Local $CLSID_Encoder = _GDIPlus_EncodersGetCLSID("jpg")
	Local $tagGUID_Struct = _WinAPI_GUIDFromString($CLSID_Encoder)
	Local $pTagGUID = DllStructGetPtr($tagGUID_Struct)
	Local $Stream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", 1, "ptr*", 0)
	DllCall($__g_hGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $Bitmap, "ptr", $Stream[3], "ptr", $pTagGUID, "ptr", 0)
	Local $Memory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $Stream[3], "ptr*", 0)
	Local $Mem_Size = _MemGlobalSize($Memory[2])
	Local $Mem_Ptr = _MemGlobalLock($Memory[2])
	Local $bData_Struct = DllStructCreate("byte[" & $Mem_Size & "]", $Mem_Ptr)
	Local $bData = DllStructGetData($bData_Struct, 1)
	Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr")
	Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $Stream[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
	_MemGlobalFree($Memory[2])
	$bData_Struct = 0
	$tVARIANT = 0
	Return BinaryToString($bData)
EndFunc   ;==>Bitmap2String

Func Pic2Clipboard()
	Local $hHBmp
	If $bClipboard_Shadow Then
		Local $hBmp_Shadow = _GDIPlus_BitmapAddShadow($hBmp, $bSave_BgColor)
		$hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp_Shadow)
		_GDIPlus_BitmapDispose($hBmp_Shadow)
	Else
		$hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
	EndIf
	_WinAPI_DeleteObject($hClipboard_Bitmap)
	$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
	_WinAPI_DeleteObject($hHBmp)

	Local $err = 0, $err_txt, $hCP
	If Not _ClipBoard_Open(0) Then ;HWnd($hGUI)
		$err = @error
		$err_txt = $aTranslations[120][$iLang]
	EndIf
	If Not _ClipBoard_Empty() Then
		$err = @error
		$err_txt = $aTranslations[134][$iLang]
	EndIf
;~ 	_ClipBoard_SetData("!", $CF_TEXT)
	If $bClipboard_PNG Then
		Local $bPNG = _GDIPlus_StreamImage2BinaryString($hBmp)
		Local $iSize = BinaryLen($bPNG)
		$hMemory_Clipboard = _MemGlobalAlloc($iSize, $GHND)
		Local $hLock = _MemGlobalLock($hMemory_Clipboard)
		Local $tData = DllStructCreate("byte[" & $iSize & "]", $hLock)
		DllStructSetData($tData, 1, Binary($bPNG))
		_MemGlobalUnlock($hMemory_Clipboard)
		$hCP = _ClipBoard_SetDataEx($hMemory_Clipboard, $iFormat_PNG)
		_MemGlobalFree($hMemory_Clipboard)
		$bPNG = 0
	Else
		$hCP = _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP)
	EndIf
	If Not $hCP Or @error Then
		$err = @error
		$err_txt = $aTranslations[121][$iLang]
	EndIf
	_ClipBoard_Close()
;~ 	$hCP_old = $hClipboard_Bitmap
	If Not $silent Then
		If Not $err Then
			MsgBox(BitOr($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $aTranslations[135][$iLang], 10)
			$bCBChanged = False
			Return True
		Else
			MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[136][$iLang] & $err_txt, 10)
			Return False
		EndIf
	EndIf
	If Not $err Then Return True
	Return False
EndFunc   ;==>Pic2Clipboard

Func Slider_Label_Color($value)
	Switch $value
		Case 0 To 40
			GUICtrlSetColor($Slider_Label_Value, 0xFF0000)
		Case 41 To 70
			GUICtrlSetColor($Slider_Label_Value, 0xFF8000)
		Case 71 To 89
			GUICtrlSetColor($Slider_Label_Value, 0x80F000)
		Case 90 To 100
			GUICtrlSetColor($Slider_Label_Value, 0x00F000)
	EndSwitch
EndFunc   ;==>Slider_Label_Color
#EndRegion Save Bitmap

#Region Print current image
Func PrintImage() ;sends current image to printer
	Local $tempFile = _TempFile(@TempDir, "~", ".png", 8)
	If _GDIPlus_ImageSaveToFile($hBmp, $tempFile) Then
		GUISetState(@SW_DISABLE, $hGUI)
		RunWait('Rundll32.exe "' & @SystemDir & '\mshtml.dll",PrintHTML "' & $tempFile & '"', @SystemDir)
;~ 		ShellExecute("Rundll32.exe", @SystemDir & "\mshtml.dll,PrintHTML " & $tempFile)
;~ 		ConsoleWrite(@SystemDir & "\Rundll32.exe" & " " &  @SystemDir & "\mshtml.dll,PrintHTML " & $tempFile & @CRLF)
		FileDelete($tempFile)
		WinActivate(HWnd($hGUI))
		GUISetState(@SW_ENABLE, $hGUI)
	Else
		MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[137][$iLang], 10, $hGUI)
	EndIf
EndFunc   ;==>PrintImage
#EndRegion Print current image

#Region Check for updates
Func Check4Update()
	GUISetCursor(15)
	Local $iRead = InetRead("https://www.autoitscript.com/forum/index.php?showtopic=122941")
	If @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[138][$iLang], 30, $hGUI)
	Local $aRegEx = StringRegExp(BinaryToString($iRead), "<title>AutoIt Windows Screenshooter (v\d\.\d+.*\d+-\d+-\d+)\s.*</title>", 1)
	GUISetCursor(-1)
	If Not IsArray($aRegEx) Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[139][$iLang], $aTranslations[149][$iLang], 30, $hGUI)
	Local $sVer = $aRegEx[0]
	If $ver = $sVer Then
		MsgBox(BitOr($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[141][$iLang], $aTranslations[142][$iLang] & $ver & @CRLF & $aTranslations[143][$iLang] & $sVer & @LF & @LF & $aTranslations[145][$iLang], 15, $hGUI)
	Else
		Local $iChk = MsgBox(BitOr($MB_ICONQUESTION, $MB_YESNO, $MB_DEFBUTTON2, $MB_TOPMOST), $aTranslations[141][$iLang], $aTranslations[142][$iLang] & $ver & @CRLF & $aTranslations[143][$iLang] & $sVer & @LF & @LF & $aTranslations[144][$iLang], 30, $hGUI)
		If $iChk = 6 Then ShellExecute("https://www.autoitscript.com/forum/index.php?showtopic=122941")
	EndIf
	WinActivate(HWnd($hGUI))
EndFunc   ;==>Check4Update
#EndRegion Check for updates

#Region Image Editor
Func ImageEditor()
	Local Const $hGUI_ImageEditor_W = Int(@DesktopWidth * 0.875)
	Local Const $hGUI_ImageEditor_H = Int(@DesktopHeight * 0.875)
	Local Const $height_delta = 60 ;* (($aDPI[0] + $aDPI[1]) / 2)

	$IE_Pen_Col = 0xF0FF0000
	$IE_PenSize = 4
	$IE_HL_Col = 0x70FFFF00
	$IE_Brush_Col = 0x18FFFF00
	$IE_HL_Col_BGR = 0x00FFFF
	$IE_HLSize = 20
	$IE_Brush_w = 16
	$IE_Brush_h = $IE_HLSize
	$IE_offset_x = 0
	$IE_offset_y = 0
	$IE_Tool_Selected = 1
	$hCursor_System = _WinAPI_CopyIcon(_WinAPI_LoadCursor(0, 32512))

	Local $IE_TB_Style = BitOR($TBSTYLE_FLAT, $TBSTYLE_TRANSPARENT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)
	Local Const $hHBITMAP_IE_Icons = _GDIPlus_BitmapCreateFromMemory(_ImageEditor_ToolbarIcons(), True)
	$hGUI_ImageEditor = GUICreate("AutoIt Windows Screenshooter - " & $aTranslations[39][$iLang] & " / " & $aTranslations[82][$iLang] & $bW & "x" & $bH & $aTranslations[78][$iLang], $hGUI_ImageEditor_W, $hGUI_ImageEditor_H)
	GUISetBkColor(0xDBE3DE, $hGUI_ImageEditor)
	If @OSBuild < 6000 Then
		DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hGUI_ImageEditor, "wstr", "", "wstr", "")
		$IE_TB_Style = BitOR($TBSTYLE_FLAT, $TBSTYLE_TRANSPARENT)
	EndIf

	$hToolbar_IE = _GUICtrlToolbar_Create($hGUI_ImageEditor, $IE_TB_Style)
;~ 	Local $idToolbar_IE = _WinAPI_GetDlgCtrlID($hToolbar_IE)
	Local Const $hReBar = _GUICtrlRebar_Create($hGUI_ImageEditor, BitOR($CCS_TOP, $RBS_VARHEIGHT, $RBS_AUTOSIZE,  $RBS_BANDBORDERS))
	Local $aStrings[16]

	$aStrings[0] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[146][$iLang])
	$aStrings[1] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[147][$iLang])
	$aStrings[2] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[148][$iLang])
	$aStrings[3] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[149][$iLang])
	$aStrings[4] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[150][$iLang])
	$aStrings[5] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[151][$iLang])
	$aStrings[6] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[152][$iLang])
	$aStrings[7] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[153][$iLang])
	$aStrings[8] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[154][$iLang])
	$aStrings[9] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[155][$iLang])
	$aStrings[10] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[156][$iLang])
	$aStrings[11] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[157][$iLang])
	$aStrings[12] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[158][$iLang])
	$aStrings[13] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[159][$iLang])
	$aStrings[14] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[278][$iLang])
	$aStrings[15] = _GUICtrlToolbar_AddString($hToolbar_IE, $aTranslations[14][$iLang])

	_GUICtrlToolbar_SetBitmapSize($hToolbar_IE, 24, 24)
	_GUICtrlToolbar_AddBitmap($hToolbar_IE, 1, 0, $hHBITMAP_IE_Icons)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idSave_IE, 2, $aStrings[0], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idCopy_IE, 3, $aStrings[1], $BTNS_AUTOSIZE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idSend_IE, 4, $aStrings[2], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idUndo_IE, 0, $aStrings[3], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idHighlighter_IE, 6, $aStrings[6], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idPen_IE, 5, $aStrings[4], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idIEPen_Size, 8, $aStrings[5], BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN, $BTNS_AUTOSIZE))
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idRectangle_IE, 9, $aStrings[7], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idEllipse_IE, 10, $aStrings[8], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idArrow_IE, 11, $aStrings[9], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idColor_IE, 12, $aStrings[10], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idText_IE, 13, $aStrings[11], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButton($hToolbar_IE, $idText_Conf_IE, 14, $aStrings[12], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idFX_IE, 15, $aStrings[13], BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN, $BTNS_AUTOSIZE))
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idFX_IE_Crop, 16, $aStrings[14], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlToolbar_AddButton($hToolbar_IE, $idFX_IE_Resize, 17, $aStrings[15], $BTNS_AUTOSIZE)
	_GUICtrlToolbar_AddButtonSep($hToolbar_IE)

	_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 2)

	Local $hHBitmap_ImageEditor = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
	$hGUI_ImageEditor_Child = GUICreate("", $hGUI_ImageEditor_W, $hGUI_ImageEditor_H - $height_delta, 0, $height_delta, BitOR($WS_POPUP, $WS_CHILD), BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI_ImageEditor)
	GUISetBkColor($iGUI_IE_BGColor, $hGUI_ImageEditor_Child)

	If $bW < $hGUI_ImageEditor_W Or $bH < ($hGUI_ImageEditor_H - $height_delta) Then
		$IE_offset_x = -($hGUI_ImageEditor_W - $bW) / 2
		$IE_offset_y = -(($hGUI_ImageEditor_H - $height_delta) - $bH) / 2
		$idPic_ImageEditor = GUICtrlCreatePic("", $IE_offset_x * -1, ($hGUI_ImageEditor_H - $bH) / 2 - $height_delta / 2, $bW, $bH)
	Else
		$idPic_ImageEditor = GUICtrlCreatePic("", 0, 0, $bW, $bH)
	EndIf

	_WinAPI_DeleteObject(GUICtrlSendMsg($idPic_ImageEditor, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_ImageEditor))
	_WinAPI_DeleteObject($hHBitmap_ImageEditor)

	_GUICtrlRebar_AddToolBarBand($hReBar, $hToolbar_IE, "", 0)

	_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE)

	If (@OSBuild < 6000) Then DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar_IE, "wstr", "", "wstr", "")

	Local Const $iKey_Undo = GUICtrlCreateButton("", -10, -10, 1, 1), $iKey_s = GUICtrlCreateButton("", -12, -10, 1, 1), $iKey_c = GUICtrlCreateButton("", -14, -10, 1, 1), _
			$iKey_n = GUICtrlCreateButton("", -16, -10, 1, 1), $iKey_h = GUICtrlCreateButton("", -18, -10, 1, 1), $iKey_p = GUICtrlCreateButton("", -20, -10, 1, 1), _
			$iKey_r = GUICtrlCreateButton("", -22, -10, 1, 1), $iKey_e = GUICtrlCreateButton("", -24, -10, 1, 1), $iKey_a = GUICtrlCreateButton("", -26, -10, 1, 1), _
			$iKey_o = GUICtrlCreateButton("", -28, -10, 1, 1), $iKey_t = GUICtrlCreateButton("", -30, -10, 1, 1), $iKey_g = GUICtrlCreateButton("", -32, -10, 1, 1)
	Local $aAccelKeys[12][2] = [["^z", $iKey_Undo],["s", $iKey_s],["c", $iKey_c],["n", $iKey_n],["h", $iKey_h],["p", $iKey_p],["r", $iKey_r],["e", $iKey_e], _
			["a", $iKey_a],["o", $iKey_o],["t", $iKey_t],["g", $iKey_g]]

	Local $bReset = False
	Local $KeyLayout = RegRead("HKCU\Keyboard Layout\Preload", 1)
	If Not @error And $KeyLayout = 00000419 Then
		_WinAPI_LoadKeyboardLayout(0x0409)
		$bReset = True
	EndIf

	GUISetAccelerators($aAccelKeys, $hGUI_ImageEditor)
	GUISetAccelerators($aAccelKeys, $hGUI_ImageEditor_Child)

	If $bReset Then _WinAPI_LoadKeyboardLayout(Dec($KeyLayout))

	Local Const $iVSscroll = _WinAPI_GetSystemMetrics(2)
	Local Const $iHSscroll = _WinAPI_GetSystemMetrics(3)
	Local Const $iYCaption = _WinAPI_GetSystemMetrics(4)
	Local Const $iYFixedFrame = _WinAPI_GetSystemMetrics(8)
	Local Const $iXFixedFrame = _WinAPI_GetSystemMetrics(7)

	Local $iMetricsSumX = ($bH > ($hGUI_ImageEditor_H - $height_delta)) * $iVSscroll + $iXFixedFrame * 2
	Local $iMetricsSumY = ($bW > $hGUI_ImageEditor_W) * $iHSscroll + $iYCaption + $iYFixedFrame

	If $bW > $hGUI_ImageEditor_W Or $bH > ($hGUI_ImageEditor_H - $height_delta) Then
		_GUIScrollBars_Init($hGUI_ImageEditor_Child)
		_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_HORZ, 0)
		_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_HORZ, $bW - $hGUI_ImageEditor_W + 61 + $iMetricsSumX)
		_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_VERT, 0)
		_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_VERT, $bH - $hGUI_ImageEditor_H + $iMetricsSumY + $height_delta)

		GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_IE")
		GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_IE")
		GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_IE")

		GUISetState(@SW_SHOW, $hGUI_ImageEditor)
		GUISetState(@SW_SHOW, $hGUI_ImageEditor_Child)

		If $bW > $hGUI_ImageEditor_W Then
			WM_HSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
			$IE_ScrollbarH = True
		EndIf
		If $bH > ($hGUI_ImageEditor_H - $height_delta) Then
			WM_VSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
			$IE_ScrollbarV = True
		EndIf
	Else
		GUISetState(@SW_SHOW, $hGUI_ImageEditor)
		GUISetState(@SW_SHOW, $hGUI_ImageEditor_Child)
	EndIf

	Local Const $hWnd_Title_Icon = _GDIPlus_BitmapCreateFromMemory(_WinTitle_Icon())
	Local Const $hIcon_New = _WinAPI_SetWindowTitleIcon($hWnd_Title_Icon, $hGUI_ImageEditor)

	Local $mx, $my, $mxo, $myo, $aCI, $cc, $hIE_Bmp_Txt, $hIE_Bmp_Ctx, $dx, $dy, $m1, $m2, $iDefaultFontSize = 50, $iMaxFontSize = 250
	Local $aIETxtFont[8] = [7, 0, "Arial", $iDefaultFontSize, 400, 0, 0, 0xFF1010]
	Local Const $hBrush_IE = _GDIPlus_BrushCreateSolid($IE_Brush_Col)
	$hPen_IE = _GDIPlus_PenCreate($IE_Pen_Col, $IE_PenSize)
	$hPenArrow_IE = _GDIPlus_PenCreate($IE_Pen_Col, $IE_PenSize)
	$hPenArrowShadow_IE = _GDIPlus_PenCreate(BitShift(BitAND(0x28F0F0F0, $IE_Pen_Col), 2), $IE_PenSize)
	Local Const $arrow_len = 7 ;Int($bW / 80)
	Local Const $hEndCap = _GDIPlus_ArrowCapCreate($arrow_len, Int($arrow_len * 0.66))
	_GDIPlus_PenSetCustomEndCap($hPenArrow_IE, $hEndCap)
	_GDIPlus_PenSetCustomEndCap($hPenArrowShadow_IE, $hEndCap)
	Local Const $hHL_IE = _GDIPlus_PenCreate($IE_HL_Col, $IE_HLSize)

	Local $hBmp_Tmp = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	Local $hCtxt_Tmp = _GDIPlus_ImageGetGraphicsContext($hBmp_Tmp)
	_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Tmp, 2)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Tmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
	_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)

	Local $hGfx_IE = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($idPic_ImageEditor))
	_GDIPlus_GraphicsSetSmoothingMode($hGfx_IE, 2)
	Local $hGfx_IE_BMP = _GDIPlus_BitmapCreateFromGraphics($bW, $bH, $hGfx_IE)
	Local $hCtx_IE = _GDIPlus_ImageGetGraphicsContext($hGfx_IE_BMP)
	_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE, 2)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)

	$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
	_GDIPlus_GraphicsSetTextRenderingHint($hCtx_IE_BMP, 4)

	Local $startX, $startY, $hGUI_ImageEditor_EnterTxt, $idEdit_IE, $idButton_IE, $aTxt_Size, $aResult, $aBuffer, $keyDLL, $hCursor_IE_tmp
	Local Static $IE_Text
	Local $iMax, $hIE_Bmp_Rot, $hIE_Bmp_Ctx_Rot, $hIE_Matrix, $r
	Local $IE_Child_Active = False, $ESC_IE = False, $ESC_IE_Txt

	$IE_Dummy_Blur = GUICtrlCreateDummy()
	$IE_Dummy_BW = GUICtrlCreateDummy()
	$IE_Dummy_Pix = GUICtrlCreateDummy()
	$IE_Dummy_Ras = GUICtrlCreateDummy()
	$IE_Dummy_Res = GUICtrlCreateDummy()
	$IE_Dummy_Crop = GUICtrlCreateDummy()
	$TB_Button_Chk = GUICtrlCreateDummy()

	Local $blur_go, $idLabel_IE_Blur, $idButton_IE_Blur, $blur_val
	Local $bw_go, $BW_val, $idLabel_IE_BW, $idButton_IE_BW
	Local $pix_go, $hGUI_IE_PixelizeConf, $idInput_IE_PC, $idLabel_Pixel, $idButton_IE_OK, $hBild
	Local $rast_go, $iColor_Rasterize, $hGUI_ImageEditor_Raster, $idLabel_IE_Raster, $idLabel_IE_Raster_Color, $idButton_IE_Color, $idButton_IE_Color_Start, $idButton_IE_PixelizeCB, $idLabel_IE_Raster_Alpha, $idLabel_IE_Raster_Alpha_Input, $IE_Alpha, $idGraphic_Color
	Local $hGUI_IE_Resize, $idGroup_IE_ISize, $idLabel_IE_Current, $idLabel_IE_New, $idLabel_IE_SizeC, $idGroup_IE_INSize, $idLabel_IE_W1, $idLabel_IE_x, $idLabel_IE_H1, $idLabel_IE_W2, $idLabel_IE_P1
	Local $idLabel_IE_P2, $idLabel_IE_H2, $idButton_IE_IHalf, $idButton_IE_IDouble, $idGroup_IE_IMethod, $idCombo_IE, $idButton_IE_Cancel, $IE_Resize = False, $IE_Old_W, $IE_Old_H, $idInputFontsize_IE
	Local $idLabelFontsize_IE, $idUpDown_Fontsize_IE, $idLabelColorChange, $idLabelColor, $iNewFontColor

	$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap($IE_PenSize, $IE_PenSize, BitOR(BitShift(BitAND($IE_Pen_Col, 0x000000FF), -16), BitAND($IE_Pen_Col, 0x0000FF00), BitShift(BitAND($IE_Pen_Col, 0x00FF0000), 16)))
	$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
	If (Not @error) And $aCI[4] = $idPic_ImageEditor Then _WinAPI_SetCursor($hCursor_IE)
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND_IE")
	GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_IE")
	GUIRegisterMsg($WM_SETCURSOR, "WM_SETCURSOR")

	_WinAPI_RedrawWindow($hToolbar_IE)

	Local $t, $u, $test, $iKey, $iZ = 0, $bUndo = False, $iW_rec, $iH_rec, $iW_ell, $iH_ell, $iX, $iY, $hBild, $aWinPos_Crop
	$IE_Old_W = $bW
	$IE_Old_H = $bH

	Do
		If WinActive($hGUI_ImageEditor) Or WinActive($hGUI_ImageEditor_Child) Then
			$iKey = 0
			$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
			Switch $aCI[4]
				Case 0
					$m1 = False
					$m2 = True
				Case Else
					If Not $m1 Then
						ControlClick($hGUI_ImageEditor_Child, "", $idPic_ImageEditor)
						$m1 = True
						$m2 = False
					EndIf
			EndSwitch
			If $aCI[2] And $aCI[4] = $idPic_ImageEditor And WinActive($hGUI_ImageEditor_Child) Then
				_GDIPlus_BitmapDispose($IE_Bmp_Undo)
				$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
				If Not $IE_Bmp_Undo Or @error Then
					MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
							$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
					ExitLoop
				EndIf
				Switch $IE_Tool_Selected
					Case 1 ;pen
						_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $IE_Old_W, $IE_Old_H)
						$mxo = MouseGetPos(0) + $IE_PenSize / 2
						$myo = MouseGetPos(1) + $IE_PenSize / 2
						Do
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							_GDIPlus_GraphicsDrawLine($hGfx_IE, ($aCI[0] + $IE_PenSize / 2) + $IE_offset_x, ($aCI[1] + $IE_PenSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hPen_IE)
							_GDIPlus_GraphicsDrawLine($hCtx_IE, ($aCI[0] + $IE_PenSize / 2) + $IE_offset_x, ($aCI[1] + $IE_PenSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hPen_IE)
							_GDIPlus_GraphicsDrawLine($hCtx_IE_BMP, ($aCI[0] + $IE_PenSize / 2) + $IE_offset_x, ($aCI[1] + $IE_PenSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hPen_IE)
							$mxo = $aCI[0] + $IE_PenSize / 2
							$myo = $aCI[1] + $IE_PenSize / 2
						Until Not $aCI[2] * Sleep(1)
						_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						$IE_Resize = False
						$iZ += 1
						$bUndo = True
					Case 2 ;highlighter
						_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $IE_Old_W, $IE_Old_H)
						$mxo = MouseGetPos(0) + $IE_HLSize / 2
						$myo = MouseGetPos(1) + $IE_HLSize / 2
						Do
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							_GDIPlus_GraphicsFillRect($hGfx_IE, $aCI[0] + $IE_offset_x, $aCI[1] + $IE_offset_y, $IE_Brush_w, $IE_Brush_h, $hBrush_IE)
							_GDIPlus_GraphicsFillRect($hCtx_IE, $aCI[0] + $IE_offset_x, $aCI[1] + $IE_offset_y, $IE_Brush_w, $IE_Brush_h, $hBrush_IE)
							_GDIPlus_GraphicsFillRect($hCtx_IE_BMP, $aCI[0] + $IE_offset_x, $aCI[1] + $IE_offset_y, $IE_Brush_w, $IE_Brush_h, $hBrush_IE)
;~ 							_GDIPlus_GraphicsDrawLine($hGfx_IE, ($aCI[0] + $IE_HLSize / 2) + $IE_offset_x, ($aCI[1] + $IE_HLSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hHL_IE)
;~ 							_GDIPlus_GraphicsDrawLine($hCtx_IE, ($aCI[0] + $IE_HLSize / 2) + $IE_offset_x, ($aCI[1] + $IE_HLSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hHL_IE)
;~ 							_GDIPlus_GraphicsDrawLine($hCtx_IE_BMP, ($aCI[0] + $IE_HLSize / 2) + $IE_offset_x, ($aCI[1] + $IE_HLSize / 2) + $IE_offset_y, $mxo + $IE_offset_x, $myo + $IE_offset_y, $hHL_IE)
							$mxo = $aCI[0] + $IE_HLSize / 2
							$myo = $aCI[1] + $IE_HLSize / 2
						Until Not $aCI[2] * Sleep(1)
						_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)

;~ 						Do
;~ 							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
;~ 							_GDIPlus_GraphicsFillRect($hGfx_IE, $aCI[0] + $IE_offset_x, $aCI[1] + $IE_offset_y, $IE_Brush_w, $IE_Brush_h, $hBrush_IE)
;~ 							_GDIPlus_GraphicsFillRect($hCtx_IE, $aCI[0] + $IE_offset_x, $aCI[1] + $IE_offset_y, $IE_Brush_w, $IE_Brush_h, $hBrush_IE)
;~ 						Until Not $aCI[2] * Sleep(30)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						$IE_Resize = False
						$iZ += 1
						$bUndo = True
					Case 3 ;rectangle
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						$startX = MouseGetPos(0) - $IE_offset_x * -1 + $IE_PenSize / 2
						$mxo = $startX
						$startY = MouseGetPos(1) - $IE_offset_y * -1 + $IE_PenSize / 2
						$myo = $startY
						Do
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							$mx = $aCI[0] - $IE_offset_x * -1 + $IE_PenSize / 2
							$my = $aCI[1] - $IE_offset_y * -1 + $IE_PenSize / 2
							If $mx <> $mxo Or $my <> $myo Then
								_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $IE_Old_W, $IE_Old_H)
								$iW_rec = Abs($startX - $mx)
								$iH_rec = Abs($startY - $my)
								If $startX < $mx And $startY < $my Then
									$iX = $startX
									$iY = $startY
								ElseIf $startX > $mx And $startY < $my Then
									$iX = $mx
									$iY = $startY
								ElseIf $startX < $mx And $startY > $my Then
									$iX = $startX
									$iY = $my
								Else ;$startX > $mx And $startY > $my
									$iX = $mx
									$iY = $my
								EndIf
								_GDIPlus_GraphicsDrawRect($hCtx_IE, $iX, $iY, $iW_rec, $iH_rec, $hPen_IE)
								_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hGfx_IE_BMP, 0, 0, $bW, $bH)
								$mxo = $mx
								$myo = $my
							EndIf
						Until Not $aCI[2] * Sleep(10)

						_GDIPlus_GraphicsDrawRect($hCtx_IE_BMP, $iX, $iY, $iW_rec, $iH_rec, $hPen_IE)
						_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)

						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)

						$IE_Resize = False
						$iZ += 1
						$bUndo = True
					Case 4 ;ellipse
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						$startX = MouseGetPos(0) - $IE_offset_x * -1 + $IE_PenSize / 2
						$mxo = $startX
						$startY = MouseGetPos(1) - $IE_offset_y * -1 + $IE_PenSize / 2
						$myo = $startY
						Do
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							$mx = $aCI[0] - $IE_offset_x * -1 + $IE_PenSize / 2
							$my = $aCI[1] - $IE_offset_y * -1 + $IE_PenSize / 2
							If $mx <> $mxo Or $my <> $myo Then
								_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $IE_Old_W, $IE_Old_H)
								$iW_ell = Abs($startX - $mx)
								$iH_ell = Abs($startY - $my)
								If $startX < $mx And $startY < $my Then
									$iX = $startX
									$iY = $startY
								ElseIf $startX > $mx And $startY < $my Then
									$iX = $mx
									$iY = $startY
								ElseIf $startX < $mx And $startY > $my Then
									$iX = $startX
									$iY = $my
								Else ;$startX > $mx And $startY > $my
									$iX = $mx
									$iY = $my
								EndIf
								_GDIPlus_GraphicsDrawEllipse($hCtx_IE, $iX, $iY, $iW_ell, $iH_ell, $hPen_IE)
								_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hGfx_IE_BMP, 0, 0, $bW, $bH)
								$mxo = $mx
								$myo = $my
							EndIf
						Until Not $aCI[2] * Sleep(10)

						_GDIPlus_GraphicsDrawEllipse($hCtx_IE_BMP, $iX, $iY, $iW_ell, $iH_ell, $hPen_IE)
						_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						$iZ += 1
						$bUndo = True
					Case 5 ;arrow
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						$startX = MouseGetPos(0) - $IE_offset_x * -1 + $IE_PenSize / 2
						$mxo = $startX
						$startY = MouseGetPos(1) - $IE_offset_y * -1 + $IE_PenSize / 2
						$myo = $startY
						Do
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							$mx = $aCI[0] - $IE_offset_x * -1 + $IE_PenSize / 2
							$my = $aCI[1] - $IE_offset_y * -1 + $IE_PenSize / 2
							If $mx <> $mxo Or $my <> $myo Then
								_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $IE_Old_W, $IE_Old_H)
								_GDIPlus_GraphicsDrawLine($hCtx_IE, $startX, $startY, $mx, $my, $hPenArrow_IE)
								_GDIPlus_GraphicsDrawLine($hCtx_IE, $startX + 10 + $IE_PenSize, $startY + 10 + $IE_PenSize, $mx + 10 + $IE_PenSize, $my + 10 + $IE_PenSize, $hPenArrowShadow_IE)
								_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hGfx_IE_BMP, 0, 0, $bW, $bH)
								$mxo = $mx
								$myo = $my
							EndIf
						Until Not $aCI[2] * Sleep(10)

						_GDIPlus_GraphicsDrawLine($hCtx_IE_BMP, $startX, $startY, $mx, $my, $hPenArrow_IE)
						_GDIPlus_GraphicsDrawLine($hCtx_IE_BMP, $startX + 10 + $IE_PenSize, $startY + 10 + $IE_PenSize, $mx + 10 + $IE_PenSize, $my + 10 + $IE_PenSize, $hPenArrowShadow_IE)
						_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						$IE_Resize = False
						$iZ += 1
						$bUndo = True
				EndSwitch
			EndIf

			Switch GUIGetMsg()
				Case $GUI_EVENT_CLOSE
					If $ESC_IE Then
						$ESC_IE = False
					Else
						ExitLoop
					EndIf
				Case $TB_Button_Chk
					Switch GUICtrlRead($TB_Button_Chk)
						Case $idSave_IE
							$skip_display = True
							$hWnd_GUI = $hGUI_ImageEditor
							Save_Bitmap()
						Case $idCopy_IE
							Pic2Clipboard()
						Case $idSend_IE
							OpenMailClient()
						Case $idUndo_IE
							If Not $bUndo Then ContinueLoop
							If $IE_Resize Then
								$bW = $IE_Old_W
								$bH = $IE_Old_H
								If $bW < $hGUI_ImageEditor_W Then
									$IE_offset_x = -($hGUI_ImageEditor_W - $bW) / 2
								Else
									$IE_offset_x = 0
								EndIf
								If $bH < ($hGUI_ImageEditor_H - $height_delta) Then
									$IE_offset_y = -(($hGUI_ImageEditor_H - $height_delta) - $bH) / 2
								Else
									$IE_offset_y = 0
								EndIf
								GUICtrlSetPos($idPic_ImageEditor, $IE_offset_x * -1, $IE_offset_y * -1, $bW, $bH)

								$iMetricsSumX = ($bH > ($hGUI_ImageEditor_H - $height_delta)) * $iVSscroll + $iXFixedFrame * 2
								$iMetricsSumY = ($bW > $hGUI_ImageEditor_W) * $iHSscroll + $iYCaption + $iYFixedFrame

								_Functions_RemoveScrollBars($hGUI_ImageEditor_Child)
								$IE_ScrollbarH = False
								$IE_ScrollbarV = False

								If $bW > $hGUI_ImageEditor_W Or $bH > ($hGUI_ImageEditor_H - $height_delta) Then
									_GUIScrollBars_Init($hGUI_ImageEditor_Child)
									_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_HORZ, 0)
									_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_HORZ, $bW - $hGUI_ImageEditor_W + 61 + $iMetricsSumX)
									_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_VERT, 0)
									_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_VERT, $bH - $hGUI_ImageEditor_H + $iMetricsSumY + $height_delta - 1)
									GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_IE")
									GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_IE")
									GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_IE")

									If $bW > $hGUI_ImageEditor_W Then
										WM_HSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
										$IE_ScrollbarH = True
									EndIf
									If $bH > ($hGUI_ImageEditor_H - $height_delta) Then
										WM_VSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
										$IE_ScrollbarV = True
									EndIf
									_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $IE_Bmp_Undo, 0, 0, $bW, $bH)
									_GDIPlus_GraphicsDrawImageRect($hCtx_IE_BMP, $hGfx_IE_BMP, 0, 0, $bW, $bH)
								Else
									GUIRegisterMsg($WM_HSCROLL, "")
									GUIRegisterMsg($WM_VSCROLL, "")
									GUIRegisterMsg($WM_MOUSEWHEEL, "")
								EndIf
								$hBmp = _GDIPlus_BitmapClone($IE_Bmp_Undo, $bW, $bH)
								_GDIPlus_BitmapDispose($hGfx_IE_BMP)
								_GDIPlus_ImageDispose($hCtx_IE_BMP)
								_GDIPlus_GraphicsDispose($hGfx_IE)
								_GDIPlus_GraphicsDispose($hCtx_IE)
								$hGfx_IE = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($idPic_ImageEditor))
								$hGfx_IE_BMP = _GDIPlus_BitmapCreateFromGraphics($bW, $bH, $hGfx_IE)
								$hCtx_IE = _GDIPlus_ImageGetGraphicsContext($hGfx_IE_BMP)
								$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
								_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
								_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
								_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
								_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE, 2)
								_GDIPlus_GraphicsSetSmoothingMode($hGfx_IE, 2)
							EndIf
							_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $IE_Bmp_Undo, 0, 0, $bW, $bH)
							_GDIPlus_GraphicsDrawImageRect($hCtx_IE_BMP, $hGfx_IE_BMP, 0, 0, $bW, $bH)
							CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
							WinSetTitle($hGUI_ImageEditor, "", "AutoIt Windows Screenshooter - " & $aTranslations[39][$iLang] & " / " & $aTranslations[82][$iLang] & $bW & "x" & $bH & $aTranslations[78][$iLang])
							$iZ -= 1
							$bUndo = False
						Case $idPen_IE
							$IE_Tool_Selected = 1
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idUndo_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idHighlighter_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idRectangle_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idEllipse_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idArrow_IE, False)
							_WinAPI_DestroyCursor($hCursor_IE)
							$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap($IE_PenSize, $IE_PenSize, BitOR(BitShift(BitAND($IE_Pen_Col, 0x000000FF), -16), BitAND($IE_Pen_Col, 0x0000FF00), BitShift(BitAND($IE_Pen_Col, 0x00FF0000), 16)))
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							If (Not @error) And $aCI[4] = $idPic_ImageEditor Then _WinAPI_SetCursor($hCursor_IE)
						Case $idHighlighter_IE
							$IE_Tool_Selected = 2
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idUndo_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idHighlighter_IE)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idRectangle_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idEllipse_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idArrow_IE, False)
							_WinAPI_DestroyCursor($hCursor_IE)
							$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap(16, $IE_HLSize, $IE_HL_Col_BGR)
							$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
							If (Not @error) And $aCI[4] = $idPic_ImageEditor Then _WinAPI_SetCursor($hCursor_IE)
						Case $idRectangle_IE
							$IE_Tool_Selected = 3
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idUndo_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idHighlighter_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idRectangle_IE)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idEllipse_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idArrow_IE, False)
						Case $idEllipse_IE
							$IE_Tool_Selected = 4
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idUndo_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idHighlighter_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idRectangle_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idEllipse_IE)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idArrow_IE, False)
						Case $idArrow_IE
							$IE_Tool_Selected = 5
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idUndo_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idPen_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idHighlighter_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idRectangle_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idEllipse_IE, False)
							_GUICtrlToolbar_CheckButton($hToolbar_IE, $idArrow_IE)
						Case $idColor_IE
							$cc = _ChooseColor(2, 0xFF0000, 2, $hGUI_ImageEditor)
							If Not @error Then
								$IE_Pen_Col = "0xF0" & Hex($cc, 6)
								_GDIPlus_PenSetColor($hPen_IE, $IE_Pen_Col)
								_GDIPlus_PenSetColor($hPenArrow_IE, $IE_Pen_Col)
								_GDIPlus_PenSetColor($hPenArrowShadow_IE, BitShift(BitAND(0x28F0F0F0, $IE_Pen_Col), 2))
								$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap($IE_PenSize, $IE_PenSize, BitOR(BitShift(BitAND($IE_Pen_Col, 0x000000FF), -16), BitAND($IE_Pen_Col, 0x0000FF00), BitShift(BitAND($IE_Pen_Col, 0x00FF0000), 16)))
								$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
								If (Not @error) And $aCI[4] = $idPic_ImageEditor Then _WinAPI_SetCursor($hCursor_IE)
								_WinAPI_RedrawWindow($hToolbar_IE)
							EndIf
						Case $idText_IE
							$bLocked_IE = True
							$hGUI_ImageEditor_EnterTxt = GUICreate($aTranslations[160][$iLang], 600, 474, -1, -1, $WS_SYSMENU, $WS_EX_TOOLWINDOW, $hGUI_ImageEditor)
							$idEdit_IE = GUICtrlCreateEdit($IE_Text, 2, 2, 590, 390)
							GUICtrlSetFont(-1, $aIETxtFont[3] * $aDPI[0], $aIETxtFont[4], $aIETxtFont[1], $aIETxtFont[2], 5)
							GUICtrlSetColor(-1, $aIETxtFont[7])
							$idButton_IE = GUICtrlCreateButton($aTranslations[161][$iLang], 2, 395, 304, 44)
							GUICtrlSetFont(-1, 20 * $aDPI[0])
							$idLabelColor = GUICtrlCreateLabel($aTranslations[156][$iLang], 305, 412, 60, 20, $SS_RIGHT)
							GUICtrlSetFont(-1, 10 * $aDPI[0])
							$idLabelColorChange = GUICtrlCreateLabel("", 370, 410, 20, 20)
							GUICtrlSetBkColor(-1, $aIETxtFont[7])
							$idLabelFontsize_IE = GUICtrlCreateLabel($aTranslations[162][$iLang], 393, 412, 45, 20, $SS_RIGHT)
							GUICtrlSetFont(-1, 10 * $aDPI[0])
							$idInputFontsize_IE = GUICtrlCreateInput($aIETxtFont[3], 440, 410, 52, 20, BitOR($ES_NUMBER, $ES_CENTER))
							GUICtrlSetFont(-1, 10 * $aDPI[0])
							GUICtrlSetLimit(-1, $iMaxFontSize, 8)
							GUICtrlSetTip(-1, $aTranslations[163][$iLang])
							$idUpDown_Fontsize_IE = GUICtrlCreateUpdown($idInputFontsize_IE)
							GUICtrlSetLimit(-1, $iMaxFontSize, 8)
							GUICtrlSetTip(-1, $aTranslations[164][$iLang])
							GUISetState(@SW_SHOW, $hGUI_ImageEditor_EnterTxt)
							Do
								Switch GUIGetMsg()
									Case $GUI_EVENT_CLOSE
;~ 										$IE_Text = ""
										ExitLoop
									Case $idButton_IE
										$IE_Text = GUICtrlRead($idEdit_IE)
										ExitLoop
									Case $idUpDown_Fontsize_IE
										GUICtrlSetFont($idEdit_IE, GUICtrlRead($idInputFontsize_IE), $aIETxtFont[4], $aIETxtFont[1], $aIETxtFont[2], 5)
									Case $idInputFontsize_IE
										GUICtrlSetData($idInputFontsize_IE, Min(Max(GUICtrlRead($idInputFontsize_IE), 8), $iMaxFontSize))
										GUICtrlSetFont($idEdit_IE, GUICtrlRead($idInputFontsize_IE), $aIETxtFont[4], $aIETxtFont[1], $aIETxtFont[2], 5)
									Case $idLabelColorChange
										$iNewFontColor = _ChooseColor(2, $aIETxtFont[7], 2, $hGUI_ImageEditor_EnterTxt)
										If $iNewFontColor <> -1 Then
											GUICtrlSetBkColor($idLabelColorChange, $iNewFontColor)
											$aIETxtFont[7] = $iNewFontColor
											GUICtrlSetColor($idEdit_IE, $aIETxtFont[7])
										EndIf
								EndSwitch
							Until False
							$aIETxtFont[3] = GUICtrlRead($idInputFontsize_IE)
							GUIDelete($hGUI_ImageEditor_EnterTxt)
							If $IE_Text <> "" Then
								_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)
								$aTxt_Size = GetStringSize($IE_Text, $aIETxtFont[2], $aIETxtFont[3], $aIETxtFont[1])
								$aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aTxt_Size[0], "int", $aTxt_Size[1], "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
								$hIE_Bmp_Txt = $aResult[6]
								$hIE_Bmp_Ctx = _GDIPlus_ImageGetGraphicsContext($hIE_Bmp_Txt)
								_GDIPlus_GraphicsSetPixelOffsetMode($hIE_Bmp_Ctx, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
								_GDIPlus_GraphicsSetSmoothingMode($hIE_Bmp_Ctx, 2)
								DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hIE_Bmp_Ctx, "int", 4)
								_GDIPlus_GraphicsDrawString2($hIE_Bmp_Ctx, $hIE_Bmp_Txt, $IE_Text, $aIETxtFont[2], $aIETxtFont[3], $aIETxtFont[1], 0xFF000000 + $aIETxtFont[7])

								$hCursor_IE_tmp = _WinAPI_CopyImage($hCursor_IE, $IMAGE_CURSOR)
								_WinAPI_DestroyCursor($hCursor_IE)

								$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap(4, 4, BitOR(0x10000 * BitXOR(BitAND(BitShift($aIETxtFont[7], 16), 0xFF), 0xFF), 0x100 * BitXOR(BitAND(BitShift($aIETxtFont[7], 8), 0xFF), 0xFF), BitXOR(BitAND($aIETxtFont[7], 0xFF), 0xFF)))

								_GDIPlus_BitmapDispose($IE_Bmp_Undo)
								$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
								If Not $IE_Bmp_Undo Or @error Then
									MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
											$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
									ExitLoop
								EndIf
								If not WinActive($hGUI_ImageEditor_Child) Then WinActivate($hGUI_ImageEditor_Child)
								$ESC_IE_Txt = False
								Do
									$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
									$mx = $aCI[0] - $IE_offset_x * -1 - $aTxt_Size[0] / 2
									$my = $aCI[1] - $IE_offset_y * -1 - $aTxt_Size[1]
									If $mx <> $mxo Or $my <> $myo Then
										_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $bW, $bH)
										_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hIE_Bmp_Txt, $mx, $my, $aTxt_Size[0], $aTxt_Size[1])
										_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hGfx_IE_BMP, 0, 0, $bW, $bH)
										$mxo = $mx
										$myo = $my
									EndIf
									If _IsPressed("1B", $dll) Then $ESC_IE_Txt = True
								Until ($aCI[2] * Sleep(20)) Or $ESC_IE_Txt

								If Not $ESC_IE_Txt Then
									$iMax = 2 * Max($aTxt_Size[0], $aTxt_Size[1])
									$aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iMax, "int", $iMax, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
									$hIE_Bmp_Rot = $aResult[6]
									$hIE_Bmp_Ctx_Rot = _GDIPlus_ImageGetGraphicsContext($hIE_Bmp_Rot)
									_GDIPlus_GraphicsSetInterpolationMode($hIE_Bmp_Ctx_Rot, 7)
									_GDIPlus_GraphicsSetPixelOffsetMode($hIE_Bmp_Ctx_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
									$hIE_Matrix = _GDIPlus_MatrixCreate()
									_GDIPlus_MatrixTranslate($hIE_Matrix, $iMax / 2, $iMax / 2)
									$mxo = MouseGetPos(0)
									$r = 0
									Do
										$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
										_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hBmp_Tmp, 0, 0, $bW, $bH)
										_GDIPlus_GraphicsClear($hIE_Bmp_Ctx_Rot, 0x00000000)
										If $mxo < $aCI[0] Then
											$r = 2
											$mxo = $aCI[0]
										ElseIf $mxo > $aCI[0] Then
											$r = -2
											$mxo = $aCI[0]
										Else
											$r = 0
										EndIf

										_GDIPlus_MatrixRotate($hIE_Matrix, $r)
										_GDIPlus_GraphicsSetTransform($hIE_Bmp_Ctx_Rot, $hIE_Matrix)
										_GDIPlus_GraphicsDrawImageRect($hIE_Bmp_Ctx_Rot, $hIE_Bmp_Txt, -$aTxt_Size[0] / 2, -$aTxt_Size[1] / 2, $aTxt_Size[0], $aTxt_Size[1])
										_GDIPlus_GraphicsDrawImageRect($hCtx_IE, $hIE_Bmp_Rot, $mx - $iMax / 2 + $aTxt_Size[0] / 2, $my - $iMax / 2 + $aTxt_Size[1] / 2, $iMax, $iMax)
										_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hGfx_IE_BMP, 0, 0, $bW, $bH)
									Until (Not $aCI[2]) * Sleep(20)

									_GDIPlus_GraphicsDrawImageRect($hCtx_IE_BMP, $hIE_Bmp_Rot, $mx - $iMax / 2 + $aTxt_Size[0] / 2, $my - $iMax / 2 + $aTxt_Size[1] / 2, $iMax, $iMax)
									_GDIPlus_GraphicsClear($hCtxt_Tmp, 0xFF000000 + $iGUI_IE_BGColor)
									_GDIPlus_GraphicsDrawImageRect($hCtxt_Tmp, $hBmp, 0, 0, $bW, $bH)


									CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
									_GDIPlus_MatrixDispose($hIE_Matrix)
									_GDIPlus_BitmapDispose($hIE_Bmp_Rot)
									_GDIPlus_GraphicsDispose($hIE_Bmp_Ctx_Rot)
									_WinAPI_DestroyCursor($hCursor_IE)
									$hCursor_IE = $hCursor_IE_tmp
									$bUndo = True
								Else
									_GDIPlus_GraphicsDrawImageRect($hGfx_IE, $hBmp, 0, 0, $bW, $bH)
								EndIf
								_GDIPlus_BitmapDispose($hIE_Bmp_Txt)
								_GDIPlus_GraphicsDispose($hIE_Bmp_Ctx)
							EndIf
							$bLocked_IE = False
						Case $idText_Conf_IE
							$aBuffer = $aIETxtFont ;save array because when _ChooseFont() has been cancelled the array will be deleted!
							$aIETxtFont = _ChooseFont("Arial", $iDefaultFontSize, 0x0000FF) ;BGR
							If @error Then $aIETxtFont = $aBuffer
					EndSwitch
				Case $IE_Dummy_Blur
					$blur_go = True
					$hGUI_ImageEditor_Blur = GUICreate($aTranslations[165][$iLang], 332, 118, -1, -1, BitOR($WS_SYSMENU, $WS_GROUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST), $hGUI_ImageEditor)
					$hSlider_IE_Blur = _GUICtrlSlider_Create($hGUI_ImageEditor_Blur, 10, 40, 310, 45, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_BOTH, $TBS_ENABLESELRANGE, $WS_TABSTOP))
					$iSliderBlur_Min = 0
					$iSliderBlur_Max = 20
					$iInputBlur = 5
					If @OSBuild < 7600 Then
						$iSliderBlur_Min = 1
						$iSliderBlur_Max = 900
						$iInputBlur = 1 - 0.333
					EndIf
					_GUICtrlSlider_SetRangeMin($hSlider_IE_Blur, $iSliderBlur_Min)
					_GUICtrlSlider_SetRangeMax($hSlider_IE_Blur, $iSliderBlur_Max)
					If @OSBuild < 7600 Then
						_GUICtrlSlider_SetPos($hSlider_IE_Blur, 1000 - 333)
					Else
						_GUICtrlSlider_SetPos($hSlider_IE_Blur, $iInputBlur)
					EndIf
					$idLabel_IE_Blur = GUICtrlCreateLabel($aTranslations[166][$iLang], 20, 12, 83, 23)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idInput_IE_Blur = GUICtrlCreateInput($iInputBlur, 112, 8, 95, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY))
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idButton_IE_Blur = GUICtrlCreateButton("Start", 224, 8, 80, 27)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					GUISetState(@SW_SHOW, $hGUI_ImageEditor_Blur)
					ControlFocus($hGUI_ImageEditor_Blur, "", $idButton_IE_Blur)

					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE
								$blur_go = False
								ExitLoop
							Case $idButton_IE_Blur
								If @OSBuild < 7600 Then
									$blur_val = (1000 - _GUICtrlSlider_GetPos($hSlider_IE_Blur)) / 1000
								Else
									$blur_val = _GUICtrlSlider_GetPos($hSlider_IE_Blur)
								EndIf
								ExitLoop
						EndSwitch

						$aCI = GUIGetCursorInfo($hGUI_ImageEditor_Blur)
						If $aCI[2] Then
							If @OSBuild < 7600 Then
								GUICtrlSetData($idInput_IE_Blur, Round(($IE_tmp / 1000), 4))
							Else
								GUICtrlSetData($idInput_IE_Blur, $IE_tmp)
							EndIf
						EndIf
					WEnd
					GUIDelete($hGUI_ImageEditor_Blur)

					If $blur_go Then
						_GDIPlus_BitmapDispose($IE_Bmp_Undo)
						$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
						If Not $IE_Bmp_Undo Or @error Then
							MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
									$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
							ExitLoop
						EndIf
						If @OSBuild < 7600 Then
							$hBild = _Blur($hBmp, $bW, $bH, 0, 0, 0, 0, $blur_val)
						Else
							$hBild = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
							Local $hEffect = _GDIPlus_EffectCreateBlur($blur_val)
							_GDIPlus_BitmapApplyEffect($hBild, $hEffect)
							_GDIPlus_EffectDispose($hEffect)
						EndIf
						_GDIPlus_BitmapDispose($hBmp)
						$hBmp = $hBild
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
						$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
					EndIf
					WinActivate($hGUI_ImageEditor_Child)
					$IE_Resize = False
					$iZ += 1
					$bUndo = True
				Case $IE_Dummy_BW
					$BW_val = 160
					$bw_go = True
					$hGUI_ImageEditor_BW = GUICreate($aTranslations[167][$iLang], 332, 118, -1, -1, BitOR($WS_SYSMENU, $WS_GROUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST), $hGUI_ImageEditor)
					$hSlider_IE_BW = _GUICtrlSlider_Create($hGUI_ImageEditor_BW, 10, 40, 310, 45, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_BOTH, $TBS_ENABLESELRANGE, $WS_TABSTOP))
					_GUICtrlSlider_SetRangeMin($hSlider_IE_BW, 1)
					_GUICtrlSlider_SetRangeMax($hSlider_IE_BW, 255)
					_GUICtrlSlider_SetPos($hSlider_IE_BW, $BW_val)
					$idLabel_IE_BW = GUICtrlCreateLabel($aTranslations[168][$iLang], 20, 2, 83, 33)
					GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
					$idInput_IE_BW = GUICtrlCreateInput($BW_val, 112, 8, 95, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY))
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idButton_IE_BW = GUICtrlCreateButton($aTranslations[109][$iLang], 224, 8, 80, 27)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					GUISetState(@SW_SHOW, $hGUI_ImageEditor_BW)
					ControlFocus($hGUI_ImageEditor_BW, "", $idButton_IE_BW)

					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE
								$bw_go = False
								GUIDelete($hGUI_ImageEditor_BW)
								ExitLoop
							Case $idButton_IE_BW
								$BW_val = _GUICtrlSlider_GetPos($hSlider_IE_BW)
								GUIDelete($hGUI_ImageEditor_BW)
								ExitLoop
						EndSwitch
						$aCI = GUIGetCursorInfo($hGUI_ImageEditor_BW)
						If $aCI[2] Then GUICtrlSetData($idInput_IE_BW, $IE_tmp)
					WEnd

					If $bw_go Then
						_GDIPlus_BitmapDispose($IE_Bmp_Undo)
						$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
						If Not $IE_Bmp_Undo Or @error Then
							MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
									$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
							ExitLoop
						EndIf
						_GDIPlus_BitmapCreateBnW($hBmp, $BW_val, True)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
						$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
					EndIf
					WinActivate($hGUI_ImageEditor_Child)
					$IE_Resize = False
					$iZ += 1
					$bUndo = True
				Case $IE_Dummy_Pix
					$pix_go = True
					$hGUI_IE_PixelizeConf = GUICreate($aTranslations[169][$iLang], 294 * $aDPI[1], 43, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST), $hGUI_ImageEditor)
					$idInput_IE_PC = GUICtrlCreateInput($IE_Pix_Size, 78, 10, 41, 21, BitOR($ES_CENTER, $ES_NUMBER))
					$idLabel_Pixel = GUICtrlCreateLabel($aTranslations[170][$iLang], 16, 10, 62, 23)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idButton_IE_PixelizeCB = GUICtrlCreateCheckbox($aTranslations[172][$iLang], 140, 12, 97 * $aDPI[1], 17)
					GUICtrlSetState(-1, $GUI_CHECKED)
					GUICtrlSetTip(-1, $aTranslations[171][$iLang])
					$idButton_IE_OK = GUICtrlCreateButton($aTranslations[173][$iLang], 244 * $aDPI[1], 8, 43, 25)
					GUISetState(@SW_SHOW, $hGUI_IE_PixelizeConf)
					ControlFocus($hGUI_IE_PixelizeConf, "", $idButton_IE_OK)

					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE
								Local $pix_go = False
								ExitLoop
							Case $idButton_IE_OK
								ExitLoop
						EndSwitch
					WEnd
					If $pix_go Then
						_GDIPlus_BitmapDispose($IE_Bmp_Undo)
						$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
						If Not $IE_Bmp_Undo Or @error Then
							MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
									$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
							ExitLoop
						EndIf
						_GDIPlus_PixelateBitmap($hBmp, Min(GUICtrlRead($idInput_IE_PC), Min($bW, $bH)), BitAND(GUICtrlRead($idButton_IE_PixelizeCB), $GUI_CHECKED))
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						GUIDelete($hGUI_IE_PixelizeConf)
						_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
						$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
					Else
						GUIDelete($hGUI_IE_PixelizeConf)
					EndIf
					WinActivate($hGUI_ImageEditor_Child)
					$IE_Resize = False
					$iZ += 1
					$bUndo = True
				Case $IE_Dummy_Ras
					$rast_go = True
					$iColor_Rasterize = 0x000000
					$hGUI_ImageEditor_Raster = GUICreate($aTranslations[174][$iLang], 378, 100, -1, -1, BitOR($WS_SYSMENU, $WS_GROUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST), $hGUI_ImageEditor)
					$idLabel_IE_Raster = GUICtrlCreateLabel($aTranslations[175][$iLang], 6, 10, 86, 56, $SS_CENTER)
					GUICtrlSetFont(-1, 18 * $aDPI[0], 400, 0, "Times New Roman")
					$idButton_IE_Color = GUICtrlCreateButton($aTranslations[176][$iLang], 176, 8, 80, 28)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idButton_IE_Color_Start = GUICtrlCreateButton($aTranslations[109][$iLang], 286, 8, 80, 60)
					GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, "Times New Roman")
					$idGraphic_Color = GUICtrlCreateGraphic(100, 8, 61, 61, $SS_ETCHEDFRAME)
					$idLabel_IE_Raster_Color = GUICtrlCreateLabel("", 104, 12, 52, 52)
					GUICtrlSetBkColor(-1, $iColor_Rasterize)
					$idLabel_IE_Raster_Alpha = GUICtrlCreateLabel($aTranslations[177][$iLang], 176, 46, 40, 15)
					GUICtrlSetFont(-1, 11 * $aDPI[0])
					$idLabel_IE_Raster_Alpha_Input = GUICtrlCreateInput(128, 220, 45, 30, 20, $ES_NUMBER)
					GUICtrlSetLimit(-1, 3, 1)
					GUICtrlSetTip(-1, $aTranslations[178][$iLang])
					GUISetState(@SW_SHOW, $hGUI_ImageEditor_Raster)
					ControlFocus($hGUI_ImageEditor_Raster, "", $idButton_IE_Color_Start)

					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE
								$rast_go = False
								ExitLoop
							Case $idButton_IE_Color, $idLabel_IE_Raster_Color
								$iColor_Rasterize = _ChooseColor(2, $iColor_Rasterize, 2)
								If Not @error Then GUICtrlSetBkColor($idLabel_IE_Raster_Color, $iColor_Rasterize)
							Case $idButton_IE_Color_Start
								ExitLoop
							Case $idLabel_IE_Raster_Alpha_Input
								If GUICtrlRead($idLabel_IE_Raster_Alpha_Input) > 255 Then GUICtrlSetData($idLabel_IE_Raster_Alpha_Input, 255)
						EndSwitch
					WEnd
					$IE_Alpha = Int(GUICtrlRead($idLabel_IE_Raster_Alpha_Input))
					If $IE_Alpha > 255 Then $IE_Alpha = 255

					GUIDelete($hGUI_ImageEditor_Raster)
					If $rast_go Then
						_GDIPlus_BitmapDispose($IE_Bmp_Undo)
						$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
						If Not $IE_Bmp_Undo Or @error Then
							MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
									$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
							ExitLoop
						EndIf
						_GDIPlus_RasterizeBitmap($hBmp, $iColor_Rasterize, $IE_Alpha)
						CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
						_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
						$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
					EndIf
					WinActivate($hGUI_ImageEditor_Child)
					$IE_Resize = False
					$iZ += 1
					$bUndo = True
				Case $IE_Dummy_Crop
					Local $iW_crop = Round($bW / 2, 0), $iH_crop = Round($bH / 2, 0)
					$iH_crop = $iH_crop > ($hGUI_ImageEditor_H - $height_delta) ? ($hGUI_ImageEditor_H - $height_delta) : $iH_crop

;~ 					$iPosX_Crop = $IE_offset_x * -1 + $bW * 0.05
;~ 					$iPosY_Crop = (($hGUI_ImageEditor_H - $bH) - $height_delta) / 2 + $bH * 0.05
;~ 					If $iW_crop > $hGUI_ImageEditor_W Then
;~ 						$iW_crop = $hGUI_ImageEditor_W / 2
						$iPosX_Crop = ($hGUI_ImageEditor_W - $iW_crop) / 2
;~ 					EndIf
;~ 					If $iH_crop > $hGUI_ImageEditor_H Then
;~ 						$iH_crop = $hGUI_ImageEditor_H / 2
						$iPosY_Crop = ($hGUI_ImageEditor_H - $iH_crop) / 2
;~ 					EndIf

					$iDeltaX_Crop = 0
					$iDeltaY_Crop = 0
					$hGUI_IE_Crop = GUICreate("", $iW_crop, $iH_crop, $iPosX_Crop, $iPosY_Crop)
					GUISetStyle(BitOR($WS_POPUP, $WS_SIZEBOX, $WS_CHILD, $WS_CLIPCHILDREN, $WS_VISIBLE), BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI_IE_Crop)
					_WinAPI_SetParent($hGUI_IE_Crop, $hGUI_ImageEditor_Child)
					$iLable_CropMove = GUICtrlCreateLabel("", 0, 0, WinGetPos($hGUI_IE_Crop)[2], WinGetPos($hGUI_IE_Crop)[3], $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
;~ 					If @OSBuild < 9700 Then DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($iLable_CropMove), "wstr", 0, "wstr", 0)
					GUICtrlSetColor(-1, 0xFFFFFF)
					GUICtrlSetBkColor(-1, 0x888888)
					Local $iLable_Dummy = GUICtrlCreateLabel("", 0, -10000, 1, 1)
					GUISetState(@SW_SHOW, $hGUI_IE_Crop)
					WinSetTrans($hGUI_IE_Crop, "", 0x80)

					GUICtrlSetData($iLable_CropMove, $aTranslations[279][$iLang] & @CRLF & WinGetPos($hGUI_IE_Crop)[2] & "x" & WinGetPos($hGUI_IE_Crop)[3])
					$bCropWinActive = True
					GUIRegisterMsg($WM_MOVE, "WM_MOVE_IE_GUI_Crop")
					GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING_Crop")
					GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO_Crop")

					Local $aAccelKeys_IE[1][2] = [["{ENTER}", $iLable_Dummy]]
					GUISetAccelerators($aAccelKeys_IE, $hGUI_IE_Crop)

					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE
								GUIDelete($hGUI_IE_Crop)
								$bCropWinActive = False
								GUIRegisterMsg($WM_MOVE, "")
								GUIRegisterMsg($WM_GETMINMAXINFO, "")
								GUIRegisterMsg($WM_WINDOWPOSCHANGING, "")
								ExitLoop
							Case $iLable_Dummy
								$bCropWinActive = False
								GUIRegisterMsg($WM_MOVE, "")
								GUIRegisterMsg($WM_GETMINMAXINFO, "")
								GUIRegisterMsg($WM_WINDOWPOSCHANGING, "")
								_GDIPlus_BitmapDispose($IE_Bmp_Undo)
								$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
								If Not $IE_Bmp_Undo Or @error Then
									MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
									$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
									ExitLoop
								EndIf
								$aWinPos_Crop = WinGetPos($hGUI_IE_Crop)
								$hBild = _GDIPlus_BitmapCloneArea($hBmp, -7 + $IE_offset_x + $iPosX_Crop, -7 + $IE_offset_y + $iPosY_Crop, $aWinPos_Crop[2], $aWinPos_Crop[3], $GDIP_PXF32ARGB)
								_GDIPlus_BitmapDispose($hBmp)
								$hBmp = $hBild
								$bW = _GDIPlus_ImageGetWidth($hBmp)
								$bH = _GDIPlus_ImageGetHeight($hBmp)
								CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
								_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
								$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
								_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
								_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
								GUIDelete($hGUI_IE_Crop)

								If $bW < $hGUI_ImageEditor_W Then
									$IE_offset_x = -($hGUI_ImageEditor_W - $bW) / 2
								Else
									$IE_offset_x = 0
								EndIf
								If $bH < ($hGUI_ImageEditor_H - $height_delta) Then
									$IE_offset_y = -(($hGUI_ImageEditor_H - $height_delta) - $bH) / 2
								Else
									$IE_offset_y = 0
								EndIf
								GUICtrlSetPos($idPic_ImageEditor, $IE_offset_x * -1, $IE_offset_y * -1, $bW, $bH)

								$iMetricsSumX = ($bH > ($hGUI_ImageEditor_H - $height_delta)) * $iVSscroll + $iXFixedFrame * 2
								$iMetricsSumY = ($bW > $hGUI_ImageEditor_W) * $iHSscroll + $iYCaption + $iYFixedFrame

								_Functions_RemoveScrollBars($hGUI_ImageEditor_Child)
								$IE_ScrollbarH = False
								$IE_ScrollbarV = False

								If $bW > $hGUI_ImageEditor_W Or $bH > ($hGUI_ImageEditor_H - $height_delta) Then
									_GUIScrollBars_Init($hGUI_ImageEditor_Child)
									_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_HORZ, 0)
									_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_HORZ, $bW - $hGUI_ImageEditor_W + 61 + $iMetricsSumX)
									_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_VERT, 0)
									_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_VERT, $bH - $hGUI_ImageEditor_H + $iMetricsSumY + $height_delta - 1)
									GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_IE")
									GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_IE")
									GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_IE")

									If $bW > $hGUI_ImageEditor_W Then
										WM_HSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
										$IE_ScrollbarH = True
									EndIf
									If $bH > ($hGUI_ImageEditor_H - $height_delta) Then
										WM_VSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
										$IE_ScrollbarV = True
									EndIf
								Else
									GUIRegisterMsg($WM_HSCROLL, "")
									GUIRegisterMsg($WM_VSCROLL, "")
									GUIRegisterMsg($WM_MOUSEWHEEL, "")
								EndIf
								WinSetTitle($hGUI_ImageEditor, "", "AutoIt Windows Screenshooter - " & $aTranslations[39][$iLang] & " / " & $aTranslations[82][$iLang] & $bW & "x" & $bH & $aTranslations[78][$iLang])
								WinActivate($hGUI_ImageEditor_Child)
								$iZ += 1
								$bUndo = True
								$IE_Resize = True
								ExitLoop
						EndSwitch
					WEnd
				Case $IE_Dummy_Res
					$IE_Old_W = $bW
					$IE_Old_H = $bH
					GUIRegisterMsg($WM_COMMAND, "")
					_GDIPlus_BitmapDispose($IE_Bmp_Undo)
					$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
					If Not $IE_Bmp_Undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
							$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
					$Undo_IE = True
					$hGUI_IE_Resize = GUICreate($aTranslations[179][$iLang], 306, 470, -1, -1, BitOR($WS_SYSMENU, $WS_GROUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST), $hGUI_ImageEditor)
					GUISetFont(8 * $aDPI[0], 400, 0, "Arial")

					$idGroup_IE_ISize = GUICtrlCreateGroup($aTranslations[180][$iLang], 16, 8, 273, 97)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_Current = GUICtrlCreateLabel($aTranslations[181][$iLang], 42, 32, 150, 22)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_New = GUICtrlCreateLabel($aTranslations[182][$iLang], 42, 64, 150, 22)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_SizeC = GUICtrlCreateLabel($bW & " x " & $bH & $aTranslations[78][$iLang], 140, 32, 120, 22, $SS_RIGHT)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_SizeN = GUICtrlCreateLabel($bW & " x " & $bH & $aTranslations[78][$iLang], 140, 64, 120, 22, $SS_RIGHT)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					GUICtrlCreateGroup("", -99, -99, 1, 1)

					$idGroup_IE_INSize = GUICtrlCreateGroup($aTranslations[183][$iLang], 16, 120, 273, 185)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_W1 = GUICtrlCreateLabel($aTranslations[184][$iLang], 30, 146, 46, 21)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idInput_IE_W = GUICtrlCreateInput($bW, 80, 144, 49, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_x = GUICtrlCreateLabel("x", 144, 146, 11, 20)
					GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_H1 = GUICtrlCreateLabel($aTranslations[185][$iLang], 221, 146, 49, 21)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idInput_IE_H = GUICtrlCreateInput($bH, 166, 144, 49, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_W2 = GUICtrlCreateLabel($aTranslations[184][$iLang], 30, 183, 46, 21)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idInput_IE_WP = GUICtrlCreateInput("100", 80, 181, 35, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_P1 = GUICtrlCreateLabel("%", 116, 185, 15, 19)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idInput_IE_HP = GUICtrlCreateInput("100", 166, 181, 35, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_P2 = GUICtrlCreateLabel("%", 202, 185, 15, 19)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idLabel_IE_H2 = GUICtrlCreateLabel($aTranslations[185][$iLang], 221, 183, 49, 21)
					GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Arial")
					$idChkBox_IE_AR = GUICtrlCreateCheckbox($aTranslations[186][$iLang], 80, 220)
					$idButton_IE_IHalf = GUICtrlCreateButton($aTranslations[187][$iLang], 36, 264, 90, 25)
					GUICtrlSetFont(-1, 9.5 * $aDPI[0], 400, 0, "Arial")
					$idButton_IE_IDouble = GUICtrlCreateButton($aTranslations[188][$iLang], 183, 264, 90, 25)
					GUICtrlSetFont(-1, 9.5 * $aDPI[0], 400, 0, "Arial")
					GUICtrlCreateGroup("", -99, -99, 1, 1)

					$idGroup_IE_IMethod = GUICtrlCreateGroup($aTranslations[189][$iLang], 16, 320, 273, 73)
					GUICtrlSetFont(-1, 8 * $aDPI[0], 400, 0, "Arial")
					$idCombo_IE = GUICtrlCreateCombo("", 32, 354, 241, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
					GUICtrlSetData(-1, $aTranslations[190][$iLang], StringRegExpReplace($aTranslations[190][$iLang], ".+\|(7 - .+)", "$1"))
					GUICtrlCreateGroup("", -99, -99, 1, 1)

					$idButton_IE_OK = GUICtrlCreateButton($aTranslations[173][$iLang], 72, 408, 75, 25)
					GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Arial")
					$idButton_IE_Cancel = GUICtrlCreateButton($aTranslations[110][$iLang], 160, 408, 75, 25)
					GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Arial")
					GUISetState(@SW_SHOW, $hGUI_IE_Resize)
					ControlFocus($hGUI_IE_Resize, "", $idButton_IE_Cancel)
					GUIRegisterMsg($WM_COMMAND, "WM_COMMAND_IE")

					Local $w, $h, $maxw, $maxh, $minw, $minh
					While 1
						Switch GUIGetMsg()
							Case $GUI_EVENT_CLOSE, $idButton_IE_Cancel
								GUIDelete($hGUI_IE_Resize)
								ContinueLoop 2
							Case $idButton_IE_OK
								ExitLoop
							Case $idButton_IE_IHalf
								$maxw = Round(GUICtrlRead($idInput_IE_W) / 2, 0)
								$maxh = Round(GUICtrlRead($idInput_IE_H) / 2, 0)
								If $maxw > 1 Or $maxh > 1 Then
									GUICtrlSetData($idInput_IE_W, $maxw)
									GUICtrlSetData($idInput_IE_H, $maxh)
									GUICtrlSetData($idInput_IE_WP, Round(GUICtrlRead($idInput_IE_W) / $bW * 100))
									GUICtrlSetData($idInput_IE_HP, Round(GUICtrlRead($idInput_IE_H) / $bH * 100))
									GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & $aTranslations[78][$iLang])
								EndIf
							Case $idButton_IE_IDouble
								$minw = Round(GUICtrlRead($idInput_IE_W) * 2, 0)
								$minh = Round(GUICtrlRead($idInput_IE_H) * 2, 0)
								If $minw < 16384 Or $minh < 16384 Then
									GUICtrlSetData($idInput_IE_W, $minw)
									GUICtrlSetData($idInput_IE_H, $minh)
									GUICtrlSetData($idInput_IE_WP, Round(GUICtrlRead($idInput_IE_W) / $bW * 100))
									GUICtrlSetData($idInput_IE_HP, Round(GUICtrlRead($idInput_IE_H) / $bH * 100))
									GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & $aTranslations[78][$iLang])
								EndIf
						EndSwitch
					WEnd

					$bW = GUICtrlRead($idInput_IE_W)
					$bH = GUICtrlRead($idInput_IE_H)

					Local $hBmp_New = _GDIPlus_ImageResize2($hBmp, $bW, $bH, _SendMessage(GUICtrlGetHandle($idCombo_IE), $CB_GETCURSEL))

					GUIDelete($hGUI_IE_Resize)

					$hBmp = $hBmp_New

					$bW = _GDIPlus_ImageGetWidth($hBmp_New)
					$bH = _GDIPlus_ImageGetHeight($hBmp_New)

					If $bW < $hGUI_ImageEditor_W Then
						$IE_offset_x = -($hGUI_ImageEditor_W - $bW) / 2
					Else
						$IE_offset_x = 0
					EndIf
					If $bH < ($hGUI_ImageEditor_H - $height_delta) Then
						$IE_offset_y = -(($hGUI_ImageEditor_H - $height_delta) - $bH) / 2
					Else
						$IE_offset_y = 0
					EndIf
					GUICtrlSetPos($idPic_ImageEditor, $IE_offset_x * -1, $IE_offset_y * -1, $bW, $bH)

					$iMetricsSumX = ($bH > ($hGUI_ImageEditor_H - $height_delta)) * $iVSscroll + $iXFixedFrame * 2
					$iMetricsSumY = ($bW > $hGUI_ImageEditor_W) * $iHSscroll + $iYCaption + $iYFixedFrame

					_Functions_RemoveScrollBars($hGUI_ImageEditor_Child)
					$IE_ScrollbarH = False
					$IE_ScrollbarV = False

					If $bW > $hGUI_ImageEditor_W Or $bH > ($hGUI_ImageEditor_H - $height_delta) Then
						_GUIScrollBars_Init($hGUI_ImageEditor_Child)
						_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_HORZ, 0)
						_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_HORZ, $bW - $hGUI_ImageEditor_W + 61 + $iMetricsSumX)
						_GUIScrollBars_SetScrollInfoMin($hGUI_ImageEditor_Child, $SB_VERT, 0)
						_GUIScrollBars_SetScrollInfoMax($hGUI_ImageEditor_Child, $SB_VERT, $bH - $hGUI_ImageEditor_H + $iMetricsSumY + $height_delta - 1)
						GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_IE")
						GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_IE")
						GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_IE")

						If $bW > $hGUI_ImageEditor_W Then
							WM_HSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
							$IE_ScrollbarH = True
						EndIf
						If $bH > ($hGUI_ImageEditor_H - $height_delta) Then
							WM_VSCROLL_IE($hGUI_ImageEditor_Child, 0, $SB_THUMBTRACK, 0)
							$IE_ScrollbarV = True
						EndIf
					Else
						GUIRegisterMsg($WM_HSCROLL, "")
						GUIRegisterMsg($WM_VSCROLL, "")
						GUIRegisterMsg($WM_MOUSEWHEEL, "")
					EndIf

					_GDIPlus_GraphicsDispose($hGfx_IE)
					_GDIPlus_GraphicsDispose($hCtx_IE)
					_GDIPlus_ImageDispose($hCtx_IE_BMP)
					_GDIPlus_BitmapDispose($hGfx_IE_BMP)

					_WinAPI_DeleteObject(GUICtrlSendMsg($idPic_ImageEditor, $STM_SETIMAGE, $IMAGE_BITMAP, 0))
					CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)

					$hGfx_IE = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($idPic_ImageEditor))
					$hGfx_IE_BMP = _GDIPlus_BitmapCreateFromGraphics($bW, $bH, $hGfx_IE)
					$hCtx_IE = _GDIPlus_ImageGetGraphicsContext($hGfx_IE_BMP)
					$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
					_GDIPlus_GraphicsSetPixelOffsetMode($hGfx_IE, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
					_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
					_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
					_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
					_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE, 2)
					_GDIPlus_GraphicsSetSmoothingMode($hGfx_IE, 2)

					WinSetTitle($hGUI_ImageEditor, "", "AutoIt Windows Screenshooter - " & $aTranslations[39][$iLang] & " / " & $aTranslations[82][$iLang] & $bW & "x" & $bH & $aTranslations[78][$iLang])
					WinActivate($hGUI_ImageEditor_Child)
					$IE_Resize = True
					$iZ += 1
					$bUndo = True
				Case $iKey_Undo
					$iKey = $idUndo_IE
				Case $iKey_s
					$iKey = $idSave_IE
				Case $iKey_c
					$iKey = $idCopy_IE
				Case $iKey_n
					$iKey = $idSend_IE
				Case $iKey_h
					$iKey = $idHighlighter_IE
				Case $iKey_p
					$iKey = $idPen_IE
				Case $iKey_r
					$iKey = $idRectangle_IE
				Case $iKey_e
					$iKey = $idEllipse_IE
				Case $iKey_a
					$iKey = $idArrow_IE
				Case $iKey_o
					$iKey = $idColor_IE
				Case $iKey_t
					$iKey = $idText_IE
				Case $iKey_g
					$iKey = $idText_Conf_IE
			EndSwitch
			If $iKey Then
				GUICtrlSendToDummy($TB_Button_Chk, $iKey)
			EndIf
		EndIf
	Until False

	If @OSBuild < 6000 Then DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hGUI_ImageEditor, "ptr", 0, "ptr", 0)

	GUIRegisterMsg($WM_HSCROLL, "")
	GUIRegisterMsg($WM_VSCROLL, "")
	GUIRegisterMsg($WM_MOUSEWHEEL, "")
	GUIRegisterMsg($WM_SETCURSOR, "")
	_WinAPI_DeleteObject($hHBITMAP_IE_Icons)
	_WinAPI_DestroyIcon($hIcon_New)
	_GDIPlus_BitmapDispose($hWnd_Title_Icon)
	_GDIPlus_BrushDispose($hBrush_IE)
	_GDIPlus_PenDispose($hPen_IE)
	_GDIPlus_PenDispose($hHL_IE)
	_GDIPlus_PenDispose($hPenArrow_IE)
	_GDIPlus_PenDispose($hPenArrowShadow_IE)
	_GDIPlus_ArrowCapDispose($hEndCap)
	_GDIPlus_BitmapDispose($IE_Bmp_Undo)
	_GDIPlus_BitmapDispose($hGfx_IE_BMP)
	_GDIPlus_GraphicsDispose($hCtxt_Tmp)
	_GDIPlus_BitmapDispose($hBmp_Tmp)
	If @OSBuild > 5999 Then ;otherwise when image editor is recalled drawings will not be copied to context handle
		_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
		_GDIPlus_GraphicsDispose($hCtx_IE)
		_GDIPlus_GraphicsDispose($hGfx_IE)
	EndIf
	GUIDelete($hGUI_ImageEditor_Child)
	GUIDelete($hGUI_ImageEditor)
	_WinAPI_SetClassLongEx($hGUI, $GCL_HICONSM, $hMainGUI_Icon)
	Return $iZ
EndFunc   ;==>ImageEditor

Func _Functions_RemoveScrollBars($hWnd, $horz = True, $vert = True)
	Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
	DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
	DllStructSetData($tSCROLLINFO, "nMin", 0)
	DllStructSetData($tSCROLLINFO, "nMax", 0)
	DllStructSetData($tSCROLLINFO, "nPage", 0)
	If $horz Then _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
	If $vert Then _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
EndFunc   ;==>_Functions_RemoveScrollBars

Func CopyImage2Control($idControl, $iBgColor = 0x808080)
	Local Const $hHBitmap_ImageEditor = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
	Local Const $hBitmap_Empty = _GDIPlus_BitmapCreateFromScan0($bW, $bH)
	Local Const $hHBitmap_Empty = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Empty, $iBgColor)
	Local Const $hB2 = GUICtrlSendMsg($idPic_ImageEditor, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Empty)
	Local Const $hB = GUICtrlSendMsg($idPic_ImageEditor, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_ImageEditor)
	_GDIPlus_ImageDispose($hBitmap_Empty)
	If $hB Then _WinAPI_DeleteObject($hB)
	If $hB2 Then _WinAPI_DeleteObject($hB2)
	_WinAPI_DeleteObject($hHBitmap_Empty)
	_WinAPI_DeleteObject($hHBitmap_ImageEditor)
EndFunc   ;==>CopyImage2Control

Func _GDIPlus_GraphicsDrawString2(ByRef $hGraphics, ByRef $hBitmap, $sString, $sFont = "Arial", $nSize = 50, $iFormat = 0, $iColor = 0xFFFF0000, $nX = 0, $nY = 0)
	Local $hBrush = _GDIPlus_BrushCreateSolid()
	Local $hPen = _GDIPlus_PenCreate(0x98101010, 1) ;Int($nSize * 1.33333 / 60)
	Local $hPath = _GDIPlus_PathCreate()
	Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
	Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
	Local $tLayout = _GDIPlus_RectFCreate($nX + Int($nSize * 1.33333 / 22), $nY + Int($nSize * 1.33333 / 16), 0, 0)
	Local $hBitmap_blurred = _GDIPlus_BitmapCreateFromScan0(_GDIPlus_ImageGetWidth($hBitmap), _GDIPlus_ImageGetHeight($hBitmap))
	Local $hBitmap_blurred_Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_blurred)
	_GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 0, $nSize * 1.33333, $hFormat)
	_GDIPlus_BrushSetSolidColor($hBrush, 0x9F000000)
	_GDIPlus_GraphicsFillPath($hBitmap_blurred_Ctxt, $hPath, $hBrush)
	_GDIPlus_PathReset($hPath)
	Local $hBmp_blurred = _Blur($hBitmap_blurred, _GDIPlus_ImageGetWidth($hBitmap_blurred), _GDIPlus_ImageGetHeight($hBitmap_blurred), 0, 0, 0, 0, 0.125)
	_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmp_blurred, 0, 0, _GDIPlus_ImageGetWidth($hBitmap_blurred), _GDIPlus_ImageGetHeight($hBitmap_blurred))
	_GDIPlus_GraphicsDispose($hBitmap_blurred_Ctxt)
	_GDIPlus_BitmapDispose($hBitmap_blurred)
	_GDIPlus_BitmapDispose($hBmp_blurred)
	$tLayout.X = $nX
	$tLayout.Y = $nY
	_GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 0, $nSize * 1.33333, $hFormat)
	_GDIPlus_BrushSetSolidColor($hBrush, $iColor)
	_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
	_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_PenDispose($hPen)
	_GDIPlus_PathDispose($hPath)
EndFunc   ;==>_GDIPlus_GraphicsDrawString2

Func GetStringSize($string, $font, $fontsize, $fontstyle = 0)
	Local $iWidth = StringLen($string) * $fontsize
	Local $iHeight = 2 * $fontsize
	Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
	Local $hGrphContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	Local $hFormat = _GDIPlus_StringFormatCreate()
	Local $hFamily = _GDIPlus_FontFamilyCreate($font)
	Local $hFont = _GDIPlus_FontCreate($hFamily, $fontsize, $fontstyle)
	Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
	Local $aInfo = _GDIPlus_GraphicsMeasureString($hGrphContext, $string, $hFont, $tLayout, $hFormat)
	_GDIPlus_FontDispose($hFont)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BitmapDispose($hBitmap)
	_GDIPlus_GraphicsDispose($hGrphContext)
	Local $aDim[2] = [Int(DllStructGetData($aInfo[0], "Width")), Int(DllStructGetData($aInfo[0], "Height"))]
	Return $aDim
EndFunc   ;==>GetStringSize

Func Call_ImageEditor()
	HotKeySet("^!{F9}")
	HotKeySet("^!{F12}")
	Local $iRet
	GUISetState(@SW_HIDE, $hGUI)

	AutoItSetOption("MouseCoordMode", 2)
	AutoItSetOption("GUICloseOnESC", 1)
	AutoItSetOption("GUIOnEventMode", 0)

	GUIRegisterMsg($WM_SYSCOMMAND, "")
	GUIRegisterMsg($WM_CONTEXTMENU, "")
	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "")
	Else
		GUIRegisterMsg($WM_NCPAINT, "")
	EndIf

	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	If Not $undo Or @error Then MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))

	$iRet = ImageEditor()

	GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
	GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
	GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
	GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "Redraw_XP")
	Else
		GUIRegisterMsg($WM_NCPAINT, "Redraw")
	EndIf
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
;~ 	$hClipboard_Bitmap = $hBitmap_s
	$z = 10
	Zoom(-1)
;~ 	_WinAPI_DeleteObject($hClipboard_Bitmap)
;~ 	$hClipboard_Bitmap = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
	_WinAPI_SetSystemCursor($hCursor_System, 32512)
	_WinAPI_DestroyCursor($hCursor_IE)
	AutoItSetOption("MouseCoordMode", 1)
	AutoItSetOption("GUICloseOnESC", 0)
	AutoItSetOption("GUIOnEventMode", 1)
	GUISetState(@SW_SHOW, $hGUI)
	Sleep(100)
	GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
	HotKeySet("^!{F9}", "Grab_Screen")
	HotKeySet("^!{F12}", "Grab_Active_Window")
	WinActivate(HWnd($hGUI))
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")
	Return $iRet
EndFunc   ;==>Call_ImageEditor
#EndRegion Image Editor

#Region Watermark
Func Call_Watermark()
	GUISetState(@SW_HIDE, $hGUI)
	HotKeySet("^!{F9}")
	HotKeySet("^!{F12}")
	AutoItSetOption("MouseCoordMode", 2)
	AutoItSetOption("GUICloseOnESC", 1)
	AutoItSetOption("GUIOnEventMode", 0)

	GUIRegisterMsg($WM_VSCROLL, "")

	GUIRegisterMsg($WM_MOUSEWHEEL, "")
	GUIRegisterMsg($WM_HSCROLL, "")
	GUIRegisterMsg($WM_COMMAND, "")
	GUIRegisterMsg($WM_SYSCOMMAND, "")
	GUIRegisterMsg($WM_CONTEXTMENU, "")
	GUIRegisterMsg($WM_ERASEBKGND, "")

	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "")
	Else
		GUIRegisterMsg($WM_NCPAINT, "")
	EndIf

	Sleep(100)
	$iColorFont_WM = 0xFF0000
	$hBitmap_WM = 0
	$hBmp_Preview_WM = 0
	$hBitmapStamp_WM = 0
	$hBitmapStampPreview_WM = 0
	$hBitmap_Preview_WM = 0
	$bStamp_WM = False
	$bResize = False

	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	If Not $undo Or @error Then MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
	Local $bReturn = Watermark()

	GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
	GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
	GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
	GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
	If @OSBuild < 6000 Then
		GUIRegisterMsg($WM_PAINT, "Redraw_XP")
	Else
		GUIRegisterMsg($WM_NCPAINT, "Redraw")
	EndIf
	Update_Resolution_Info($hBmp)
	Draw2Graphic($hBmp)
;~ 	$hClipboard_Bitmap = $hBitmap_s
	$z = 10
	Zoom(-1)
;~ 	_WinAPI_DeleteObject($hClipboard_Bitmap)
;~ 	$hClipboard_Bitmap = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
	If $image2clipboard Then
		$silent = True
		Pic2Clipboard()
		$silent = False
	EndIf
	_WinAPI_SetSystemCursor($hCursor_System, 32512)
	_WinAPI_DestroyCursor($hCursor_IE)
	AutoItSetOption("MouseCoordMode", 1)
	AutoItSetOption("GUICloseOnESC", 0)
	AutoItSetOption("GUIOnEventMode", 1)
	GUISetState(@SW_SHOW, $hGUI)
	Sleep(100)
	GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
	HotKeySet("^!{F9}", "Grab_Screen")
	HotKeySet("^!{F12}", "Grab_Active_Window")
	WinActivate(HWnd($hGUI))
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")
	Return $bReturn
EndFunc   ;==>Call_Watermark

Func Watermark()
	#Region GUI
	Local $aPos, $hCtx_Stamp, $hHBitmap_Stamp, $hB, $w, $h, $f, $iFS, $hCtx_WM_BMP, $fAccel
	$iPos_WM = 9
	$bFill = False
	$iAdjX_WM = 0
	$iAdjY_WM = 0

	$hGUI_WM = GUICreate("AutoIt Watermark Image", $iGUI_W, $iGUI_H)
	GUISetFont(8 * $aDPI[0], 400, 0, "Times New Roman")
	GUISetBkColor($iGUI_WM_color, $hGUI_WM)
	Local Const $idPicLogo_WM = GUICtrlCreatePic("", $iW_Grp_WM + 32, 14, 189, 161)

	Local Const $idGroupText_WM = GUICtrlCreateGroup($aTranslations[191][$iLang], 16, 8, 337, 168)
	GUICtrlSetFont(-1, 8.5 * $aDPI[0], 400, 0, "Times New Roman")
	$idInputText_WM = GUICtrlCreateInput("Watermarked by UEZ", 64, 26, 274, 23)
	GUICtrlSetFont(-1, 9 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hInputText_WM = GUICtrlGetHandle($idInputText_WM)
	Local Const $sInputTextNN = _WinAPI_GetClassName($hInputText_WM) & _GetNN($hInputText_WM)
	Local Const $idLabelText_WM = GUICtrlCreateLabel($aTranslations[192][$iLang], 18, 27, 44, 30, $SS_RIGHT)
	GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
	Local Const $idLabelFont_WM = GUICtrlCreateLabel($aTranslations[193][$iLang], 18, 60, 44, 30, $SS_RIGHT) ;, BitOR($SS_CENTER, $SS_CENTERIMAGE))
	GUICtrlSetFont(-1, 9.5 * $aDPI[0], 400, 0, "Times New Roman")
	$idComboFont_WM = GUICtrlCreateCombo("", 64, 58, 193, 25, BitOR($CBS_DROPDOWNLIST, $CBS_SORT, $WS_VSCROLL))
	GUICtrlSetData(-1, $sFonts, "Arial")
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[194][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	$hComboFont_WM = GUICtrlGetHandle($idComboFont_WM)
	$idButtonLoadFont_WM = GUICtrlCreateButton($aTranslations[195][$iLang], 264, 57, 75, 25)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[196][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hButtonLoadFont_WM = GUICtrlGetHandle($idButtonLoadFont_WM)
	Local Const $sButtonLoadFontNN = _WinAPI_GetClassName($hButtonLoadFont_WM) & _GetNN($hButtonLoadFont_WM)
	Local Const $idLabelSize_WM = GUICtrlCreateLabel($aTranslations[162][$iLang], 18, 98, 44, 30, $SS_RIGHT)
	GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
	$idInputFSize_WM = GUICtrlCreateInput("24", 64, 96, 48, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hInputFSize_WM = GUICtrlGetHandle($idInputFSize_WM)
	Local Const $sInputFSizeNN = _WinAPI_GetClassName($hInputFSize_WM) & _GetNN($hInputFSize_WM)
	$idUpdown_WM = GUICtrlCreateUpdown($idInputFSize_WM, $UDS_ARROWKEYS)
	GUICtrlSetLimit(-1, $iMaxFontSize_WM, $iMinFontSize_WM)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$hUpdown_WM = GUICtrlGetHandle($idUpdown_WM)
	Local Const $idLabelColor_WM = GUICtrlCreateLabel($aTranslations[192][$iLang], 140, 97, 39, 23)
	GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[197][$iLang])
	$idButtonColor_WM = GUICtrlCreateButton("", 180, 94, 27, 25, BitOR($BS_FLAT, $WS_BORDER, $BS_PUSHLIKE))
	GUICtrlSetBkColor(-1, $iColorFont_WM)
	GUICtrlSetTip(-1, $aTranslations[198][$iLang])
	GUICtrlSetCursor(-1, 0)
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hButtonColor_WM = GUICtrlGetHandle($idButtonColor_WM)
	Local Const $sButtonColorNN = _WinAPI_GetClassName($hButtonColor_WM) & _GetNN($hButtonColor_WM)
	$idRadioImagePreview_WM = GUICtrlCreateRadio("", 223, 87, 12, 17)
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $idLabelImage_WM = GUICtrlCreateLabel($aTranslations[199][$iLang], 238, 87, 48, 23)
	GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[200][$iLang])
	$idCheckboxFill_WM = GUICtrlCreateCheckbox($aTranslations[201][$iLang], 223, 111, 62)
	GUICtrlSetFont(-1, 11 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUICtrlSetTip(-1, $aTranslations[202][$iLang])
	Local Const $idPicStampPreview_WM = GUICtrlCreatePic("", 287, 87, 50, 40, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN))
	GUICtrlSetTip(-1, $aTranslations[203][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hPicImagePreview_WM = GUICtrlGetHandle($idPicStampPreview_WM)
	$idRadioColor_WM = GUICtrlCreateRadio("", 126, 97, 12, 17)
	GUICtrlSetState(-1, $GUI_CHECKED)
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $iOpaque_Max_WM = 255
	Local Const $iOpaque_Min_WM = 1
	Local Const $idLabelOpaque_WM = GUICtrlCreateLabel($aTranslations[204][$iLang], 18, 140, 59, 32, $SS_RIGHT)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	$idSliderOpaque_WM = GUICtrlCreateSlider(78, 130, 226, 38 * $aDPI[0], BitOR($TBS_TOP, $TBS_LEFT, $TBS_BOTH, $TBS_ENABLESELRANGE))
	GUICtrlSetLimit(-1, $iOpaque_Max_WM, $iOpaque_Min_WM)
	GUICtrlSetData(-1, 92)
	GUICtrlSetTip(-1, $aTranslations[205][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)

	$hSliderOpaque_WM = GUICtrlGetHandle($idSliderOpaque_WM)
	$idInputOpaque_WM = GUICtrlCreateInput("92", 305, 141, 33, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hInputOpaque_WM = GUICtrlGetHandle($idInputOpaque_WM)
	Local Const $sInputOpaqueNN = _WinAPI_GetClassName($hInputOpaque_WM) & _GetNN($hInputOpaque_WM)
	GUICtrlCreateGroup("", -99, -99, 1, 1)

	Local Const $idGroupPos_WM = GUICtrlCreateGroup($aTranslations[206][$iLang], 360, 8, 378, 168), $iSizeRadio = 10 * $aDPI[0]
	GUICtrlSetFont(-1, $iSizeRadio * $aDPI[0], 400, 0, "Times New Roman")
	$idRadioUpperLeft_WM = GUICtrlCreateRadio("", 376, 32, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioUpperMid_WM = GUICtrlCreateRadio("", 440, 32, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioUpperRight_WM = GUICtrlCreateRadio("", 504, 32, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioMidRight_WM = GUICtrlCreateRadio("", 504, 86, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioCenter_WM = GUICtrlCreateRadio("", 440, 86, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioMidLeft_WM = GUICtrlCreateRadio("", 376, 86, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioButtomRight_WM = GUICtrlCreateRadio("", 504, 143, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUICtrlSetState(-1, $GUI_CHECKED)
	$idRadioButtomMid_WM = GUICtrlCreateRadio("", 440, 143, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idRadioButtomLeft_WM = GUICtrlCreateRadio("", 376, 143, 16 * $aDPI[0], 17 * $aDPI[0])
	GUICtrlSetFont(-1, $iSizeRadio)
	GUICtrlSetState(-1, $GUI_DISABLE)

	Local Const $idLabelDelimiter_WM = GUICtrlCreateLabel("", 532, 18, 2, 158, $SS_ETCHEDVERT)
	Local Const $iDegree_Max_WM = 180
	Local Const $iDegree_Min_WM = -180
	$idSliderDegree_WM = GUICtrlCreateSlider(544, 17, 30 * $aDPI[0], 157, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_VERT, $TBS_ENABLESELRANGE))
	GUICtrlSetLimit(-1, $iDegree_Max_WM, $iDegree_Min_WM)
	GUICtrlSetTip(-1, $aTranslations[207][$iLang])
	GUICtrlSetCursor(-1, 0)
	GUICtrlSetState(-1, $GUI_DISABLE)
	$hSliderDegree_WM = GUICtrlGetHandle($idSliderDegree_WM)
	$idInputDegree_WM = GUICtrlCreateInput("0", 578, 143, 30, 22, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
	GUICtrlSetFont(-1, 8.5 * $aDPI[0])
	GUICtrlSetLimit(-1, 3)
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hInputDegree_WM = GUICtrlGetHandle($idInputDegree_WM)
	Local Const $sInputDegreeNN = _WinAPI_GetClassName($hInputDegree_WM) & _GetNN($hInputDegree_WM)
	Local Const $idLabelDegree_WM = GUICtrlCreateLabel($aTranslations[208][$iLang], 612, 145, 124, 19)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	$idCheckboxCircular_WM = GUICtrlCreateCheckbox($aTranslations[209][$iLang], 586, 24, 150, 32)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[210][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	$idInputRadius_WM = GUICtrlCreateInput("64", 586, 62, 34, 22, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
	GUICtrlSetLimit(-1, $iRadius_Min_WM)
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUICtrlSetFont(-1, 9 * $aDPI[0])
	Local Const $hInputRadius_WM = GUICtrlGetHandle($idInputRadius_WM)
	Local Const $sInputRadiusNN = _WinAPI_GetClassName($hInputRadius_WM) & _GetNN($hInputRadius_WM)
	Local Const $idLabelRadius_WM = GUICtrlCreateLabel($aTranslations[211][$iLang], 624, 64, 110, 19)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	$idSliderRadius_WM = GUICtrlCreateSlider(586, 92, 130, 34 * $aDPI[1], $TBS_BOTH)
	GUICtrlSetLimit(-1, $iRadius_Max_WM, $iRadius_Min_WM)
	GUICtrlSetData(-1, 60)
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUICtrlSetTip(-1, $aTranslations[212][$iLang])
	$hSliderRadius_WM = GUICtrlGetHandle($idSliderRadius_WM)
	GUICtrlCreateGroup("", -99, -99, 1, 1)

	Local Const $idGroupPreview_WM = GUICtrlCreateGroup($aTranslations[213][$iLang] & $iW_Pic_WM & "x" & $iH_Pic_WM & ") ", 16, 176, $iW_Grp_WM, $iH_Grp_WM)
	GUICtrlSetFont(-1, 8.5 * $aDPI[0], 400, 0, "Times New Roman")
	$idPicPreview_WM = GUICtrlCreatePic("", 26, 194, $iW_Pic_WM, $iH_Pic_WM)
	GUICtrlSetState(-1, $GUI_DISABLE)
	GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM)
	Local Const $hPicPreview_WM = GUICtrlGetHandle($idPicPreview_WM)
	GUICtrlCreateGroup("", -99, -99, 1, 1)

	Local Const $idGroupTxtEffects_WM = GUICtrlCreateGroup($aTranslations[214][$iLang], $iW_Grp_WM + 52, 176, 170, 160)
	GUICtrlSetFont(-1, 8.5 * $aDPI[0], 400, 0, "Times New Roman")
	$idRadioTxtFXDefault_WM = GUICtrlCreateRadio($aTranslations[215][$iLang], 790, 210, 128, 17 * $aDPI[0])
	GUICtrlSetState(-1, $GUI_CHECKED)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	Local Const $hRadioTxtFXDefault_WM = GUICtrlGetHandle($idRadioTxtFXDefault_WM)
	Local Const $sRadioTxtFXDefaultNN = _WinAPI_GetClassName($hRadioTxtFXDefault_WM) & _GetNN($hRadioTxtFXDefault_WM)
	$idRadioTxtFXOutline_WM = GUICtrlCreateRadio($aTranslations[216][$iLang], 790, 250, 128, 17 * $aDPI[0])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hRadioTxtFXOutline_WM = GUICtrlGetHandle($idRadioTxtFXOutline_WM)
	Local Const $sRadioTxtFXOutlineNN = _WinAPI_GetClassName($hRadioTxtFXOutline_WM) & _GetNN($hRadioTxtFXOutline_WM)
	$idRadioTxtFXEmbossed_WM = GUICtrlCreateRadio($aTranslations[217][$iLang], 790, 290, 128, 17 * $aDPI[0])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hRadioTxtFXEmbossed_WM = GUICtrlGetHandle($idRadioTxtFXEmbossed_WM)
	Local Const $sRadioTxtFXEmbossedNN = _WinAPI_GetClassName($hRadioTxtFXEmbossed_WM) & _GetNN($hRadioTxtFXEmbossed_WM)
	GUICtrlCreateGroup("", -99, -99, 1, 1)

	Local Const $idButtonUndo_WM = GUICtrlCreateButton($aTranslations[149][$iLang], 590, 670, 75, 25 * $aDPI[0])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[218][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hButtonUndo_WM = GUICtrlGetHandle($idButtonUndo_WM)
	Local Const $sButtonUndoNN = _WinAPI_GetClassName($hButtonUndo_WM) & _GetNN($hButtonUndo_WM)
	Local Const $idButtonApply_WM = GUICtrlCreateButton($aTranslations[219][$iLang], 684, 670, 75, 25 * $aDPI[0])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")
	GUICtrlSetTip(-1, $aTranslations[220][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	Local Const $hButtonApply_WM = GUICtrlGetHandle($idButtonApply_WM)
	Local Const $sButtonApplyNN = _WinAPI_GetClassName($hButtonApply_WM) & _GetNN($hButtonApply_WM)
	Local Const $idButtonExit_WM = GUICtrlCreateButton($aTranslations[44][$iLang], 908, 660, 36, 36, $BS_ICON)
	_GUICtrlButton_SetImage($idButtonExit_WM, "shell32.dll", 27, True)
	GUICtrlSetTip(-1, $aTranslations[221][$iLang])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman")

	$idSliderAdjY_WM = GUICtrlCreateSlider($iW_Grp_WM + 16, 172, 30 * $aDPI[0], ($iH_Pic_WM + 44), BitOR($TBS_VERT, $TBS_AUTOTICKS, $TBS_LEFT))
	GUICtrlSetData(-1, 0)
	GUICtrlSetLimit(-1, 0, 0)
	GUICtrlSetTip(-1, $aTranslations[222][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	$hSliderAdjY_WM = GUICtrlGetHandle($idSliderAdjY_WM)
	$idSliderAdjX_WM = GUICtrlCreateSlider(8, 645, $iW_Grp_WM + 16, 22 * $aDPI[0], $TBS_AUTOTICKS)
	GUICtrlSetData(-1, 0)
	GUICtrlSetLimit(-1, 0, 0)
	GUICtrlSetTip(-1, $aTranslations[223][$iLang])
	GUICtrlSetState(-1, $GUI_DISABLE)
	$hSliderAdjX_WM = GUICtrlGetHandle($idSliderAdjX_WM)

	Local $aStringSize = GetStringSize($aTranslations[82][$iLang], "Times New Roman", 10 * $aDPI[0])
	Local Const $idLabelImgDim = GUICtrlCreateLabel($aTranslations[82][$iLang], 16, 675, $aStringSize[0])
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman", 5)
	$idLabelImgDimSize = GUICtrlCreateLabel("0 x 0 ", $aStringSize[0] + 12, 675, 70)
	GUICtrlSetFont(-1, 10 * $aDPI[0], 400, 0, "Times New Roman", 5)
	GUICtrlSetColor(-1, 0x00080)

	Local Const $iKey_Undo = GUICtrlCreateButton("", -10, -10, 1, 1)
	Local $aAccelKeys[1][2] = [["^z", $iKey_Undo]]


	Local $bReset = False
	Local $KeyLayout = RegRead("HKCU\Keyboard Layout\Preload", 1)
	If Not @error And $KeyLayout = 00000419 Then
		_WinAPI_LoadKeyboardLayout(0x0409)
		$bReset = True
	EndIf

	GUISetAccelerators($aAccelKeys, $hGUI_WM)

	If $bReset Then _WinAPI_LoadKeyboardLayout(Dec($KeyLayout))

	GUISetState(@SW_SHOW, $hGUI_WM)

	Local Const $hWnd_Title_Icon = _GDIPlus_BitmapCreateFromMemory(_W_Logo())
	Local Const $hIcon_New_WM = _WinAPI_SetWindowTitleIcon($hWnd_Title_Icon, $hGUI_WM)

	#EndRegion GUI

	Local $aWinPos = WinGetPos($hGUI_WM)
	$iGUI_MinW = $aWinPos[2]
	$iGUI_MinH = $aWinPos[3]
	Local $aPos, $hCtx_Stamp, $hHBitmap_Stamp, $hB, $w, $h, $f, $iFS, $hCtx_WM_BMP, $fAccel
	Local $iSaveColor_WM = $iColorFont_WM, $iColorFont_Current_WM = $iColorFont_WM
	Local $aButton, $iBtnPosX, $iBtnPosY, $sFn, $aMPos, $iOPosX, $iOPosY, $t_wm, $ic = 0, $iMRot, $iODeg

	Local Const $hHBITMAP_Logo_WM = _GDIPlus_BitmapCreateFromMemory(_W_Logo(), True)
	$hB = GUICtrlSendMsg($idPicLogo_WM, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP_Logo_WM)
	If $hB Then _WinAPI_DeleteObject($hB)

	Local $iMemX = 0, $iMemY = 0

	$hBitmap_Preview_WM = _WinAPI_CreateDIB($iW_Pic_WM, $iH_Pic_WM)
	$hDC_WM = _WinAPI_GetWindowDC($hPicPreview_WM)
	$hDC_backbuffer_WM = _WinAPI_CreateCompatibleDC($hDC_WM)
	$DC_obj_WM = _WinAPI_SelectObject($hDC_backbuffer_WM, $hBitmap_Preview_WM)
	$hGraphic_WM = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer_WM)
	_GDIPlus_GraphicsClear($hGraphic_WM, 0xFF000000 + $iGUI_WM_color)

	GUICtrlSetState($idInputText_WM, $GUI_ENABLE)
	GUICtrlSetState($idComboFont_WM, $GUI_ENABLE)
	GUICtrlSetState($idInputFSize_WM, $GUI_ENABLE)
	GUICtrlSetState($idUpdown_WM, $GUI_ENABLE)
	GUICtrlSetState($idButtonColor_WM, $GUI_ENABLE)
	GUICtrlSetState($idPicStampPreview_WM, $GUI_ENABLE)
	GUICtrlSetState($idSliderOpaque_WM, $GUI_ENABLE)
	GUICtrlSetState($idInputOpaque_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioUpperLeft_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioUpperMid_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioUpperRight_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioMidRight_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioCenter_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioMidLeft_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioButtomRight_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioButtomMid_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioButtomLeft_WM, $GUI_ENABLE)
	GUICtrlSetState($idSliderDegree_WM, $GUI_ENABLE)
	GUICtrlSetState($idInputDegree_WM, $GUI_ENABLE)
	GUICtrlSetState($idCheckboxCircular_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioColor_WM, $GUI_ENABLE)
	GUICtrlSetState($idButtonApply_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioTxtFXOutline_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioTxtFXEmbossed_WM, $GUI_ENABLE)
	GUICtrlSetState($idSliderAdjX_WM, $GUI_ENABLE)
	GUICtrlSetState($idSliderAdjY_WM, $GUI_ENABLE)
	GUICtrlSetState($idButtonLoadFont_WM, $GUI_ENABLE)

	GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_WM")
	GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_WM")

	If @OSBuild < 6000 Or (Not $aero) Then
		GUIRegisterMsg($WM_PAINT, "WM_REDRAW_WM")
	Else
		GUIRegisterMsg($WM_NCPAINT, "WM_REDRAW_WM")
		GUIRegisterMsg($WM_ERASEBKGND, "WM_REDRAW_WM")
	EndIf

	$iFS = Max(Ceiling(0.5 * $bW / StringLen(GUICtrlRead($idInputText_WM))), $iMinFontSize_WM)
	GUICtrlSetData($idInputFSize_WM, $iFS)
	GUICtrlSetData($idInputRadius_WM, Min($iRadius_Max_WM, $iFS * 3))
	GUICtrlSetData($idLabelImgDimSize, $bW & " x " & $bH)

	GUICtrlSetLimit($idSliderAdjX_WM, $bW, -$bW)
	GUICtrlSetLimit($idSliderAdjY_WM, $bH, -$bH)
	GUICtrlSetData($idSliderAdjX_WM, 0)
	GUICtrlSetData($idSliderAdjY_WM, 0)
	UpdatePreview_WM()
	$bResize = False
	$iMemX = 0
	$iMemY = 0
	$fAccel = Max(1, Min(7, ($bW * $bH) / (2.5 * 307200)))
	$t_wm = TimerInit()

	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND_WM")

	Local $bUndo = False

	While 1
		Switch GUIGetMsg()
			Case $idInputText_WM
				If ControlGetFocus($hGUI_WM) <> $sInputTextNN Then ContinueCase
				If StringLen(GUICtrlRead($idInputText_WM)) > 0 And Not $bStamp_WM Then UpdatePreview_WM()
			Case $idButtonApply_WM
				If ControlGetFocus($hGUI_WM) <> $sButtonApplyNN Then ContinueCase
				If $hBitmapUndo_WM Then _GDIPlus_BitmapDispose($hBitmapUndo_WM)
				$hBitmapUndo_WM = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
				$hCtx_WM_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
				_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_WM_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
				_GDIPlus_GraphicsDrawImageRect($hCtx_WM_BMP, $hBitmap_WM, 0, 0, $bW, $bH)
				_GDIPlus_GraphicsDispose($hCtx_WM_BMP)
				DllCall("gdi32.dll", "bool", "BitBlt", "handle", $hDC_WM, "int", 0, "int", 0, "int", $iW_Pic_WM, "int", $iH_Pic_WM, "handle", $hDC_backbuffer_WM, "int", 0, "int", 0, "dword", $SRCCOPY)
				GUICtrlSetBkColor($idButtonApply_WM, 0x00FF00)
				Sleep(200)
				GUICtrlSetStyle($idButtonApply_WM, 0)
				GUICtrlSetState($idButtonUndo_WM, $GUI_ENABLE)
				$ic += 1
			Case $idButtonUndo_WM
				If ControlGetFocus($hGUI_WM) <> $sButtonUndoNN Then ContinueCase
				_GDIPlus_BitmapDispose($hBmp)
				$bW = _GDIPlus_ImageGetWidth($hBitmapUndo_WM)
				$bH = _GDIPlus_ImageGetHeight($hBitmapUndo_WM)
				$hBmp = _GDIPlus_BitmapClone($hBitmapUndo_WM, $bW, $bH)
				$bResize = True
				GUICtrlSetLimit($idSliderAdjX_WM, $bW, -$bW)
				GUICtrlSetLimit($idSliderAdjY_WM, $bH, -$bH)
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				GUICtrlSetState($idButtonUndo_WM, $GUI_DISABLE)
				$bUpdate_WM = True
				If $ic < 2 Then $i -= 1
			Case $idInputDegree_WM, $idInputFSize_WM, $idInputOpaque_WM, $idInputRadius_WM, $idComboFont_WM
				GUICtrlSetData($idInputDegree_WM, Max(Min(Int(GUICtrlRead($idInputDegree_WM)), $iDegree_Max_WM), $iDegree_Min_WM))
				GUICtrlSetData($idSliderDegree_WM, GUICtrlRead($idInputDegree_WM))
				GUICtrlSetData($idInputOpaque_WM, Max(Min(Int(GUICtrlRead($idInputOpaque_WM)), $iOpaque_Max_WM), $iOpaque_Min_WM))
				GUICtrlSetData($idSliderOpaque_WM, GUICtrlRead($idInputOpaque_WM))
				GUICtrlSetData($idInputRadius_WM, Max(Min(Int(GUICtrlRead($idInputRadius_WM)), $iRadius_Max_WM), $iRadius_Min_WM))
				GUICtrlSetData($idSliderRadius_WM, GUICtrlRead($idInputRadius_WM))
				If StringInStr($sAddFonts, GUICtrlRead($idComboFont_WM)) Then
					$bFontMan = True
				Else
					$bFontMan = False
				EndIf
				UpdatePreview_WM()
			Case $GUI_EVENT_CLOSE, $idButtonExit_WM
				GUIRegisterMsg($WM_COMMAND, "")
				GUIRegisterMsg($WM_VSCROLL, "")
				GUIRegisterMsg($WM_HSCROLL, "")
				GUIRegisterMsg($WM_PAINT, "")
				GUIRegisterMsg($WM_NCPAINT, "")
				DllCall($dll, "int", "AnimateWindow", "hwnd", HWnd($hGUI_WM), "int", 200, "int", $AW_BLEND + $AW_HIDE)
				_WinAPI_DeleteObject($hHBITMAP_Logo_WM)

				_GDIPlus_BitmapDispose($hBmp_Preview_WM)
				_GDIPlus_BitmapDispose($hBitmap_WM)
				_GDIPlus_GraphicsDispose($hGraphic_WM)
				_WinAPI_SelectObject($hDC_backbuffer_WM, $DC_obj_WM)
				_WinAPI_DeleteObject($hBitmap_Preview_WM)
				_WinAPI_ReleaseDC($hPicPreview_WM, $hDC_WM)
				_WinAPI_DestroyIcon($hIcon_New_WM)
				If $hBitmapUndo_WM Then _GDIPlus_BitmapDispose($hBitmapUndo_WM)
				If $hBitmapStamp_WM Then _GDIPlus_BitmapDispose($hBitmapStamp_WM)
				GUIDelete($hGUI_WM)
				_WinAPI_SetClassLongEx($hGUI, $GCL_HICONSM, $hMainGUI_Icon)
				Return $ic
			Case $idPicStampPreview_WM
				$sFileImage_WM = FileOpenDialog($aTranslations[224][$iLang], "", $aTranslations[225][$iLang] & "(*.jpg;*.bmp;*png;*gif;*tif)", 3, "", $hGUI_WM)
				If Not @error Then
					GUIRegisterMsg($WM_VSCROLL, "")
					GUIRegisterMsg($WM_HSCROLL, "")
					GUICtrlSetState($idRadioImagePreview_WM, $GUI_CHECKED)
					GUICtrlSetState($idRadioImagePreview_WM, $GUI_ENABLE)
					If $hBitmapStamp_WM Then _GDIPlus_BitmapDispose($hBitmapStamp_WM)
					$hBitmapStamp_WM = _GDIPlus_BitmapCreateFromFile($sFileImage_WM)
					$hBitmap_Stamp_w = _GDIPlus_ImageGetWidth($hBitmapStamp_WM)
					$hBitmap_Stamp_h = _GDIPlus_ImageGetHeight($hBitmapStamp_WM)
					If $hBitmap_Stamp_w >= $bW Or $hBitmap_Stamp_h >= $bH Then
						Local $f
						If $hBitmap_Stamp_w >= $hBitmap_Stamp_h Then
							$f = $hBitmap_Stamp_w / $bW
						Else
							$f = $hBitmap_Stamp_h / $bH
						EndIf
						$hBitmap_Stamp_w = Int($hBitmap_Stamp_w / $f / 2)
						$hBitmap_Stamp_h = Int($hBitmap_Stamp_h / $f / 2)
						Local $hBitmapStamp_WM_new = _GDIPlus_BitmapClone($hBitmapStamp_WM, $hBitmap_Stamp_w, $hBitmap_Stamp_h)
						_GDIPlus_BitmapDispose($hBitmapStamp_WM)
						$hBitmapStamp_WM = $hBitmapStamp_WM_new
					EndIf
					GUICtrlSetLimit($idSliderDegree_WM, 400, 1)
					GUICtrlSetData($idSliderDegree_WM, 100)
					GUICtrlSetData($idInputDegree_WM, 100)
					$aPos = ControlGetPos($hGUI_WM, "", $idPicStampPreview_WM)
					$hBitmapStampPreview_WM = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aPos[2], "int", $aPos[3], "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
					$hBitmapStampPreview_WM = $hBitmapStampPreview_WM[6]
					$hCtx_Stamp = _GDIPlus_ImageGetGraphicsContext($hBitmapStampPreview_WM)
					_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_Stamp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
					_GDIPlus_GraphicsClear($hCtx_Stamp, 0xFFF0F0F0)
					$hB = GUICtrlSendMsg($idPicStampPreview_WM, $STM_SETIMAGE, $IMAGE_BITMAP, $hCtx_Stamp)
					If $hB Then _WinAPI_DeleteObject($hB)
					DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtx_Stamp, "int", 7)
					If $hBitmap_Stamp_w < $aPos[2] And $hBitmap_Stamp_h < $aPos[3] Then
						_GDIPlus_GraphicsDrawImageRect($hCtx_Stamp, $hBitmapStamp_WM, ($aPos[2] - $hBitmap_Stamp_w) / 2, ($aPos[3] - $hBitmap_Stamp_h) / 2, $hBitmap_Stamp_w, $hBitmap_Stamp_h)
					Else
						If $hBitmap_Stamp_w >= $hBitmap_Stamp_h Then
							$f = $hBitmap_Stamp_w / $aPos[2]
							If $hBitmap_Stamp_h / $f > $aPos[3] Then $f = $hBitmap_Stamp_w / $aPos[3]
						Else
							$f = $hBitmap_Stamp_h / $aPos[3]
						EndIf
						$w = $hBitmap_Stamp_w / $f
						$h = $hBitmap_Stamp_h / $f
						_GDIPlus_GraphicsDrawImageRect($hCtx_Stamp, $hBitmapStamp_WM, ($aPos[2] - $w) / 2, ($aPos[3] - $h) / 2, $w, $h)
					EndIf
					$hHBitmap_Stamp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapStampPreview_WM)
					$hB = GUICtrlSendMsg($idPicStampPreview_WM, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Stamp)
					If $hB Then _WinAPI_DeleteObject($hB)
					_WinAPI_DeleteObject($hHBitmap_Stamp)
					_GDIPlus_BitmapDispose($hBitmapStampPreview_WM)
					_GDIPlus_GraphicsDispose($hCtx_Stamp)
					$bStamp_WM = True
					GUICtrlSetData($idSliderAdjX_WM, 0)
					GUICtrlSetData($idSliderAdjY_WM, 0)
					$iAdjX_WM = 0
					$iAdjY_WM = 0
					GUICtrlSetState($idCheckboxFill_WM, $GUI_ENABLE)
					GUICtrlSetState($idRadioColor_WM, $GUI_UNCHECKED)
					UpdatePreview_WM()
					Disable_Controls()
					GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_WM")
					GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_WM")
					$t_wm = TimerInit()
				EndIf
			Case $idCheckboxCircular_WM
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				If BitAND(GUICtrlRead($idCheckboxCircular_WM), $GUI_CHECKED) Then
					GUICtrlSetState($idInputRadius_WM, $GUI_ENABLE)
					GUICtrlSetState($idSliderRadius_WM, $GUI_ENABLE)
				Else
					GUICtrlSetState($idInputRadius_WM, $GUI_DISABLE)
					GUICtrlSetState($idSliderRadius_WM, $GUI_DISABLE)
				EndIf
				UpdatePreview_WM()
			Case $idCheckboxFill_WM
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				If BitAND(GUICtrlRead($idCheckboxFill_WM), $GUI_CHECKED) Then
					$bFill = True
				Else
					$bFill = False
				EndIf
				UpdatePreview_WM()
			Case $idRadioUpperLeft_WM
				$iPos_WM = 1
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioUpperMid_WM
				$iPos_WM = 2
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioUpperRight_WM
				$iPos_WM = 3
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioMidLeft_WM
				$iPos_WM = 4
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioCenter_WM
				$iPos_WM = 5
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioMidRight_WM
				$iPos_WM = 6
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioButtomLeft_WM
				$iPos_WM = 7
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioButtomMid_WM
				$iPos_WM = 8
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioButtomRight_WM
				$iPos_WM = 9
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				UpdatePreview_WM()
			Case $idRadioImagePreview_WM
				$bStamp_WM = True
				GUICtrlSetLimit($idSliderDegree_WM, 400, 1)
				GUICtrlSetData($idSliderDegree_WM, 100)
				GUICtrlSetData($idInputDegree_WM, 100)
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				GUICtrlSetState($idCheckboxFill_WM, $GUI_ENABLE)
				UpdatePreview_WM()
				Disable_Controls()
			Case $idRadioColor_WM
				$bStamp_WM = False
				GUICtrlSetLimit($idSliderDegree_WM, 180, -180)
				GUICtrlSetData($idSliderDegree_WM, 0)
				GUICtrlSetData($idInputDegree_WM, 0)
				GUICtrlSetData($idSliderAdjX_WM, 0)
				GUICtrlSetData($idSliderAdjY_WM, 0)
				$iAdjX_WM = 0
				$iAdjY_WM = 0
				GUICtrlSetState($idCheckboxFill_WM, $GUI_DISABLE)
				UpdatePreview_WM()
				Enable_Controls_WM()
			Case $idButtonColor_WM
				If ControlGetFocus($hGUI_WM) <> $sButtonColorNN Then ContinueCase
				$iSaveColor_WM = $iColorFont_WM
				$iColorFont_WM = _ChooseColor(2, $iColorFont_WM, 2, HWnd($hGUI_WM))
				If Not @error Then
					GUICtrlSetBkColor($idButtonColor_WM, $iColorFont_WM)
					UpdatePreview_WM()
					If BitAND(GUICtrlRead($idRadioTxtFXEmbossed_WM), $GUI_CHECKED) = $GUI_CHECKED Then
						$iColorFont_Embossed_WM = $iColorFont_WM
					Else
						$iColorFont_Current_WM = $iColorFont_WM
					EndIf
				Else
					$iColorFont_WM = $iSaveColor_WM
				EndIf
			Case $idRadioTxtFXDefault_WM
				If ControlGetFocus($hGUI_WM) <> $sRadioTxtFXDefaultNN Then ContinueCase
				$sFX_WM = "Default"
				$iColorFont_WM = $iColorFont_Current_WM
				GUICtrlSetBkColor($idButtonColor_WM, $iColorFont_WM)
				UpdatePreview_WM()
			Case $idRadioTxtFXOutline_WM
				If ControlGetFocus($hGUI_WM) <> $sRadioTxtFXOutlineNN Then ContinueCase
				$sFX_WM = "Outlined"
				$iColorFont_WM = $iColorFont_Current_WM
				GUICtrlSetBkColor($idButtonColor_WM, $iColorFont_WM)
				UpdatePreview_WM()
			Case $idRadioTxtFXEmbossed_WM
				If ControlGetFocus($hGUI_WM) <> $sRadioTxtFXEmbossedNN Then ContinueCase
				$sFX_WM = "Embossed"
				$iColorFont_WM = $iColorFont_Embossed_WM
				GUICtrlSetBkColor($idButtonColor_WM, $iColorFont_WM)
				UpdatePreview_WM()
			Case $idButtonLoadFont_WM
				If ControlGetFocus($hGUI_WM) <> $sButtonLoadFontNN Then ContinueCase
				$sFileFont = FileOpenDialog($aTranslations[226][$iLang], "", $aTranslations[227][$iLang] & "(*.TTF)", 3, "", $hGUI_WM)
				If Not @error Then
					$bFontMan = True
					Local $hFile = _WinAPI_CreateFile($sFileFont, 2, 2, 2)
					If $hFile = 0 Then ContinueCase
					Local $lFile = FileGetSize($sFileFont)
					Local $tBuffer = DllStructCreate("byte[" & $lFile + 1 & "]")
					Local $pBuffer = DllStructGetPtr($tBuffer), $iFile
					_WinAPI_ReadFile($hFile, $pBuffer, $lFile, $iFile)
					_WinAPI_CloseHandle($hFile)
					$sFileFontName = _GetFontInfoFromFilePtr($pBuffer)
					If StringInStr($sAddFonts, $sFileFontName) Then
						MsgBox(BitOr($MB_ICONINFORMATION, $MB_TOPMOST), $aTranslations[83][$iLang], $aTranslations[228][$iLang] & $sFileFontName & @CRLF & _
								$aTranslations[229][$iLang] & $sFileFont & @CRLF & @CRLF & _
								$aTranslations[230][$iLang], 10)
					Else
						DllCall($__g_hGDIPDll, "int", "GdipPrivateAddFontFile", "ptr", $hCollection_WM, "wstr", $sFileFont)
						GUICtrlSetData($idComboFont_WM, $sFileFontName, $sFileFontName)
						$sAddFonts &= $sFileFontName & ","
						UpdatePreview_WM()
					EndIf
				EndIf
			Case $GUI_EVENT_RESTORE
				If $aero Then
					CopyImageGfx($hBmp_Preview_WM)
				Else
					DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC_WM, "int", 0, "int", 0, "int", $bW, "int", $bH, "handle", $hDC_backbuffer_WM, "int", 0, "int", 0, "dword", $SRCCOPY)
				EndIf
			Case $iKey_Undo
				GUICtrlSendMsg($idButtonUndo_WM, $BM_CLICK, 0, 0)
		EndSwitch

		$aMPos = GUIGetCursorInfo($hGUI_WM)
		If $aMPos[4] = $idPicPreview_WM And TimerDiff($t_wm) > 500 Then
			If $aMPos[2] Then
				If Not $iAdjX_WM And Not $iAdjY_WM Then
					$iMemX = 0
					$iMemY = 0
				EndIf
				$iAdjX_WM = Int(($aMPos[0] - $iOPosX) * $fAccel) + $iMemX
				$iAdjY_WM = Int(($aMPos[1] - $iOPosY) * $fAccel) + $iMemY
				GUICtrlSetData($idSliderAdjX_WM, $iAdjX_WM)
				GUICtrlSetData($idSliderAdjY_WM, $iAdjY_WM)
				$bUpdate_WM = True
			Else
				$iOPosX = $aMPos[0]
				$iOPosY = $aMPos[1]
				$iMemX = $iAdjX_WM
				$iMemY = $iAdjY_WM
			EndIf

			If $aMPos[3] Then
				$iOPosX = $aMPos[0]
				$iODeg = GUICtrlRead($idSliderDegree_WM)
				Do
					$aMPos = GUIGetCursorInfo($hGUI_WM)
					$iMRot = Mod($aMPos[0] - $iOPosX, 180) + $iODeg
					GUICtrlSetData($idSliderDegree_WM, $iMRot)
					GUICtrlSetData($idInputDegree_WM, $iMRot)
					UpdatePreview_WM()
				Until Not $aMPos[3]
			EndIf
		EndIf

		If $bUpdate_WM Then
			UpdatePreview_WM()
			$bUpdate_WM = False
		EndIf
	WEnd
EndFunc   ;==>Watermark

Func _GDIPlus_StampImage($hBmp, $hBmp_Stamp, $iPos, $iRotation_WM = 100, $fAlpha = 0.25, $iAdjX = 0, $iAdjY = 0, $bFill = False, $iMinW = 8, $iMinH = 8)
	If $fAlpha < 0 Then $fAlpha = 0
	If $fAlpha > 1 Then $fAlpha = 1
	If $hBitmap_WM Then _GDIPlus_BitmapDispose($hBitmap_WM)
	$hBitmap_WM = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	Local $hCtxt_Stamp = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Stamp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtxt_Stamp, "int", 7)
	Local $iW_Stamp = _GDIPlus_ImageGetWidth($hBmp_Stamp), $iH_Stamp = _GDIPlus_ImageGetHeight($hBmp_Stamp)

	Local $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
	Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, -(1 - $fAlpha_WM))
	Local $pColorMatrix = DllStructGetPtr($tColorMatrix)
	_GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix)
	Local $fSize = $iRotation_WM / 100, $hBrush_Fill
	If $bFill Then
		Local $hBmp_Fill = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $bW, "int", $bH, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
		$hBmp_Fill = $hBmp_Fill[6]
		Local $hCtxt_Fill = _GDIPlus_ImageGetGraphicsContext($hBmp_Fill)
		_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Fill, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
		If $fSize <> 1.00 Then
			Local $iWn = Int($iW_Stamp * $fSize), $iHn = Int($iH_Stamp * $fSize)
			Local $hBmp_tmp = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWn, "int", $iHn, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
			$hBmp_tmp = $hBmp_tmp[6]
			Local $hCtxt_tmp = _GDIPlus_ImageGetGraphicsContext($hBmp_tmp)
			_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_tmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
			DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtxt_tmp, "int", 7)
			_GDIPlus_GraphicsDrawImageRect($hCtxt_tmp, $hBmp_Stamp, 0, 0, $iWn, $iHn)
			$hBrush_Fill = DllCall($__g_hGDIPDll, "uint", "GdipCreateTexture", "ptr", $hBmp_tmp, "int", 0, "ptr*", 0)
			$hBrush_Fill = $hBrush_Fill[3]
			_GDIPlus_BitmapDispose($hBmp_tmp)
			_GDIPlus_GraphicsDispose($hCtxt_tmp)
		Else
			$hBrush_Fill = DllCall($__g_hGDIPDll, "uint", "GdipCreateTexture", "ptr", $hBmp_Stamp, "int", 0, "ptr*", 0)
			$hBrush_Fill = $hBrush_Fill[3]
		EndIf
		_GDIPlus_GraphicsFillRect($hCtxt_Fill, 0, 0, $bW, $bH, $hBrush_Fill)
		_GDIPlus_GraphicsDrawImageRectRect($hCtxt_Stamp, $hBmp_Fill, 0, 0, $bW, $bH, $iAdjX, $iAdjY, $bW, $bH, $hAttribute_Alpha)
		_GDIPlus_BrushDispose($hBrush_Fill)
		_GDIPlus_GraphicsDispose($hCtxt_Fill)
		_GDIPlus_BitmapDispose($hBmp_Fill)
	Else
		Local $iX, $iY, $fW = $iW_Stamp * $fSize, $fH = $iH_Stamp * $fSize, $fX = 0, $fY = 0
		Switch $iPos
			Case 1
				$iX = Min($iMinW, $bW)
				$iY = Min($iMinH, $bH)
			Case 2
				$iX = Abs(($bW - $iW_Stamp) / 2)
				$iY = Min($iMinH, $bH)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize) / 2
			Case 3
				$iX = Abs($bW - $iW_Stamp - Min($iMinW, $bW))
				$iY = Min($iMinH, $bH)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize)
			Case 4
				$iX = Min($iMinW, $bW)
				$iY = Abs(($bH - $iH_Stamp) / 2)
				$fY = ($iH_Stamp - $iH_Stamp * $fSize) / 2
			Case 5
				$iX = Abs(($bW - $iW_Stamp) / 2)
				$iY = Abs(($bH - $iH_Stamp) / 2)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize) / 2
				$fY = ($iH_Stamp - $iH_Stamp * $fSize) / 2
			Case 6
				$iX = Abs($bW - $iW_Stamp - Min($iMinW, $bW))
				$iY = Abs(($bH - $iH_Stamp) / 2)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize)
				$fY = ($iH_Stamp - $iH_Stamp * $fSize) / 2
			Case 7
				$iX = Min($iMinW, $bW)
				$iY = Abs($bH - Min($iMinH, $bH) - $iH_Stamp)
				$fY = ($iH_Stamp - $iH_Stamp * $fSize)
			Case 8
				$iX = Abs(($bW - $iW_Stamp) / 2)
				$iY = Abs($bH - Min($iMinH, $bH) - $iH_Stamp)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize) / 2
				$fY = ($iH_Stamp - $iH_Stamp * $fSize)
			Case 9
				$iX = Abs($bW - $iW_Stamp - Min($iMinW, $bW))
				$iY = Abs($bH - Min($iMinH, $bH) - $iH_Stamp)
				$fX = ($iW_Stamp - $iW_Stamp * $fSize)
				$fY = ($iH_Stamp - $iH_Stamp * $fSize)
		EndSwitch
		_GDIPlus_GraphicsDrawImageRectRect($hCtxt_Stamp, $hBmp_Stamp, 0, 0, $iW_Stamp, $iH_Stamp, $iX + $fX + $iAdjX, $iY + $fY + $iAdjY, $fW, $fH, $hAttribute_Alpha)
	EndIf
	_GDIPlus_GraphicsDispose($hCtxt_Stamp)
	_GDIPlus_ImageAttributesDispose($hAttribute_Alpha)
	Return $hBitmap_WM
EndFunc   ;==>_GDIPlus_StampImage

Func _GDIPlus_WatermarkImage($hBitmap, $sText, $iX, $iY, $iPos = 0, $sFontName = "Arial", $iFontSize = 16, $fAngle = 0, $iFontColor = 0xFFFFFF, $fAlpha = 0.25, $iAdjX = 0, $iAdjY = 0, $bLineBreak = True, $sFileFontName = 0)
	If $fAlpha < 0 Then $fAlpha = 0
	If $fAlpha > 1 Then $fAlpha = 1
	Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap)
	_GDIPlus_BitmapDispose($hBitmap_WM)
	$hBitmap_WM = _GDIPlus_BitmapClone($hBitmap, $iW, $iH)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
	DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt, "int", 4)
	Local $hBrush = _GDIPlus_BrushCreateSolid(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor)
	Local $hFormat = _GDIPlus_StringFormatCreate(0x0400 + 0x0800)
	Local $hFamily
	If $bFontMan Then
		$hFamily = DllCall($__g_hGDIPDll, "int", "GdipCreateFontFamilyFromName", "wstr", $sFileFontName, "ptr", $hCollection_WM, "ptr*", 0)
		$hFamily = $hFamily[3]
	Else
		$hFamily = _GDIPlus_FontFamilyCreate($sFontName)
	EndIf
	Local $iWTxt, $iHTxt
	Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0)
	Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
	Local $aMeasure = _GDIPlus_GraphicsMeasureString($hCtxt, $sText, $hFont, $tLayout, $hFormat)
	If Not @error Then
		If Not Int($fAngle) Then
			$iWTxt = Ceiling(DllStructGetData($aMeasure[0], "width"))
			$iHTxt = Ceiling(DllStructGetData($aMeasure[0], "height"))
			If $bLineBreak And $iWTxt > $iW * 0.85 Then
				DllStructSetData($tLayout, "width", $iW * 0.95)
				DllStructSetData($tLayout, "height", 0)
				$aMeasure = _GDIPlus_GraphicsMeasureString($hCtxt, $sText, $hFont, $tLayout, $hFormat)
				$iWTxt = Ceiling(DllStructGetData($aMeasure[0], "width"))
				$iHTxt = Ceiling(DllStructGetData($aMeasure[0], "height"))
			EndIf

			If Not Int($iPos) Or Int($iPos) > 9 Then
				DllStructSetData($tLayout, "x", $iX)
				DllStructSetData($tLayout, "y", $iY)
			Else
				DllStructSetData($tLayout, "x", $iFontSize / 2 + $iAdjX)
				DllStructSetData($tLayout, "width", $iW - $iFontSize)
				Switch $iPos
					Case 1 To 3
						DllStructSetData($tLayout, "y", $iAdjY)
						_GDIPlus_StringFormatSetAlign($hFormat, $iPos - 1)
					Case 4 To 6
						DllStructSetData($tLayout, "y", ($iH - $iHTxt) / 2 + $iAdjY)
						_GDIPlus_StringFormatSetAlign($hFormat, $iPos - 4)
					Case 7 To 9
						DllStructSetData($tLayout, "y", $iH - $iHTxt + $iAdjY)
						_GDIPlus_StringFormatSetAlign($hFormat, $iPos - 7)
				EndSwitch
			EndIf
			Switch $sFX_WM
				Case "Default"
					_GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)
				Case "Outlined"
					Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreatePath", "int", 0, "ptr*", 0)
					Local $hPath_WM = $aResult[2], $iPenSize
					Switch $iFontSize
						Case 4 To 64
							$iPenSize = 1
						Case 65 To 99
							$iPenSize = 2
						Case Else
							$iPenSize = 3
					EndSwitch
					$aResult = DllCall($__g_hGDIPDll, "uint", "GdipAddPathString", "handle", $hPath_WM, "wstr", $sText, "int", -1, "handle", $hFamily, "int", 0, "float", $iFontSize * 1.3333333, "ptr", DllStructGetPtr($tLayout), "handle", $hFormat)
					Local $hPen_WM = _GDIPlus_PenCreate(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor, $iPenSize)
					DllCall($__g_hGDIPDll, "uint", "GdipDrawPath", "handle", $hCtxt, "handle", $hPen_WM, "handle", $hPath_WM)
					DllCall($__g_hGDIPDll, "uint", "GdipDeletePath", "handle", $hPath_WM)
					_GDIPlus_PenDispose($hPen_WM)
				Case "Embossed"
					Local $iDelta
					If $iFontSize < 100 Then
						$iDelta = 2
					Else
						$iDelta = 4
					EndIf
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + 0xFFFFFF)
					_GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + 0x303030)
					DllStructSetData($tLayout, "x", DllStructGetData($tLayout, "x") + $iDelta)
					DllStructSetData($tLayout, "y", DllStructGetData($tLayout, "y") + $iDelta)
					_GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor)
					DllStructSetData($tLayout, "x", DllStructGetData($tLayout, "x") - $iDelta / 2)
					DllStructSetData($tLayout, "y", DllStructGetData($tLayout, "y") - $iDelta / 2)
					_GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)
			EndSwitch
		Else
			Local $iQ
			$fAngle = Mod($fAngle, 360)
			$iWTxt = DllStructGetData($aMeasure[0], "width")
			$iHTxt = DllStructGetData($aMeasure[0], "height")
			If $iWTxt > $iHTxt Then
				$iQ = $iWTxt
			Else
				$iQ = $iHTxt
			EndIf
			Local $hBitmap_WM_Rot, $hCtxt_Rot, $hMatrix, $iR

			If $iPos Then
				Switch $iPos
					Case 1
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ - $iFontSize - $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, $fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ + $iFontSize + $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2) ;position of the text within rotation bitmap
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = (-$iQ + $iFontSize + $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = (-$iQ + $iHTxt) / 2 + $iAdjY

					Case 2
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, $iQ / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, $fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, -$iQ / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", 0)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = ($iFontSize + $iW - $iQ) / 2 + $iAdjX
						$iR = $iWTxt / 2 ;Sqrt((($iWTxt + $iHTxt) / 2) ^ 2)
						$iY = -$iR + $iFontSize / 1.25 + Cos((Abs($fAngle) - 90) / $fRad) * $iR * 0.9 + $iAdjY
					Case 3
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ + $iFontSize + $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, -$fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ - $iFontSize - $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = $iW + (-$iQ - $iFontSize - $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = (-$iQ + $iHTxt) / 2 + $iAdjY
					Case 4
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ - $iFontSize - $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, $fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ + $iFontSize + $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = (-$iQ + $iFontSize + $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = ($iH - $iQ) / 2 + $iAdjY
					Case 5
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, $iQ / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, $fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, -$iQ / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", 0)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = ($iW - $iQ) / 2 + $iAdjX
						$iY = ($iH - $iQ) / 2 + $iAdjY
					Case 6
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ + $iFontSize + $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, -$fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ - $iFontSize - $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = $iW + (-$iQ - $iFontSize - $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = ($iH - $iQ) / 2 + $iAdjY
					Case 7
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ - $iFontSize - $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, $fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ + $iFontSize + $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = (-$iQ + $iFontSize + $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = $iH + (-$iQ - $iHTxt) / 2 + $iAdjY
					Case 8
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, $iQ / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, -$fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, -$iQ / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", 0)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = ($iFontSize + $iW - $iQ) / 2 + $iAdjX
						$iR = $iWTxt / 2 ;Sqrt((($iWTxt + $iHTxt) / 2) ^ 2)
						$iY = $iH - $iR - $iFontSize / 1.25 - Cos((Abs($fAngle) - 90) / $fRad) * $iR * 0.9 + $iAdjY
					Case 9
						$iQ *= 3.25
						$hBitmap_WM_Rot = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iQ, "int", $iQ, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
						$hBitmap_WM_Rot = $hBitmap_WM_Rot[6]
						$hCtxt_Rot = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM_Rot)
						_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Rot, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
						_GDIPlus_GraphicsSetSmoothingMode($hCtxt_Rot, 2)
						DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt_Rot, "int", 4)
						$hMatrix = _GDIPlus_MatrixCreate()
						_GDIPlus_MatrixTranslate($hMatrix, ($iQ + $iFontSize + $iWTxt) / 2, $iQ / 2)
						_GDIPlus_MatrixRotate($hMatrix, -$fAngle, False)
						_GDIPlus_MatrixTranslate($hMatrix, (-$iQ - $iFontSize - $iWTxt) / 2, -$iQ / 2)
						_GDIPlus_GraphicsSetTransform($hCtxt_Rot, $hMatrix)
						DllStructSetData($tLayout, "x", ($iQ - $iWTxt) / 2)
						DllStructSetData($tLayout, "y", ($iQ - $iHTxt) / 2)
						$iX = $iW + (-$iQ - $iFontSize - $iWTxt) / 2 + $iAdjX ;position of the rotated bitmap onto the main bitmap
						$iY = $iH + (-$iQ - $iHTxt) / 2 + $iAdjY
				EndSwitch
			EndIf

			Switch $sFX_WM
				Case "Default"
					_GDIPlus_GraphicsDrawStringEx($hCtxt_Rot, $sText, $hFont, $tLayout, $hFormat, $hBrush)
				Case "Outlined"
					Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreatePath", "int", 0, "ptr*", 0)
					Local $hPath_WM = $aResult[2], $iPenSize
					Switch $iFontSize
						Case 4 To 64
							$iPenSize = 1
						Case 65 To 99
							$iPenSize = 2
						Case Else
							$iPenSize = 3
					EndSwitch
					$aResult = DllCall($__g_hGDIPDll, "uint", "GdipAddPathString", "handle", $hPath_WM, "wstr", $sText, "int", -1, "handle", $hFamily, "int", 0, "float", $iFontSize * 1.3333333, "struct*", DllStructGetPtr($tLayout), "handle", $hFormat)
					Local $hPen_WM = _GDIPlus_PenCreate(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor, $iPenSize)
					DllCall($__g_hGDIPDll, "uint", "GdipDrawPath", "handle", $hCtxt_Rot, "handle", $hPen_WM, "handle", $hPath_WM)
					DllCall($__g_hGDIPDll, "uint", "GdipDeletePath", "handle", $hPath_WM)
					_GDIPlus_PenDispose($hPen_WM)
				Case "Embossed"
					Local $iDelta
					If $iFontSize < 100 Then
						$iDelta = 2
					Else
						$iDelta = 4
					EndIf
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + 0xFFFFFF)
					_GDIPlus_GraphicsDrawStringEx($hCtxt_Rot, $sText, $hFont, $tLayout, $hFormat, $hBrush)
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + 0x303030)
					DllStructSetData($tLayout, "x", DllStructGetData($tLayout, "x") + $iDelta)
					DllStructSetData($tLayout, "y", DllStructGetData($tLayout, "y") + $iDelta)
					_GDIPlus_GraphicsDrawStringEx($hCtxt_Rot, $sText, $hFont, $tLayout, $hFormat, $hBrush)
					_GDIPlus_BrushSetSolidColor($hBrush, BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor)
					DllStructSetData($tLayout, "x", DllStructGetData($tLayout, "x") - $iDelta / 2)
					DllStructSetData($tLayout, "y", DllStructGetData($tLayout, "y") - $iDelta / 2)
					_GDIPlus_GraphicsDrawStringEx($hCtxt_Rot, $sText, $hFont, $tLayout, $hFormat, $hBrush)
			EndSwitch

			_GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap_WM_Rot, $iX, $iY, $iQ, $iQ)
			_GDIPlus_MatrixDispose($hMatrix)
			_GDIPlus_GraphicsDispose($hCtxt_Rot)
			_GDIPlus_BitmapDispose($hBitmap_WM_Rot)
		EndIf
	EndIf
	_GDIPlus_FontDispose($hFont)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_GraphicsDispose($hCtxt)
	$tLayout = 0
	Return $hBitmap_WM
EndFunc   ;==>_GDIPlus_WatermarkImage

Func _GDIPlus_CreateRotatedLetters($hBitmap, $sText, $iPos = 9, $iFontSize = 16, $iRadius = 100, $sFont = "Impact", $iFontColor = 0xFFFFFF, $fAlpha = 0.04, $fStart_angle = 0, $iAdjX = 0, $iAdjY = 0, $sFileFontName = 0)
	If $fAlpha < 0 Then $fAlpha = 0
	If $fAlpha > 1 Then $fAlpha = 1
	Local $iPosX, $iPosY
	Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap)
	If $hBitmap_WM Then _GDIPlus_BitmapDispose($hBitmap_WM)
	$hBitmap_WM = _GDIPlus_BitmapClone($hBitmap, $iW, $iH)
	Switch $iPos
		Case 1
			$iPosX = $iRadius + $iFontSize
			$iPosY = $iRadius + $iFontSize
		Case 2
			$iPosX = $iW / 2
			$iPosY = $iRadius + $iFontSize
		Case 3
			$iPosX = $iW - ($iRadius + $iFontSize)
			$iPosY = $iRadius + $iFontSize
		Case 4
			$iPosX = $iRadius + $iFontSize
			$iPosY = $iH / 2
		Case 5
			$iPosX = $iW / 2
			$iPosY = $iH / 2
		Case 6
			$iPosX = $iW - ($iRadius + $iFontSize)
			$iPosY = $iH / 2
		Case 7
			$iPosX = $iRadius + $iFontSize
			$iPosY = $iH - ($iRadius + $iFontSize)
		Case 8
			$iPosX = $iW / 2
			$iPosY = $iH - ($iRadius + $iFontSize)
		Case 9
			$iPosX = $iW - ($iRadius + $iFontSize)
			$iPosY = $iH - ($iRadius + $iFontSize)
	EndSwitch
	Local Const $iW2 = $iPosX
	Local Const $iH2 = $iPosY
	Local Const $sLen = StringLen($sText)
	Local Const $delta_a = Floor(360 / $sLen)
	Local Const $iLetter_w = 256, $iLetter_h = 256
	Local Const $iLetter_w2 = $iLetter_w / 2
	Local Const $iLetter_h2 = $iLetter_h / 2
	Local Const $fCenter_x = $iW2 - $iLetter_w2
	Local Const $fCenter_y = $iH2 - $iLetter_h2
	Local Const $fDeg = ACos(-1) / 180

	Local $aTable[$sLen][14]
	Local $i, $a, $lW, $lH, $x, $y, $aRes, $aFamily
	Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap_WM)
	_GDIPlus_GraphicsSetPixelOffsetMode($hContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	For $i = 0 To $sLen - 1 ;generate table
		$aTable[$i][0] = StringMid($sText, $i + 1, 1) ;get next letter
		$aRes = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iLetter_w, "int", $iLetter_h, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0) ;create empty 32 bit bitmap
		$aTable[$i][1] = $aRes[6] ;create bitmap
		$aTable[$i][2] = _GDIPlus_ImageGetGraphicsContext($aTable[$i][1]) ;create context of bitmap to draw to bitmap
		_GDIPlus_GraphicsSetPixelOffsetMode($aTable[$i][2], $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
		$aTable[$i][3] = _GDIPlus_BrushCreateSolid(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor)
		$aTable[$i][4] = _GDIPlus_StringFormatCreate(0x1404) ;$hFormat
		If $bFontMan Then
			$aFamily = DllCall($__g_hGDIPDll, "int", "GdipCreateFontFamilyFromName", "wstr", $sFileFontName, "ptr", $hCollection_WM, "ptr*", 0)
			$aTable[$i][5] = $aFamily[3]
		Else
			$aTable[$i][5] = _GDIPlus_FontFamilyCreate($sFont) ;$hFamily
		EndIf
		$aTable[$i][6] = _GDIPlus_FontCreate($aTable[$i][5], $iFontSize) ;$hFont
		$aTable[$i][7] = _GDIPlus_RectFCreate(0, 0, 0, 0) ;$tLayout
		$aTable[$i][8] = _GDIPlus_GraphicsMeasureString($aTable[$i][2], $aTable[$i][0], $aTable[$i][6], $aTable[$i][7], $aTable[$i][4])
		$aTable[$i][9] = _GDIPlus_MatrixCreate() ;create a matrix for each letter
		$aTable[$i][10] = $i * $delta_a + $fStart_angle ;calculate angle of letter
		$aTable[$i][11] = $iRadius ;radius
		$aTable[$i][12] = _GDIPlus_PenCreate(BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor, 1) ;$hPen

		_GDIPlus_GraphicsSetSmoothingMode($aTable[$i][2], 2)
		DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $aTable[$i][2], "int", 4)

		_GDIPlus_GraphicsClear($aTable[$i][2], 0x00000000)
		;calculated possition of letter to place it in the middle of the graphic
		$a = $aTable[$i][8]
		$lW = DllStructGetData($a[0], "width")
		$lH = DllStructGetData($a[0], "height")
		DllStructSetData($a[0], "x", $iLetter_w2 - $lW / 2)
		DllStructSetData($a[0], "y", $iLetter_h2 - $lH / 2)

		;rotate letter
		_GDIPlus_MatrixTranslate($aTable[$i][9], $iLetter_w2, $iLetter_h2)
		_GDIPlus_MatrixRotate($aTable[$i][9], -27 + $aTable[$i][10], False)
		_GDIPlus_MatrixTranslate($aTable[$i][9], -$iLetter_w2, -$iLetter_h2)
		_GDIPlus_GraphicsSetTransform($aTable[$i][2], $aTable[$i][9])

		;print letter to bitmap
		Switch $sFX_WM
			Case "Default"
				_GDIPlus_GraphicsDrawStringEx($aTable[$i][2], $aTable[$i][0], $aTable[$i][6], $a[0], $aTable[$i][4], $aTable[$i][3])
			Case "Outlined"
				Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreatePath", "int", 0, "ptr*", 0)
				Local $hPath_WM = $aResult[2], $iPenSize
				Switch $iFontSize
					Case 4 To 64
						$iPenSize = 1
					Case 65 To 99
						$iPenSize = 2
					Case Else
						$iPenSize = 3
				EndSwitch
				_GDIPlus_PenSetWidth($aTable[$i][12], $iPenSize)
				$aResult = DllCall($__g_hGDIPDll, "uint", "GdipAddPathString", "handle", $hPath_WM, "wstr", $aTable[$i][0], "int", -1, "handle", $aTable[$i][5], "int", 0, "float", $iFontSize * 1.3333333, "struct*", DllStructGetPtr($a[0]), "handle", $aTable[$i][4])
				DllCall($__g_hGDIPDll, "uint", "GdipDrawPath", "handle", $aTable[$i][2], "handle", $aTable[$i][12], "handle", $hPath_WM)
				DllCall($__g_hGDIPDll, "uint", "GdipDeletePath", "handle", $hPath_WM)
			Case "Embossed"
				Local $iDelta
				If $iFontSize < 100 Then
					$iDelta = 2
				Else
					$iDelta = 4
				EndIf
				_GDIPlus_BrushSetSolidColor($aTable[$i][3], BitShift(Int($fAlpha * 0xFF), -24) + 0xFFFFFF)
				_GDIPlus_GraphicsDrawStringEx($aTable[$i][2], $aTable[$i][0], $aTable[$i][6], $a[0], $aTable[$i][4], $aTable[$i][3])
				_GDIPlus_BrushSetSolidColor($aTable[$i][3], BitShift(Int($fAlpha * 0xFF), -24) + 0x303030)
				DllStructSetData($a[0], "x", DllStructGetData($a[0], "x") + $iDelta)
				DllStructSetData($a[0], "y", DllStructGetData($a[0], "y") + $iDelta)
				_GDIPlus_GraphicsDrawStringEx($aTable[$i][2], $aTable[$i][0], $aTable[$i][6], $a[0], $aTable[$i][4], $aTable[$i][3])
				_GDIPlus_BrushSetSolidColor($aTable[$i][3], BitShift(Int($fAlpha * 0xFF), -24) + $iFontColor)
				DllStructSetData($a[0], "x", DllStructGetData($a[0], "x") - $iDelta / 2)
				DllStructSetData($a[0], "y", DllStructGetData($a[0], "y") - $iDelta / 2)
				_GDIPlus_GraphicsDrawStringEx($aTable[$i][2], $aTable[$i][0], $aTable[$i][6], $a[0], $aTable[$i][4], $aTable[$i][3])
		EndSwitch

		;copy letter to main screen in a circle
		$x = $fCenter_x + Cos(-90 + $aTable[$i][10] * $fDeg) * $aTable[$i][11]
		$y = $fCenter_y + Sin(-90 + $aTable[$i][10] * $fDeg) * $aTable[$i][11]
		_GDIPlus_GraphicsDrawImageRect($hContext, $aTable[$i][1], $x + $iAdjX, $y + $iAdjY, $iLetter_w, $iLetter_h)
	Next

	For $i = 0 To $sLen - 1
		_GDIPlus_BitmapDispose($aTable[$i][1])
		_GDIPlus_GraphicsDispose($aTable[$i][2])
		_GDIPlus_BrushDispose($aTable[$i][3])
		_GDIPlus_StringFormatDispose($aTable[$i][4])
		_GDIPlus_FontFamilyDispose($aTable[$i][5])
		_GDIPlus_FontDispose($aTable[$i][6])
		_GDIPlus_MatrixDispose($aTable[$i][9])
		_GDIPlus_PenDispose($aTable[$i][12])
	Next
	_GDIPlus_GraphicsDispose($hContext)
	Return $hBitmap_WM
EndFunc   ;==>_GDIPlus_CreateRotatedLetters

Func Enable_Controls_WM()
	GUICtrlSetState($idInputText_WM, $GUI_ENABLE)
	GUICtrlSetState($idComboFont_WM, $GUI_ENABLE)
	GUICtrlSetState($idInputFSize_WM, $GUI_ENABLE)
	GUICtrlSetState($idUpdown_WM, $GUI_ENABLE)
	GUICtrlSetState($idButtonColor_WM, $GUI_ENABLE)
	GUICtrlSetState($idCheckboxCircular_WM, $GUI_ENABLE)
	If BitAND(GUICtrlRead($idCheckboxCircular_WM), $GUI_CHECKED) = $GUI_CHECKED Then
		GUICtrlSetState($idSliderRadius_WM, $GUI_ENABLE)
		GUICtrlSetState($idInputRadius_WM, $GUI_ENABLE)
	EndIf
	GUICtrlSetState($idRadioTxtFXDefault_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioTxtFXOutline_WM, $GUI_ENABLE)
	GUICtrlSetState($idRadioTxtFXEmbossed_WM, $GUI_ENABLE)
	GUICtrlSetState($idButtonLoadFont_WM, $GUI_ENABLE)
EndFunc   ;==>Enable_Controls_WM

Func Disable_Controls()
	GUICtrlSetState($idInputText_WM, $GUI_DISABLE)
	GUICtrlSetState($idComboFont_WM, $GUI_DISABLE)
	GUICtrlSetState($idInputFSize_WM, $GUI_DISABLE)
	GUICtrlSetState($idUpdown_WM, $GUI_DISABLE)
	GUICtrlSetState($idCheckboxCircular_WM, $GUI_DISABLE)
	GUICtrlSetState($idButtonColor_WM, $GUI_DISABLE)
	GUICtrlSetState($idInputRadius_WM, $GUI_DISABLE)
	GUICtrlSetState($idSliderRadius_WM, $GUI_DISABLE)
	GUICtrlSetState($idRadioTxtFXDefault_WM, $GUI_DISABLE)
	GUICtrlSetState($idRadioTxtFXOutline_WM, $GUI_DISABLE)
	GUICtrlSetState($idRadioTxtFXEmbossed_WM, $GUI_DISABLE)
	GUICtrlSetState($idButtonLoadFont_WM, $GUI_DISABLE)
EndFunc   ;==>Disable_Controls

Func UpdatePreview_WM()
	$sText_WM = GUICtrlRead($idInputText_WM)
	$sFont_WM = GUICtrlRead($idComboFont_WM)
	$fAlpha_WM = GUICtrlRead($idInputOpaque_WM) / 0xFF
	$iFontSize_WM = GUICtrlRead($idInputFSize_WM)
	$iRadius_WM = GUICtrlRead($idInputRadius_WM)
	$iRotation_WM = GUICtrlRead($idInputDegree_WM)
	If $hBmp_Preview_WM Then _GDIPlus_BitmapDispose($hBmp_Preview_WM)
	$hBmp_Preview_WM = 0
	If Not $bStamp_WM Then
		If BitAND(GUICtrlRead($idCheckboxCircular_WM), $GUI_CHECKED) Then
			$hBmp_Preview_WM = _GDIPlus_CreateRotatedLetters($hBmp, $sText_WM, $iPos_WM, $iFontSize_WM, $iRadius_WM, $sFont_WM, $iColorFont_WM, $fAlpha_WM, $iRotation_WM, $iAdjX_WM, $iAdjY_WM, $sFileFontName)
		Else
			$hBmp_Preview_WM = _GDIPlus_WatermarkImage($hBmp, $sText_WM, $iManPosX, $iManPosY, $iPos_WM, $sFont_WM, $iFontSize_WM, $iRotation_WM, $iColorFont_WM, $fAlpha_WM, $iAdjX_WM, $iAdjY_WM, True, $sFileFontName)
		EndIf
	Else
		$hBmp_Preview_WM = _GDIPlus_StampImage($hBmp, $hBitmapStamp_WM, $iPos_WM, $iRotation_WM, $fAlpha_WM, $iAdjX_WM, $iAdjY_WM, $bFill)
	EndIf
	CopyImageGfx($hBmp_Preview_WM)
	Sleep(10)
EndFunc   ;==>UpdatePreview_WM

Func CopyImageGfx($hBmp)
	Local $w, $h, $f
	_GDIPlus_GraphicsClear($hGraphic_WM, 0xFF000000 + $iGUI_WM_color)
	If $bW < $iW_Pic_WM And $bH < $iH_Pic_WM Then
		_GDIPlus_GraphicsDrawImageRect($hGraphic_WM, $hBmp, ($iW_Pic_WM - $bW) / 2, ($iH_Pic_WM - $bH) / 2, $bW, $bH)
	Else
		If $bW >= $bH Then
			$f = $bW / $iW_Pic_WM
			If ($bH / $f) > $iH_Pic_WM Then $f = $bH / $iH_Pic_WM
		Else
			$f = $bH / $iH_Pic_WM
		EndIf
		$w = Int($bW / $f)
		$h = Int($bH / $f)
		_GDIPlus_GraphicsDrawImageRect($hGraphic_WM, $hBmp, ($iW_Pic_WM - $w) / 2, ($iH_Pic_WM - $h) / 2, $w, $h)
	EndIf
	DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC_WM, "int", 0, "int", 0, "int", $iW_Pic_WM, "int", $iH_Pic_WM, "handle", $hDC_backbuffer_WM, "int", 0, "int", 0, "dword", $SRCCOPY)
EndFunc   ;==>CopyImageGfx
#EndRegion Watermark

#Region Windows Message Codes
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $ilParam
	Local $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "int", $iwParam, "int", -1, "ptr", 0, "int", 0)
	If @error Then Return SetError(1, 0, "GUI_RUNDEFMSG")

	Local $sDroppedFile, $tBuffer = DllStructCreate("char[256]")
	If $aRet[0] = 1 Then
		DllCall("shell32.dll", "int", "DragQueryFile", "int", $iwParam, "int", 0, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer))
		$sDroppedFile = DllStructGetData($tBuffer, 1)
		If StringInStr(FileGetAttrib($sDroppedFile), "D") Then
			DllCall("shell32.dll", "none", "DragFinish", "int", $iwParam)
			Return 0 ;This is not a file
		EndIf
	EndIf
	DllCall("shell32.dll", "none", "DragFinish", "int", $iwParam)
	$tBuffer = 0
	LoadFileToGUI($sDroppedFile)
;~ 	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_DROPFILES

; Handle $WM_DRAWCLIPBOARD messages
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg
	; Display any text on clipboard
;~     ConsoleWrite("GUI handle ............: " & $hGUI & @LF)
;~     ConsoleWrite("Clipboard owner .......: " & _ClipBoard_GetOwner() & @LF)
;~     ConsoleWrite("Clipboard open window .: " & _ClipBoard_GetOpenWindow() & @LF)
;~     ConsoleWrite("Clipboard sequence ....: " & _ClipBoard_GetSequenceNumber() & @LF & @LF)
	If _ClipBoard_GetOwner() <> $hGUI Then $bCBChanged = True
	; Pass the message to the next viewer
	If $hNext <> 0 Then _SendMessage($hNext, $WM_DRAWCLIPBOARD, $iwParam, $ilParam)
EndFunc   ;==>WM_DRAWCLIPBOARD

Func WM_LBUTTONDOWN($hWnd, $iMsg, $StartWindowPosaram, $lParam) ;thanks to martin
	Local $drag = GetMousePosType()
	If $drag > 0 And $hWnd = $hGUI_MarkArea Then DllCall($dll, "long", "SendMessage", "hwnd", HWnd($hWnd), "int", $WM_SYSCOMMAND, "int", 0xF000 + $drag, "int", 0) ;resize window
;~ 	If $drag > 0 And $hWnd = $hGUI_MarkArea Then _SendMessage($hWnd, $WM_SYSCOMMAND, 0xF000 + $drag, 0)
	;F001 = LHS, F002 = RHS, F003 = top, F004 = TopLeft, F005 = TopRight, F006 = Bottom, F007 = BL, F008 = BR
	;F009 = move gui, same as F011 F012  to F01F
	;F010,  moves cursor to centre top of gui - no idea what that is useful for.
	;F012,  $SC_DRAGMOVE
	;F020 minimizes
	;F030 maximizes
	If $hWnd = $hGUI_MarkArea_Child Then DllCall($dll, "long", "SendMessage", "hwnd", HWnd($hGUI_MarkArea), "int", $WM_SYSCOMMAND, "int", 0xF012, "int", 0) ;move window
EndFunc   ;==>WM_LBUTTONDOWN

Func WM_WINMOVE($hWnd, $iMsg, $wParam, $lParam)
;~ 	Draw_Zoom_Preview(MouseGetPos(0), MouseGetPos(1))
;~ 	ToolTip($aTranslations[86][$iLang] & $w_area & "x" & $h_area & @CRLF & $aTranslations[87][$iLang] & MouseGetPos(0) & "," & MouseGetPos(1) & @LF & $aTranslations[104][$iLang] & @LF & $aTranslations[105][$iLang], $drx + MouseGetPos(0), $dry + MouseGetPos(1))
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
	If Not DllStructGetData($stWinPos, 3) And Not DllStructGetData($stWinPos, 4) Then Return "GUI_RUNDEFMSG" ;no position change on x or y
	WM_SIZE(0, -1, 0, 0)
;~ 	Draw_Zoom_Preview(MouseGetPos(0), MouseGetPos(1))
	Return 0
EndFunc   ;==>WM_WINMOVE

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $wParam, $lParam
	Local $aGUI_size = WinGetClientSize($hGUI_MarkArea)
	Local $mpos = MouseGetPos()
	If $iMsg <> -1 Then
		Local $aGUI_pos = WinGetPos($hGUI_MarkArea)
		_GuiHole($hGUI_MarkArea, $margin, $margin, $aGUI_pos[2] - 2 * $margin, $aGUI_pos[3] - 2 * $margin, $aGUI_pos[2], $aGUI_pos[3])
		WinMove($hGUI_MarkArea_Child, "", $aGUI_pos[0] + $margin, $aGUI_pos[1] + $margin, $aGUI_pos[2] - 2 * $margin, $aGUI_pos[3] - 2 * $margin)
	EndIf
	Local Static $iShow = 1
	If Not Mod($iShow, 25) Then
		Draw_Zoom_Preview($mpos[0], $mpos[1])
	EndIf
	$iShow += 1
	$w_area = $aGUI_size[0]
	$h_area = $aGUI_size[1]
	Local Static $iTimer = TimerInit()
	If TimerDiff($iTimer) > 49 Then
		ToolTip($aTranslations[86][$iLang] & $w_area & "x" & $h_area & @CRLF & $aTranslations[87][$iLang] & $mpos[0] & "," & $mpos[1] & @LF & $aTranslations[104][$iLang] & @LF & $aTranslations[105][$iLang], $drx + $mpos[0], $dry + $mpos[1])
		$iTimer = TimerInit()
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_SIZE

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	Local $d, $dd, $iX, $iY
	Switch $wParam
		Case $id_Low
			If Not $bAuto Then
				_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 0)
				_GDIPlus_GraphicsSetInterpolationMode($hContext, 5)
				Zoom(2)
			EndIf
		Case $id_Medium
			If Not $bAuto Then
				_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 1)
				_GDIPlus_GraphicsSetInterpolationMode($hContext, 0)
				Zoom(2)
			EndIf
		Case $id_High
			If Not $bAuto Then
				_GUICtrlMenu_CheckRadioItem($hQMenu_Sub, 0, 2, 2)
				_GDIPlus_GraphicsSetInterpolationMode($hContext, 7)
				Zoom(2)
			EndIf
		Case $id_Auto
			$bAuto = BitXOR($bAuto, 1)
			_GUICtrlMenu_CheckMenuItem($hQMenu_Sub, 4, $bAuto)
			If $bAuto Then
				AutoDisplaySettings()
				Zoom(2)
			EndIf
		Case $id_Reset
			$z = 10
			Zoom(-1)
		Case $id_Gray
			_GDIPlus_BitmapCreateGrayscale($hBmp)
			Zoom(2)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
		Case $id_BW
			_GDIPlus_BitmapCreateBnW($hBmp, 160)
			Zoom(2)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
		Case $id_Invert
			_GDIPlus_BitmapCreateNegative($hBmp)
			Zoom(2)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
		Case $id_Rotm90 ;rotate -90°
			FlipImage(3)
			Zoom(-1)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
		Case $id_Rotp90 ;rotate +90°
			FlipImage(1)
			Zoom(-1)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
		Case $id_Undo
			Undo()
			Zoom(2)
			_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 2)
		Case $id_ImgEditor
			If Call_ImageEditor() Then
				_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
				GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
			EndIf
		Case $id_Watermark
			If Call_Watermark() Then
				_GUICtrlMenu_EnableMenuItem($hQMenu_Sub3, 6, 0)
				GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
			EndIf
		Case $Button_Clipboard_Menu_Sub_Item1
			GUICtrlSetState($Button_Clipboard_Menu_Sub_Item1, $GUI_CHECKED)
			GUICtrlSetState($Button_Clipboard_Menu_Sub_Item2, $GUI_UNCHECKED)
			$image2clipboard = True
		Case $Button_Clipboard_Menu_Sub_Item2
			GUICtrlSetState($Button_Clipboard_Menu_Sub_Item1, $GUI_UNCHECKED)
			GUICtrlSetState($Button_Clipboard_Menu_Sub_Item2, $GUI_CHECKED)
			$image2clipboard = False
		Case $Button_Clipboard_Menu_Sub2
			If BitAND(GUICtrlRead($Button_Clipboard_Menu_Sub2), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Clipboard_Menu_Sub2, $GUI_UNCHECKED)
				$bClipboard_PNG = False
				$bClipboard_Shadow = False
			Else
				GUICtrlSetState($Button_Clipboard_Menu_Sub2, $GUI_CHECKED)
				GUICtrlSetState($Button_Clipboard_Menu_Sub3, $GUI_UNCHECKED)
				$bClipboard_PNG = True
				$bClipboard_Shadow = False
			EndIf
		Case $Button_Clipboard_Menu_Sub3
			If BitAND(GUICtrlRead($Button_Clipboard_Menu_Sub3), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Clipboard_Menu_Sub3, $GUI_UNCHECKED)
				$bClipboard_Shadow = False
				$bClipboard_PNG = False
			Else
				GUICtrlSetState($Button_Clipboard_Menu_Sub3, $GUI_CHECKED)
				GUICtrlSetState($Button_Clipboard_Menu_Sub2, $GUI_UNCHECKED)
				$bClipboard_Shadow = True
				$bClipboard_PNG = False
			EndIf
		Case $Button_Menu_Item1
			ControlClick($hGUI, "", $Button_JPG_Quality)
		Case $Button_Menu_Item2
			If BitAND(GUICtrlRead($Button_Menu_Item2), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Menu_Item2, $GUI_UNCHECKED)
			Else
				GUICtrlSetState($Button_Menu_Item2, $GUI_CHECKED)
			EndIf
		Case $Button_Menu_Item3
			If BitAND(GUICtrlRead($Button_Menu_Item3), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Menu_Item3, $GUI_UNCHECKED)
			Else
				GUICtrlSetState($Button_Menu_Item3, $GUI_CHECKED)
			EndIf
		Case $Button_Menu_Item4
			If BitAND(GUICtrlRead($Button_Menu_Item4), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Menu_Item4, $GUI_UNCHECKED)
			Else
				GUICtrlSetState($Button_Menu_Item4, $GUI_CHECKED)
			EndIf
		Case $aButton_Menu_AVI_Sub1_Item[0]
			$dd = 0
			For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub1_Item[1]
			$dd = 1
			For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub1_Item[2]
			$dd = 2
			For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub1_Item[3]
			$dd = 3
			For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub1_Item[4]
			$dd = 4
			For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub1_Item[UBound($aButton_Menu_AVI_Sub1_Item) - 1]
			$dd = 5
			Local $new_time = "10000"
			$iX = MouseGetPos(0) - 250
			$iY = MouseGetPos(1) - 150
			While Not StringIsInt($new_time) Or $new_time < 1 Or $new_time > 600
				Local $new_time = InputBox($aTranslations[234][$iLang], $aTranslations[235][$iLang], 15, "", -1, 140, $iX, $iY, 0, $hGUI)
				If @error Then ExitLoop
			WEnd
			If Not @error Then
				$AVI_ReqTime[$dd] = $new_time
				GUICtrlSetData($aButton_Menu_AVI_Sub1_Item[$dd], $aTranslations[236][$iLang] & $new_time & $aTranslations[67][$iLang])
				For $d = 0 To UBound($aButton_Menu_AVI_Sub1_Item) - 1
					If $d = $dd Then
						GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_CHECKED)
					Else
						GUICtrlSetState($aButton_Menu_AVI_Sub1_Item[$d], $GUI_UNCHECKED)
					EndIf
				Next
			EndIf
		Case $aButton_Menu_AVI_Sub2_Item[0]
			$dd = 0
			For $d = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub2_Item[4], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub2_Item[1]
			$dd = 1
			For $d = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub2_Item[4], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub2_Item[2]
			$dd = 2
			For $d = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub2_Item[4], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub2_Item[3]
			$dd = 3
			For $d = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
				If $d = $dd Then
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_UNCHECKED)
				EndIf
			Next
			GUICtrlSetData($aButton_Menu_AVI_Sub2_Item[4], $aTranslations[68][$iLang])
		Case $aButton_Menu_AVI_Sub2_Item[4]
			$dd = 4
			Local $new_fps = "100"
			$iX = MouseGetPos(0) - 250
			$iY = MouseGetPos(1) - 150
			While Not StringIsInt($new_fps) Or $new_fps < 1 Or $new_fps > 30
				Local $new_fps = InputBox($aTranslations[237][$iLang], $aTranslations[238][$iLang], 3, "", -1, 140, $iX, $iY, 0, $hGUI)
				If @error Then ExitLoop
			WEnd
			If Not @error Then
				$AVI_FPS[$dd] = $new_fps
				GUICtrlSetData($aButton_Menu_AVI_Sub2_Item[$dd], $aTranslations[236][$iLang] & $new_fps & $aTranslations[70][$iLang])
				For $d = 0 To UBound($aButton_Menu_AVI_Sub2_Item) - 1
					If $d = $dd Then
						GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_CHECKED)
					Else
						GUICtrlSetState($aButton_Menu_AVI_Sub2_Item[$d], $GUI_UNCHECKED)
					EndIf
				Next
			EndIf
		Case $Button_Menu_GrabScreen_Item
			Recapture()
		Case $Button_Menu_Web_Item1
			If BitAND(GUICtrlRead($Button_Menu_Web_Item1), $GUI_CHECKED) = $GUI_CHECKED Then
				GUICtrlSetState($Button_Menu_Web_Item1, $GUI_UNCHECKED)
			Else
				GUICtrlSetState($Button_Menu_Web_Item1, $GUI_CHECKED)
			EndIf
		Case $Button_Menu_Web_Item2_Sub[0]
			$dd = 0
			For $d = 0 To UBound($Button_Menu_Web_Item2_Sub) - 1
				If $d = $dd Then
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_UNCHECKED)
				EndIf
			Next
		Case $Button_Menu_Web_Item2_Sub[1]
			$dd = 1
			For $d = 0 To UBound($Button_Menu_Web_Item2_Sub) - 1
				If $d = $dd Then
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_UNCHECKED)
				EndIf
			Next
		Case $Button_Menu_Web_Item2_Sub[2]
			$dd = 2
			For $d = 0 To UBound($Button_Menu_Web_Item2_Sub) - 1
				If $d = $dd Then
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_UNCHECKED)
				EndIf
			Next
		Case $Button_Menu_Web_Item2_Sub[3]
			$dd = 3
			For $d = 0 To UBound($Button_Menu_Web_Item2_Sub) - 1
				If $d = $dd Then
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_CHECKED)
				Else
					GUICtrlSetState($Button_Menu_Web_Item2_Sub[$d], $GUI_UNCHECKED)
				EndIf
			Next
		Case $aButton_Menu_Lang_Items[0]
			If $iLang <> 0 Then Change_Language(0)
		Case $aButton_Menu_Lang_Items[1]
			If $iLang <> 1 Then Change_Language(1)
		Case $aButton_Menu_Lang_Items[2]
			If $iLang <> 2 Then Change_Language(2)
		Case $aButton_Menu_Lang_Items[3]
			If $iLang <> 3 Then Change_Language(3)
		Case $aButton_Menu_Lang_Items[4]
			If $iLang <> 4 Then Change_Language(4)
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_COMMAND

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	Local $pos
	Switch $lParam
		Case $hSlider
			$pos = _GUICtrlSlider_GetPos($hSlider)
			GUICtrlSetData($Slider_Label_Value, $pos)
			Slider_Label_Color($pos)
	EndSwitch
EndFunc   ;==>WM_HSCROLL

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	Local $mi = GUIGetCursorInfo(HWnd($hGUI))
	If Not @error Then
		If $mi[4] = $Gfx Then
			_GUICtrlMenu_TrackPopupMenu($hQMenu, $hWnd)
			Return True
		EndIf
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_CONTEXTMENU

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	Local $idFrom
	$idFrom = BitAND($wParam, 0x0000FFFF)
	Switch $idFrom
		Case $id_Ruler
			Call_Ruler()
		Case $id_OpenMailClient
			HotKeySet("^!{F9}")
			OpenMailClient()
			HotKeySet("^!{F9}", "Grab_Screen")
		Case $id_Print
			HotKeySet("^!{F9}")
			PrintImage()
			HotKeySet("^!{F9}", "Grab_Screen")
		Case $id_ImportClipboard
			GrabPrintScreenClipboard()
		Case $id_ImageEditor
			Call_ImageEditor()
		Case $id_ChkUpd
			HotKeySet("^!{F9}")
			Check4Update()
			HotKeySet("^!{F9}", "Grab_Screen")
		Case $id_VisitWeb
			ShellExecute("https://www.autoitscript.com/forum/index.php?showtopic=122941")
		Case $id_About
			HotKeySet("^!{F9}")
			About()
			HotKeySet("^!{F9}", "Grab_Screen")
		Case $id_Donate
			Donate()
		Case $id_Exit
			_Exit()
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_SYSCOMMAND

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
	#forceref $hWnd, $MsgID, $wParam
	Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $index, $subitem, $hWindow, $aStyleEx
	$hWndListView = $hListView
	If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($List)
	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
	$iCode = DllStructGetData($tNMHDR, "Code")
	Switch $hWndFrom
		Case $hWndListView
			Switch $iCode
				Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
					$bRepaintXP = False
					GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
					$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
					$index = DllStructGetData($tInfo, "Index")
					If $index > -1 Then
						Capture_Window(HWnd(_GUICtrlListView_GetItemText($List, $index, 1)), $aWnd[$index][2], $aWnd[$index][3])
					EndIf
					$bRepaintXP = True
				Case $LVN_KEYDOWN
					$bRepaintXP = False
					GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
					$tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
					Switch DllStructGetData($tInfo, "VKey")
						Case 38
							$index = _GUICtrlListView_GetSelectionMark($List) - 1
							If $index > -1 Then
								Capture_Window(HWnd(_GUICtrlListView_GetItemText($List, $index, 1)), $aWnd[$index][2], $aWnd[$index][3])
							EndIf
						Case 40
							$index = _GUICtrlListView_GetSelectionMark($List) + 1
							If $index < _GUICtrlListView_GetItemCount($hListView) Then
								Capture_Window(HWnd(_GUICtrlListView_GetItemText($List, $index, 1)), $aWnd[$index][2], $aWnd[$index][3])
							EndIf
					EndSwitch
					$bRepaintXP = True
				Case $NM_RDBLCLK
					If @OSBuild < 6000 Or (Not $aero) Then Return 0
					GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
					$index = _GUICtrlListView_GetSelectionMark($List)
					If $index > -1 And $index < _GUICtrlListView_GetItemCount($List) And _GUICtrlListView_GetSelectedCount($List) > 0 Then
						Local $iState = _WinAPI_GetGUIMinMaxAnim()
						If $iState Then _WinAPI_SetGUIMinMaxAnim(0)
						$hWindow = HWnd(_GUICtrlListView_GetItemText($List, $index, 1))
						$aStyleEx = _WinAPI_GetWindowLong($hWindow, $GWL_EXSTYLE)
						_WinAPI_SetWindowLong($hWindow, $GWL_EXSTYLE, BitOR($aStyleEx, $WS_EX_LAYERED))
						_WinAPI_SetLayeredWindowAttributes($hWindow, 0x00, 0xFF, $LWA_ALPHA)
						Capture_Window2($hWindow)
						_WinAPI_SetWindowLong($hWindow, $GWL_EXSTYLE, $aStyleEx)
						If $iState Then _WinAPI_SetGUIMinMaxAnim(1)
					EndIf
				Case $LVN_COLUMNCLICK
					GUICtrlSetState($Button_Clipboard, $GUI_ENABLE)
					$tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
					$subitem = DllStructGetData($tInfo, "SubItem")
					_GUICtrlListView_SimpleSort($hWndFrom, $B_DESCENDING, $subitem)
					Switch $subitem
						Case 0
							_ArraySort($aWnd, Not $B_DESCENDING[0], 0, 0, $subitem)
						Case 1
							_ArraySort($aWnd, Not $B_DESCENDING[1], 0, 0, $subitem)
					EndSwitch
			EndSwitch
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_NOTIFY

Func WM_MOUSEWHEEL_GUI($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $lParam
	Local $wheel_Dir = _WinAPI_HiWord($wParam)
	Local $mi = GUIGetCursorInfo()
	If Not @error Then
		If $mi[4] <> $List Then
			If $wheel_Dir > 0 Then
				Zoom(1)
			Else
				Zoom(0)
			EndIf
		EndIf
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL_GUI

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $lParam
	Local $wheel_Dir = _WinAPI_HiWord($wParam)
	If $wheel_Dir > 0 Then
		If $zoom_level < $zoom_max Then
			$zoom_level += 1
		EndIf
	Else
		If $zoom_level > $zoom_min Then
			$zoom_level -= 1
		EndIf
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL

Func WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)
	#forceref $iMsg, $wParam, $lParam
	Switch $hWnd
		Case $hGUI_ImageEditor_Child
			Local $aMPos_IE = GUIGetCursorInfo($hGUI_ImageEditor_Child)
			If (Not @error) And ($aMPos_IE[4] = $idPic_ImageEditor) Then
				_WinAPI_SetCursor($hCursor_IE)
				Return 1
			EndIf
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_SETCURSOR

Func WM_MOUSEWHEEL_IE($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $lParam
	If $hWnd = $hGUI_ImageEditor_Child Then
		Local $wheel_Dir = _WinAPI_HiWord($wParam), $y, $steps_y = 8

		If _IsPressed("10", $dll) Or _IsPressed("02", $dll) Then
			If $wheel_Dir > 0 And $IE_ScrollbarH Then
				For $y = 1 To $steps_y
					_SendMessage($hGUI_ImageEditor_Child, $WM_HSCROLL, $SB_LINEUP)
				Next
			Else
				If $IE_ScrollbarH Then
					For $y = 1 To $steps_y
						_SendMessage($hGUI_ImageEditor_Child, $WM_HSCROLL, $SB_LINEDOWN)
					Next
				EndIf
			EndIf
		Else
			If $wheel_Dir > 0 And $IE_ScrollbarV Then

				For $y = 1 To $steps_y
					_SendMessage($hGUI_ImageEditor_Child, $WM_VSCROLL, $SB_LINEUP)
				Next
			Else
				If $IE_ScrollbarV Then
					For $y = 1 To $steps_y
						_SendMessage($hGUI_ImageEditor_Child, $WM_VSCROLL, $SB_LINEDOWN)
					Next
				EndIf
			EndIf
		EndIf
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL_IE

Func WM_NOTIFY_IE($hWnd, $MsgID, $wParam, $lParam)
	#forceref $hWnd, $MsgID, $wParam
	Local $tNMHDR, $event, $hWndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
	Local $tNMTOOLBAR, $tNMTBHOTITEM, $tNMTBCUSTOMDRAW, $tNMHDR, $iDrawStage, $iItemSpec, $hDC, $iItemState

	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
	$idFrom = DllStructGetData($tNMHDR, "IDFrom")
	$code = DllStructGetData($tNMHDR, "Code")

	Switch $hWndFrom
		Case $hToolbar_IE
			Switch $code
				Case $NM_CUSTOMDRAW
					$tNMTBCUSTOMDRAW = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
					$iDrawStage = DllStructGetData($tNMTBCUSTOMDRAW, "DrawStage")
					If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
					If $iDrawStage <> $CDDS_ITEMPREPAINT Then Return $CDRF_DODEFAULT

					$iItemSpec = DllStructGetData($tNMTBCUSTOMDRAW, "ItemSpec")
					$hDC = DllStructGetData($tNMTBCUSTOMDRAW, "HDC")
					$iItemState = DllStructGetData($tNMTBCUSTOMDRAW, "ItemState")

					Switch $iItemSpec
						Case $idColor_IE
							_WinAPI_SelectObject($hDC, $hFont_IE_Color)
							Local Const $tSize = _WinAPI_GetTextExtentPoint32($hDC, _GUICtrlToolbar_GetButtonText($hToolbar_IE, $idColor_IE))
							DllStructSetData($tNMTBCUSTOMDRAW, "rcText", DllStructGetData($tSize, "X"), 3) ;width
                            DllStructSetData($tNMTBCUSTOMDRAW, "rcText", DllStructGetData($tSize, "Y"), 4) ;height
							DllStructSetData($tNMTBCUSTOMDRAW, "clrText", BitOR(BitShift(BitAND($IE_Pen_Col, 0x000000FF), -16), BitAND($IE_Pen_Col, 0x0000FF00), BitShift(BitAND($IE_Pen_Col, 0x00FF0000), 16)))
							Return BitOR($CDRF_NEWFONT, $TBCDRF_USECDCOLORS)
					EndSwitch
				Case $NM_LDOWN
					Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar_IE, $IE_iItem)
						Case True
							If $bLocked_IE Then Return 0
							GUICtrlSendToDummy($TB_Button_Chk, $IE_iItem)
					EndSwitch
				Case $TBN_HOTITEMCHANGE
					$tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
					$i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
					$i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
					$IE_iItem = $i_idNew
					$dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
				Case $TBN_DROPDOWN
					Switch $IE_iItem
						Case $idIEPen_Size
							_GUICtrlMenu_TrackPopupMenu($hMenu_IE_PS, $hGUI_ImageEditor)
							Return 0
						Case $idFX_IE
							_GUICtrlMenu_TrackPopupMenu($hMenu_IE_FX, $hGUI_ImageEditor)
							Return 0
					EndSwitch

			EndSwitch
		Case $hSlider_IE_Blur
			$IE_tmp = _GUICtrlSlider_GetPos($hSlider_IE_Blur)
			Return 1
		Case $hSlider_IE_GS
			$IE_tmp = _GUICtrlSlider_GetPos($hSlider_IE_GS)
			Return 1
		Case $hSlider_IE_BW
			$IE_tmp = _GUICtrlSlider_GetPos($hSlider_IE_BW)
			Return 1
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_NOTIFY_IE

Func WM_COMMAND_IE($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $ilParam
	Local $ii
	Switch BitAND($iwParam, 0x0000FFFF)
		Case $idInput_IE_W
			$ii = GUICtrlRead($idInput_IE_W)
			Switch BitAND(GUICtrlRead($idChkBox_IE_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_IE_W, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_IE_W, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_IE_W) * $bH / $bW, 0)
					GUICtrlSetData($idInput_IE_H, $ii)
			EndSwitch
			GUICtrlSetData($idInput_IE_WP, Round(GUICtrlRead($idInput_IE_W) / $bW * 100))
			GUICtrlSetData($idInput_IE_HP, Round(GUICtrlRead($idInput_IE_H) / $bH * 100))
			GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & " Pixel")
		Case $idInput_IE_H
			$ii = GUICtrlRead($idInput_IE_H)
			Switch BitAND(GUICtrlRead($idChkBox_IE_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_IE_H, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_IE_H, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_IE_H) * $bW / $bH, 0)
					GUICtrlSetData($idInput_IE_W, $ii)
			EndSwitch
			GUICtrlSetData($idInput_IE_WP, Round(GUICtrlRead($idInput_IE_W) / $bW * 100))
			GUICtrlSetData($idInput_IE_HP, Round(GUICtrlRead($idInput_IE_H) / $bH * 100))
			GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & " Pixel")
		Case $idInput_IE_WP
			$ii = Round(GUICtrlRead($idInput_IE_WP) / 100 * $bW, 0)
			Switch BitAND(GUICtrlRead($idChkBox_IE_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_IE_W, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_IE_W, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_IE_W) * $bH / $bW, 0)
					GUICtrlSetData($idInput_IE_H, $ii)
			EndSwitch
			GUICtrlSetData($idInput_IE_HP, Round(GUICtrlRead($idInput_IE_H) / $bH * 100))
			GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & " Pixel")
		Case $idInput_IE_HP
			$ii = Round(GUICtrlRead($idInput_IE_HP) / 100 * $bH, 0)
			Switch BitAND(GUICtrlRead($idChkBox_IE_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_IE_H, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_IE_H, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_IE_H) * $bW / $bH, 0)
					GUICtrlSetData($idInput_IE_W, $ii)
			EndSwitch
			GUICtrlSetData($idInput_IE_WP, Round(GUICtrlRead($idInput_IE_W) / $bW * 100))
			GUICtrlSetData($idLabel_IE_SizeN, GUICtrlRead($idInput_IE_W) & " x " & GUICtrlRead($idInput_IE_H) & " Pixel")
	EndSwitch
	Switch $iwParam
		Case $idFX_IE_GS
			Local $GS_val = 128, $aCI, $gs_go = True
			If $gs_go Then
				_GDIPlus_BitmapDispose($IE_Bmp_Undo)
				$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
				If Not $IE_Bmp_Undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
						$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
				_GDIPlus_BitmapCreateGrayscale($hBmp, True)
				CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
				WinActivate($hGUI_ImageEditor_Child)
				_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
				$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
				_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
				_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
			EndIf
		Case $idFX_IE_BW
			GUICtrlSendToDummy($IE_Dummy_BW)
			Return 1
		Case $idFX_IE_INV
			_GDIPlus_BitmapDispose($IE_Bmp_Undo)
			$IE_Bmp_Undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
			If Not $IE_Bmp_Undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
					$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
			_GDIPlus_BitmapCreateNegative($hBmp, True)
			CopyImage2Control($idPic_ImageEditor, $iGUI_IE_BGColor)
			WinActivate($hGUI_ImageEditor_Child)
			_GDIPlus_GraphicsDispose($hCtx_IE_BMP)
			$hCtx_IE_BMP = _GDIPlus_ImageGetGraphicsContext($hBmp)
			_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_IE_BMP, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
			_GDIPlus_GraphicsSetSmoothingMode($hCtx_IE_BMP, 2)
			Return 1
		Case $idFX_IE_BLUR
			GUICtrlSendToDummy($IE_Dummy_Blur)
			Return 1
		Case $idFX_IE_Pix
			GUICtrlSendToDummy($IE_Dummy_Pix)
			Return 1
		Case $idFX_IE_Rast
			GUICtrlSendToDummy($IE_Dummy_Ras)
			Return 1
		Case $idFX_IE_Resize
			GUICtrlSendToDummy($IE_Dummy_Res)
			Return 1
		Case $idFX_IE_Crop
			GUICtrlSendToDummy($IE_Dummy_Crop)
			Return 1
		Case $idIEPen_Size_1px
			_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 0)
			_GDIPlus_PenSetWidth($hPen_IE, 1)
			_GDIPlus_PenSetWidth($hPenArrow_IE, 1)
			_GDIPlus_PenSetWidth($hPenArrowShadow_IE, 1)
			$IE_PenSize = 1
		Case $idIEPen_Size_2px
			_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 1)
			_GDIPlus_PenSetWidth($hPen_IE, 2)
			_GDIPlus_PenSetWidth($hPenArrow_IE, 2)
			_GDIPlus_PenSetWidth($hPenArrowShadow_IE, 2)
			$IE_PenSize = 2
		Case $idIEPen_Size_4px
			_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 2)
			_GDIPlus_PenSetWidth($hPen_IE, 4)
			_GDIPlus_PenSetWidth($hPenArrow_IE, 4)
			_GDIPlus_PenSetWidth($hPenArrowShadow_IE, 4)
			$IE_PenSize = 4
		Case $idIEPen_Size_8px
			_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 3)
			_GDIPlus_PenSetWidth($hPen_IE, 8)
			_GDIPlus_PenSetWidth($hPenArrow_IE, 8)
			_GDIPlus_PenSetWidth($hPenArrowShadow_IE, 8)
			$IE_PenSize = 8
		Case $idIEPen_Size_16px
			_GUICtrlMenu_CheckRadioItem($hMenu_IE_PS, 0, 5, 4)
			_GDIPlus_PenSetWidth($hPen_IE, 16)
			_GDIPlus_PenSetWidth($hPenArrow_IE, 16)
			_GDIPlus_PenSetWidth($hPenArrowShadow_IE, 16)
			$IE_PenSize = 16
	EndSwitch

	If _GUICtrlToolbar_IsButtonChecked($hToolbar_IE, $idPen_IE) Or _GUICtrlToolbar_IsButtonChecked($hToolbar_IE, $idRectangle_IE) Or _GUICtrlToolbar_IsButtonChecked($hToolbar_IE, $idEllipse_IE) Or _GUICtrlToolbar_IsButtonChecked($hToolbar_IE, $idArrow_IE) Then
		_WinAPI_DestroyCursor($hCursor_IE)
		$hCursor_IE = _WinAPI_CreateSolidCursorFromBitmap($IE_PenSize, $IE_PenSize, BitOR(BitShift(BitAND($IE_Pen_Col, 0x000000FF), -16), BitAND($IE_Pen_Col, 0x0000FF00), BitShift(BitAND($IE_Pen_Col, 0x00FF0000), 16)))
		Local $aCI = GUIGetCursorInfo($hGUI_ImageEditor_Child)
		If (Not @error) And $aCI[4] = $idPic_ImageEditor Then _WinAPI_SetCursor($hCursor_IE)
	EndIf
	_GUICtrlToolbar_CheckButton($hToolbar_IE, $idIEPen_Size, False)
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_COMMAND_IE

Func WM_HSCROLL_IE($hWnd, $Msg, $wParam, $lParam)
	#forceref $Msg, $lParam
	Local $Min, $Max, $Page, $TrackPos

	; Get all the horizontal scroll bar information
	Local $tSCROLLINFO_X = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
	$Min = DllStructGetData($tSCROLLINFO_X, "nMin")
	$Max = DllStructGetData($tSCROLLINFO_X, "nMax")
	$Page = DllStructGetData($tSCROLLINFO_X, "nPage")

	; Save the position for comparison later on
	$IE_offset_x = DllStructGetData($tSCROLLINFO_X, "nPos")
	$TrackPos = DllStructGetData($tSCROLLINFO_X, "nTrackPos")
	#forceref $Min, $Max
	Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
	Switch $nScrollCode

		Case $SB_LINELEFT ; user clicked left arrow
			DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x - 1)

		Case $SB_LINERIGHT ; user clicked right arrow
			DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x + 1)

		Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
			DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x - $Page)

		Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box
			DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x + $Page)

		Case $SB_THUMBTRACK ; user dragged the scroll box
			DllStructSetData($tSCROLLINFO_X, "nPos", $TrackPos)
	EndSwitch

	DllStructSetData($tSCROLLINFO_X, "fMask", $SIF_POS)
	_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO_X)

	$IE_offset_x = DllStructGetData($tSCROLLINFO_X, "nPos")

	ControlMove("", "", $idPic_ImageEditor, -$IE_offset_x, -$IE_offset_y)

	If $bCropWinActive Then
		$bCropWinActive = False
		$bMove_Crop = False
		WinMove($hGUI_IE_Crop, "", -1 * $IE_offset_x + $iPosX_Crop + $iDeltaX_Crop - 7, -1 * ($IE_ScrollbarV ? $IE_offset_y : 0) + $iPosY_Crop + $iDeltaY_Crop - 7)
		$bMove_Crop = True
		$bCropWinActive = True
	EndIf

	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_HSCROLL_IE

Func WM_VSCROLL_IE($hWnd, $Msg, $wParam, $lParam)
	#forceref $Msg, $lParam
	Local $Min, $Max, $Page, $TrackPos

;~  ; Get all the horizontal scroll bar information
	Local $tSCROLLINFO_Y = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
	$Min = DllStructGetData($tSCROLLINFO_Y, "nMin")
	$Max = DllStructGetData($tSCROLLINFO_Y, "nMax")
	$Page = DllStructGetData($tSCROLLINFO_Y, "nPage")
	; Save the position for comparison later on
	$IE_offset_y = DllStructGetData($tSCROLLINFO_Y, "nPos")
	$TrackPos = DllStructGetData($tSCROLLINFO_Y, "nTrackPos")
	#forceref $Min, $Max
	Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
	Switch $nScrollCode
		Case $SB_LINELEFT ; user clicked left arrow
			DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y - 1)

		Case $SB_LINERIGHT ; user clicked right arrow
			DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y + 1)

		Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
			DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y - $Page)

		Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box
			DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y + $Page)

		Case $SB_THUMBTRACK ; user dragged the scroll box
			DllStructSetData($tSCROLLINFO_Y, "nPos", $TrackPos)
	EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

	DllStructSetData($tSCROLLINFO_Y, "fMask", $SIF_POS)
	_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO_Y)

	$IE_offset_y = DllStructGetData($tSCROLLINFO_Y, "nPos")

	ControlMove("", "", $idPic_ImageEditor, -$IE_offset_x, -$IE_offset_y)

	If $bCropWinActive Then
		$bCropWinActive = False
		$bMove_Crop = False
		WinMove($hGUI_IE_Crop, "", -1 * ($IE_ScrollbarH ? $IE_offset_x : 0) + $iPosX_Crop + $iDeltaX_Crop - 7, -1 * $IE_offset_y + $iPosY_Crop + $iDeltaY_Crop - 7)
		$bMove_Crop = True
		$bCropWinActive = True
	EndIf

	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_VSCROLL_IE

Func WM_GETMINMAXINFO_Crop($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam
	Local $aPos = ControlGetPos($hGUI_ImageEditor_Child, "", $idPic_ImageEditor)
	Local $tGETMINMAXINFO = DllStructCreate("int;int;" & _ ;1-2 Reserved
											"int msw;int msh;" & _ ;3-4 MaxSize
											"int mpw;int mxh;" & _ ;5-6 MaxPosition
											"int mintw;int minth;" & _ ;7-8 MinTrackSize
											"int maxtw;int maxth", $lParam) ;9-10 MaxTrackSize
	$tGETMINMAXINFO.maxtw = $aPos[2]
	$tGETMINMAXINFO.maxtH = $aPos[3]
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_GETMINMAXINFO_Crop

Func WM_WINDOWPOSCHANGING_Crop($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    If $hWnd = $hGUI_IE_Crop Then
		Local $tWinPos = DllStructCreate("hwnd hwndInsertAfter;hwnd hwnd;int x;int y;int cx;int cy; uint flags", $lParam)
		Local Const $aCtrlPos = ControlGetPos($hGUI_ImageEditor_Child, "", $idPic_ImageEditor)
		If $tWinPos.x < $aCtrlPos[0] Then $tWinPos.x = $aCtrlPos[0]
		If $tWinPos.y < $aCtrlPos[1] Then $tWinPos.y = $aCtrlPos[1]
		If $tWinPos.x + $tWinPos.cx > $aCtrlPos[0] + $aCtrlPos[2] Then $tWinPos.x = $aCtrlPos[0] + $aCtrlPos[2] - $tWinPos.cx
		If $tWinPos.y + $tWinPos.cy > $aCtrlPos[1] + $aCtrlPos[3] Then $tWinPos.y = $aCtrlPos[1] + $aCtrlPos[3] - $tWinPos.cy
		Local Static $iOldcx = -10000, $iOldcy = -10000
		If $iOldcx <> $tWinPos.cx Or $iOldcy <> $tWinPos.cy Then
			GUICtrlSetData($iLable_CropMove, $aTranslations[279][$iLang] & @CRLF & $tWinPos.cx & "x" & $tWinPos.cy)
			$iOldcx = $tWinPos.cx
			$iOldcy = $tWinPos.cy
		EndIf
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_WINDOWPOSCHANGING_Crop

Func WM_MOVE_IE_GUI_Crop($hWnd, $iMsg, $wParam, $lParam)
	#forceref $iMsg, $wParam
	If $hWnd = $hGUI_IE_Crop And $bMove_Crop Then
		$iPosX_Crop = _WinAPI_LoWord($lParam)
		$iPosY_Crop = _WinAPI_HiWord($lParam)
		$iDeltaX_Crop = ($IE_offset_X > 0 ? $IE_offset_X : 0)
		$iDeltaY_Crop = ($IE_offset_Y > 0 ? $IE_offset_Y : 0)
	EndIf
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOVE_IE_GUI_Crop

Func WM_VSCROLL_WM($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam
	Switch $lParam
		Case $hSliderDegree_WM
			Local $iDegree = GUICtrlRead($idSliderDegree_WM)
			Local Static $iPrevDegree = -1
			If $iPrevDegree <> $iDegree Then
				GUICtrlSetData($idInputDegree_WM, $iDegree)
;~ 				UpdatePreview_WM()
				$bUpdate_WM = True
				$iPrevDegree = $iRotation_WM
			EndIf
		Case $hSliderAdjY_WM
			$iAdjY_WM = GUICtrlRead($idSliderAdjY_WM)
			$bUpdate_WM = True
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_VSCROLL_WM

Func WM_HSCROLL_WM($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg
	Switch $lParam
		Case $hSliderOpaque_WM
			Local Static $iPrevOpaque = -1
			Local $iOpaque = GUICtrlRead($idSliderOpaque_WM)
			If $iPrevOpaque <> $iOpaque Then
				GUICtrlSetData($idInputOpaque_WM, $iOpaque)
				ToolTip(Round(100 * GUICtrlRead($idSliderOpaque_WM) / 0xFF, 0) & " %")
				$bUpdate_WM = True
				$iPrevOpaque = $iOpaque
			EndIf
		Case $hSliderRadius_WM
			Local Static $iPrevRad = -1
			Local $iRad = GUICtrlRead($idSliderRadius_WM)
			If $iPrevRad <> $iRad Then
				GUICtrlSetData($idInputRadius_WM, $iRad)
				$bUpdate_WM = True
				$iPrevRad = $iRad
			EndIf
		Case $hSliderAdjX_WM
			$iAdjX_WM = GUICtrlRead($idSliderAdjX_WM)
			$bUpdate_WM = True
		Case Else
	EndSwitch
	Switch BitAND($wParam, 0xFF)
		Case 5 ;$SB_THUMBTRACK = 5
		Case Else
			ToolTip("")
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_HSCROLL_WM

Func WM_PAINT_WM($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $wParam, $lParam
	DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC_WM, "int", 0, "int", 0, "int", $bW, "int", $bH, "handle", $hDC_backbuffer_WM, "int", 0, "int", 0, "dword", $SRCCOPY)
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_PAINT_WM

Func WM_REDRAW_WM($hWnd, $Msg, $wParam, $lParam)
	Switch $Msg
		Case $WM_NCPAINT
			CopyImageGfx($hBmp_Preview_WM)
			Return "GUI_RUNDEFMSG"
		Case $WM_PAINT
			CopyImageGfx($hBmp_Preview_WM)
			Return "GUI_RUNDEFMSG"
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_REDRAW_WM

Func WM_COMMAND_WM($hWnd, $Msg, $wParam, $lParam)
	#forceref $hWnd, $Msg, $lParam
	Local $ii
	Switch BitAND($wParam, 0x0000FFFF)
		Case $idInput_WM_W
			$ii = GUICtrlRead($idInput_WM_W)
			Switch BitAND(GUICtrlRead($idChkBox_WM_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_WM_W, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_WM_W, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_WM_W) * $bH / $bW, 0)
					GUICtrlSetData($idInput_WM_H, $ii)
			EndSwitch
			GUICtrlSetData($idInput_WM_WP, Round(GUICtrlRead($idInput_WM_W) / $bW * 100))
			GUICtrlSetData($idInput_WM_HP, Round(GUICtrlRead($idInput_WM_H) / $bH * 100))
			GUICtrlSetData($idLabel_WM_SizeN, GUICtrlRead($idInput_WM_W) & " x " & GUICtrlRead($idInput_WM_H) & " Pixel")
		Case $idInput_WM_H
			$ii = GUICtrlRead($idInput_WM_H)
			Switch BitAND(GUICtrlRead($idChkBox_WM_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_WM_H, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_WM_H, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_WM_H) * $bW / $bH, 0)
					GUICtrlSetData($idInput_WM_W, $ii)
			EndSwitch
			GUICtrlSetData($idInput_WM_WP, Round(GUICtrlRead($idInput_WM_W) / $bW * 100))
			GUICtrlSetData($idInput_WM_HP, Round(GUICtrlRead($idInput_WM_H) / $bH * 100))
			GUICtrlSetData($idLabel_WM_SizeN, GUICtrlRead($idInput_WM_W) & " x " & GUICtrlRead($idInput_WM_H) & " Pixel")
		Case $idInput_WM_WP
			$ii = Round(GUICtrlRead($idInput_WM_WP) / 100 * $bW, 0)
			Switch BitAND(GUICtrlRead($idChkBox_WM_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_WM_W, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_WM_W, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_WM_W) * $bH / $bW, 0)
					GUICtrlSetData($idInput_WM_H, $ii)
			EndSwitch
			GUICtrlSetData($idInput_WM_HP, Round(GUICtrlRead($idInput_WM_H) / $bH * 100))
			GUICtrlSetData($idLabel_WM_SizeN, GUICtrlRead($idInput_WM_W) & " x " & GUICtrlRead($idInput_WM_H) & " Pixel")
		Case $idInput_WM_HP
			$ii = Round(GUICtrlRead($idInput_WM_HP) / 100 * $bH, 0)
			Switch BitAND(GUICtrlRead($idChkBox_WM_AR), $GUI_CHECKED)
				Case 0
					GUICtrlSetData($idInput_WM_H, Max(1, Min($ii, 16384)))
				Case 1
					GUICtrlSetData($idInput_WM_H, Max(1, Min($ii, 16384)))
					$ii = Round(GUICtrlRead($idInput_WM_H) * $bW / $bH, 0)
					GUICtrlSetData($idInput_WM_W, $ii)
			EndSwitch
			GUICtrlSetData($idInput_WM_WP, Round(GUICtrlRead($idInput_WM_W) / $bW * 100))
			GUICtrlSetData($idLabel_WM_SizeN, GUICtrlRead($idInput_WM_W) & " x " & GUICtrlRead($idInput_WM_H) & " Pixel")
		Case Else
			$bUpdate_WM = True
	EndSwitch
	Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_COMMAND_WM
#EndRegion Windows Message Codes

#Region Ruler
Func Ruler()
	$selected = True
	GUISetState(@SW_HIDE, $hGUI)
	Local Static $hGUI_Ruler_BG
	If Not $hGUI_Ruler_BG Then
		$hGUI_Ruler_BG = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], $WS_POPUP, $WS_EX_TOOLWINDOW, $hGUI)
		WinSetTrans($hGUI_Ruler_BG, "", 0x01)
		GUISetState(@SW_SHOW, $hGUI_Ruler_BG)
	EndIf
	Local $zl = $zoom_level, $v, $esc = True
	$hGUI_Zoom = GUICreate("", $zw, $zh, $zx, $zx, BitOR($WS_POPUP, $DS_MODALFRAME), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE, $WS_EX_TOOLWINDOW), $hGUI_Ruler_BG) ;WinGetHandle(AutoItWinGetTitle()))
	GUISetState(@SW_SHOW, $hGUI_Zoom)
	$hDC_Zoom = _WinAPI_GetDC(0)
	$hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Zoom)
	$zx = @DesktopWidth - $zw - 4
	$zy = 0

	WinMove($hGUI_Zoom, "", $zx, $zy)
	Local $mpos, $cmpos, $aMPosOld[2], $aDPI_x, $aDPI_y, $iBGc = 0x123456
	Local $hGUI_Ruler = GUICreate($aTranslations[36][$iLang], 1, 1, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), $hGUI_Ruler_BG);, WinGetHandle(AutoItWinGetTitle()))
	GUISetBkColor($iBGc, $hGUI_Ruler)
	_WinAPI_SetLayeredWindowAttributes($hGUI_Ruler, $iBGc, 0xFF)
	WinMove($hGUI_Ruler, "", $aFullScreen[0], $aFullScreen[1], $aFullScreen[2], $aFullScreen[3])
	GUISetState(@SW_SHOW, $hGUI_Ruler)
	GUISetCursor(14, 1, $hGUI_Ruler)
	GUISetCursor(14, 1, $hGUI_Ruler_BG)
	WinSetOnTop($hGUI_Zoom, "", 1)
	Local $hGraphic_Ruler = _GDIPlus_GraphicsCreateFromHWND($hGUI_Ruler)
	_GDIPlus_GraphicsSetSmoothingMode($hGraphic_Ruler, 0)
	_GDIPlus_GraphicsSetPixelOffsetMode($hGraphic_Ruler, 4)
	_GDIPlus_GraphicsClear($hGraphic_Ruler, 0xFF000000 + $iBGc)
	Local $hBrush_Ruler = _GDIPlus_LineBrushCreate(0, 0, 0x08, 1, 0xFFFFFFFF, 0xFFFF0000, 3)
	Local $hPen_Ruler = _GDIPlus_PenCreate2($hBrush_Ruler, 1.66666)
	Local $hPen_Ruler_Clear = _GDIPlus_PenCreate(0xFF000000 + $iBGc, 10)
	$aDPI_x = DllCall($__g_hGDIPDll, "uint", "GdipGetDpiX", "handle", $hGraphic_Ruler, "float*", 0)
	$aDPI_y = DllCall($__g_hGDIPDll, "uint", "GdipGetDpiY", "handle", $hGraphic_Ruler, "float*", 0)

	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")
	Local Const $fDeg = 180 / ACos(-1)
	Local $dy = 80, $iPosX, $iPosY, $fDist, $fAngle, $mwx, $mwy, $iPrevX, $iPrevY, $iPrevW, $iPrevH
	$up = -1
	While Not _IsPressed("1B", $dll) * Sleep(10)
		$red = Hex(Int(0xFF * (Cos($v * 1.10) + 1) / 2), 2)
		$green = Hex(Int(0xFF * (Sin($v * 1.00) + 1) / 2), 2)
		$blue = Hex(Int(0xFF * (Sin($v * 1.20) + 1) / 2), 2)
		Draw_Zoom_Preview(MouseGetPos(0), MouseGetPos(1), 0.5)
		$iPosX = MouseGetPos(0)
		$iPosY = MouseGetPos(1)

		If $aMPosOld[0] <> $iPosX Or $aMPosOld[1] <> $iPosY Then
			ToolTip($aTranslations[239][$iLang] & @LF & _
					$aTranslations[242][$iLang] & $iPosX & $aTranslations[243][$iLang] & $iPosY, $iPosX + 10, $iPosY + $dy, "", 0, 4)
			$aMPosOld[0] = $iPosX
			$aMPosOld[1] = $iPosY
		EndIf
		If $iPosY > ($aFullScreen[3] - 100) Then $dy = -100
		If $iPosY < ($aFullScreen[1] + 80) Then $dy = 80

		If _IsPressed("01", $dll) Then
			ToolTip("")
			Sleep(150)
			$mpos = MouseGetPos()
			$dy = 80
			Do
				$iPosX = MouseGetPos(0)
				$iPosY = MouseGetPos(1)
				$fDist = Pixel_Distance($mpos[0], $mpos[1], $iPosX, $iPosY)
				$mwx = $iPosX - $mpos[0]
				$mwy = $mpos[1] - $iPosY
				$fAngle = Mod(-ATan($mwy / $mwx) * $fDeg + 90, 360)
				If $mwx < 0 Then $fAngle += 180
				If $iPosY > ($aFullScreen[3] - 110) Then $dy = -110
				If $iPosY < ($aFullScreen[1] + 90) Then $dy = 90
				Draw_Zoom_Preview($iPosX, $iPosY, 0.5)
				$red = Hex(Int(0xFF * (Cos($v * 1.10) + 1) / 2), 2)
				$green = Hex(Int(0xFF * (Sin($v * 1.00) + 1) / 2), 2)
				$blue = Hex(Int(0xFF * (Sin($v * 1.20) + 1) / 2), 2)
				$v += $fade_speed
				$cmpos = MouseGetPos()
				If $aMPosOld[0] <> $iPosX Or $aMPosOld[1] <> $iPosY Then
					ToolTip($aTranslations[245][$iLang] & @LF & _
						$aTranslations[240][$iLang] & $mpos[0] & $aTranslations[241][$iLang] & $mpos[1] & @LF & _
						$aTranslations[242][$iLang] & $iPosX & $aTranslations[243][$iLang] & $iPosY & @LF & _
						$aTranslations[266][$iLang] & StringFormat("%.2f °", $fAngle) & @LF & _
						$aTranslations[244][$iLang] & 1 + Round($fDist, 0) & $aTranslations[78][$iLang], $iPosX + 10, $iPosY + $dy, "", 0, 4)
;~ 					_GDIPlus_GraphicsClear($hGraphic_Ruler, 0xFF000000 + $iBGc)
					_GDIPlus_GraphicsDrawLine($hGraphic_Ruler, $iPrevX, $iPrevY, $iPrevW, $iPrevH, $hPen_Ruler_Clear)
					_GDIPlus_GraphicsDrawLine($hGraphic_Ruler, $mpos[0] + Abs($aFullScreen[0]), $mpos[1] + Abs($aFullScreen[1]), $iPosX + Abs($aFullScreen[0]), $iPosY + Abs($aFullScreen[1]), $hPen_Ruler)
					_GDIPlus_GraphicsFillEllipse($hGraphic_Ruler, -3 + $mpos[0] + Abs($aFullScreen[0]), -3 + $mpos[1] + Abs($aFullScreen[1]), 6, 6, $hBrush_Ruler)
					$iPrevX = $mpos[0] + Abs($aFullScreen[0])
					$iPrevY = $mpos[1] + Abs($aFullScreen[1])
					$iPrevW = $iPosX + Abs($aFullScreen[0])
					$iPrevH = $iPosY + Abs($aFullScreen[1])
					$aMPosOld[0] = $iPosX
					$aMPosOld[1] = $iPosY
				EndIf
;~ 				Sleep(20)
			Until _IsPressed("01", $dll)
			_GDIPlus_GraphicsFillEllipse($hGraphic_Ruler, -3 + $iPosX + Abs($aFullScreen[0]), -3 + $iPosY + Abs($aFullScreen[1]), 6, 6, $hBrush_Ruler)
			$esc = False
			ExitLoop
		EndIf
		$v += $fade_speed
	WEnd
	ToolTip("")
	_GDIPlus_PenDispose($hPen_Ruler)
	_GDIPlus_PenDispose($hPen_Ruler_Clear)
	_GDIPlus_BrushDispose($hBrush_Ruler)
	_GDIPlus_GraphicsDispose($hGraphic_Ruler)
	_WinAPI_ReleaseDC($hGUI_Zoom, $hGUI_ZoomDC)
	_WinAPI_ReleaseDC(0, $hDC_Zoom)
	GUIDelete($hGUI_Zoom)
	If Not $esc And IsArray($mpos) Then
		WinSetOnTop($hGUI_Ruler, "", 0)
		Local $dist = Pixel_Distance($mpos[0] - 1, $mpos[1] - 1, $cmpos[0], $cmpos[1])
		Local $iChoice = MsgBox(BitOr($MB_YESNO, $MB_ICONQUESTION, $MB_DEFBUTTON2, $MB_TOPMOST), $aTranslations[246][$iLang], _
				$aTranslations[247][$iLang] & $mpos[0] & @LF & _
				$aTranslations[248][$iLang] & $mpos[1] & @LF & _
				$aTranslations[249][$iLang] & $cmpos[0] & @LF & _
				$aTranslations[250][$iLang] & $cmpos[1] & @LF & _
				$aTranslations[266][$iLang] & StringFormat("%.2f °", $fAngle) & @LF & _
				$aTranslations[251][$iLang] & $aDPI_x[2] & @LF & _
				$aTranslations[252][$iLang] & $aDPI_y[2] & @LF & @LF & _
				$aTranslations[244][$iLang] & @LF & _
				@TAB & Round($dist, 0) & $aTranslations[78][$iLang] & @LF & _
				@TAB & StringFormat("%05.2f", $dist * 2.54 / $aDPI_x[2]) & $aTranslations[253][$iLang] & @LF & _
				@TAB & StringFormat("%05.2f", $dist / $aDPI_x[2]) & $aTranslations[254][$iLang] & @LF & @LF & @LF & _
				$aTranslations[255][$iLang], 60, $hGUI_Ruler_BG)
		If $iChoice = 6 Then
			GUIDelete($hGUI_Ruler)
			GUIDelete($hGUI_Zoom)
			Ruler()
		EndIf
	EndIf
	GUIDelete($hGUI_Ruler)
	GUIDelete($hGUI_Ruler_BG)
	GUIRegisterMsg($WM_MOUSEWHEEL, "")
	$zoom_level = $zl
	GUISetState(@SW_SHOW, $hGUI)
	$hGUI_Ruler_BG = 0
EndFunc   ;==>Ruler
#EndRegion Ruler

#Region Send mail
Func OpenMailClient()
	$silent = True
	If BitAND(GUICtrlGetState($Button_Clipboard), $GUI_ENABLE) = $GUI_ENABLE Then
		Local $iPrev = $bClipboard_PNG
		$bClipboard_PNG = False
		If Not Pic2Clipboard() Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[256][$iLang], 30, $hGUI)
		$bClipboard_PNG = $iPrev
	EndIf
	$silent = False
	_INetMail("", "Windows Screenshooter", $aTranslations[257][$iLang])
	If @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[258][$iLang], 30, $hGUI)
EndFunc   ;==>OpenMailClient
#EndRegion Send mail

#Region About Intro
Func About()
	GUIRegisterMsg($WM_NOTIFY, "")
	GUIRegisterMsg($WM_SYSCOMMAND, "")
	GUIRegisterMsg($WM_CONTEXTMENU, "")
	GUIRegisterMsg($WM_MOUSEWHEEL, "")
	GUISetStyle(Default, $WS_EX_TOPMOST, $hGUI)

	AutoItSetOption("GUICloseOnESC", 1)
	GUISetOnEvent($GUI_EVENT_CLOSE, "")
	Local $i, $z

	For $i = 6 To 18
		_GUICtrlMenu_SetItemDisabled($hMenu, $i)
	Next

	#Region binary string read
	Local $_XM_Tune = ChipMuzik(), $hMusic
	Load_XM($_XM_Tune, $hMusic)
	Vol_XM($hMusic, 66)
	Play_XM($hMusic) ; let's hear it

	#EndRegion binary string read

	Local $fade, $size = 0
	If @OSBuild < 6000 Or Not $aero Then
		$fade = 1
		$size = 3
	Else
		$fade = 0.075
	EndIf

	$hGUI_About = GUICreate("", $width - $size, $height - $size, 0, 0, BitOR($WS_POPUP, $WS_CHILD, $WS_CLIPSIBLINGS), BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)
	WinSetTrans($hGUI_About, "", 0x00)
	GUISetState(@SW_SHOW, $hGUI_About)

	#Region GDI+ Init
	$hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI_About)
	$hBMP_About = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGfx)
	$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBMP_About)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
	DllCall($__g_hGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt, "int", 4) ;http://msdn.microsoft.com/en-us/library/ms535817(v=vs.85).aspx

	Local $aGUIPos = WinGetPos(HWnd($hGUI))
	Sleep(333)
	$hHBITMAP = _ScreenCapture_CaptureWnd("", HWnd($hGUI), ($aGUIPos[2] - $width) / 2 + 1, $iFrameH + 1, ($aGUIPos[2] - $width) / 2 + $width + 1, $iFrameH + $height + 1, False)
	$hBmp_A = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
	_WinAPI_DeleteObject($hHBITMAP)
	$hImg_A = _Blur($hBmp_A, $width, $height)
	_GDIPlus_GraphicsDrawImageRect($hGfx, $hImg_A, 0, 0, $width, $height)
	#EndRegion GDI+ Init

	#Region Dancing Animation
	Local $iFrameDimCount_Anim, $aRes_Anim
	$hImage_Anim = _GDIPlus_BitmapCreateFromMemory(GIF_Anim())
	$iW_Anim = _GDIPlus_ImageGetWidth($hImage_Anim)
	$iH_Anim = _GDIPlus_ImageGetHeight($hImage_Anim)
	$aRes_Anim = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "handle", $hImage_Anim, "ptr*", 0)
	$iFrameDimCount_Anim = $aRes_Anim[2]
	DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsList", "handle", $hImage_Anim, "ptr", $pGUID, "int", $iFrameDimCount_Anim)
	$aRes_Anim = DllCall($__g_hGDIPDll, "uint", "GdipImageGetFrameCount", "handle", $hImage_Anim, "ptr", $pGUID, "ptr*", 0)
	$iFrameCount_Anim = $aRes_Anim[3]
	#EndRegion Dancing Animation

	For $i = 0 To $bubbles - 1
		$aData[$i][0] = Random(0, $width - $max_size, 1)
		$aData[$i][1] = Random(0, $height - $max_size, 1)
		$aData[$i][2] = _Random(-$max_speed, $max_speed, -1.5, 1.5) ;vx
		$aData[$i][3] = _Random(-$max_speed, $max_speed, -1.5, 1.5) ;vy
		$aData[$i][4] = Random($min_size, $max_size, 1) ;size
		$aData[$i][5] = _CreateBubbleBitmap($aData[$i][4], 0x98F0E0E0, "0xC0" & Hex(Random(0xA0, 0xE8, 1), 2) & Hex(Random(0xA0, 0xE8, 1), 2) & Hex(Random(0xA0, 0xF0, 1), 2)) ;handle to bitmap
	Next

	#Region fade-in GUI
;~ 	Local Const $snd_vol = 0.75
;~ 	Local Const $zz = 100 / 0xFF
	For $z = 0 To 0xFF - $fade Step $fade
		WinSetTrans($hGUI_About, "", $z)
;~ 		Vol_XM($hMusic, ($z * $zz) * $snd_vol)
	Next
	#EndRegion fade-in GUI

	#Region Init Scroller
	Local $bFont1 = Ethnocentric_Font()
	Local $bFont2 = _UEZ_Logo_Font()
	Local $tFont_Mem1 = DllStructCreate("byte[" & BinaryLen($bFont1) & "]") ;Ethnocentric
	Local $tFont_Mem2 = DllStructCreate("byte[" & BinaryLen($bFont2) & "]") ;Vtks Revolt
	DllStructSetData($tFont_Mem1, 1, $bFont1)
	DllStructSetData($tFont_Mem2, 1, $bFont2)
	Local $hCollection = _GDIPlus_NewPrivateFontCollection()
	_GDIPlus_PrivateAddMemoryFont($hCollection, DllStructGetPtr($tFont_Mem1), DllStructGetSize($tFont_Mem1))
	_GDIPlus_PrivateAddMemoryFont($hCollection, DllStructGetPtr($tFont_Mem2), DllStructGetSize($tFont_Mem2))

	$tRectF = _GDIPlus_RectFCreate(0, 0, $width / 5, $height / 5)
	$hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, 0x60201010, 0xF0F04040, 45, True, 1)
	$hFormat = _GDIPlus_StringFormatCreate()
	_GDIPlus_StringFormatSetAlign($hFormat, 1)
	#Region scroller text
	Dim $aText[54][9] = [ _	;text, $hFamily, $hFont, font name, font size
			["AUTOIT", 1, 0, "Ethnocentric", 56], _
			["Windows Screenshooter", 0, 0, "Comic Sans MS", 48], _
			[$ver, 0, 0, "Comic Sans MS", 24], _
			[" ", 0, 0, "Arial", 50], _
			["Main Code", 0, 0, "Verdana", 30], _
			["by", 0, 0, "Times New Roman", 40], _
			["UEZ", 2, 0, "Vtks Revolt", 180], _
			[" ", 0, 0, "Arial", 20], _
			["Additional Code by:", 0, 0, "Georgia", 24], _
			["(alphabetical order)", 0, 0, "Tahoma", 14], _
			[" ", 0, 0, "Arial", 20], _
			["Authenticity", 0, 0, "Arial", 32], _
			["AutoIt Team", 0, 0, "Arial", 32], _
			["AutoItObject Team", 0, 0, "Arial", 32], _
			["Eemuli", 0, 0, "Arial", 32], _
			["eukalyptus", 0, 0, "Arial", 32], _
			["funkey", 0, 0, "Arial", 32], _
			["_Kurt", 0, 0, "Arial", 32], _
			["martin", 0, 0, "Arial", 32], _
			["monoceres", 0, 0, "Arial", 32], _
			["progandy", 0, 0, "Arial", 32], _
			["taietel", 0, 0, "Arial", 32], _
			["trancexx", 0, 0, "Arial", 32], _
			["Ward", 0, 0, "Arial", 32], _
			["wolf9228", 0, 0, "Arial", 32], _
			["Yashied", 0, 0, "Arial", 32], _
			[" ", 0, 0, "Arial", 100], _
			["Thanks to:", 0, 0, "Tunga", 40], _
			[" ", 0, 0, "Arial", 32], _
			["Andreas Skaarung for the chip tune:", 0, 0, "MV Boli", 36], _
			["Stop the Watch!", 0, 0, "Impact", 32], _
			[" ", 0, 0, "Arial", 32], _
			["UEZ Logo Font:", 0, 0, "Comic Sans MS", 36], _
			["Douglas Vitkauskas", 0, 0, "Arial", 32], _
			[" ", 0, 0, "Arial", 32], _
			["Windows Screenshooter Logo:", 0, 0, "Times New Roman", 32], _
			["http://picturetopeople.org", 0, 0, "Arial", 40], _
			[" ", 0, 0, "Arial", 32], _
			["andygo, Oscar and Raupi ", 0, 0, "Estrangelo Edessa", 48], _
			["for helping me to fix some issues", 0, 0, "Nyala", 32], _
			[" ", 0, 0, "Arial", 32], _
			["mesale0077", 0, 0, "Verdana", 40], _
			["for turkish language translation", 0, 0, "Comic Sans MS", 32], _
			[" ", 0, 0, "Arial", 32], _
			["wakillon", 0, 0, "Verdana", 40], _
			["for french language translation", 0, 0, "Comic Sans MS", 32], _
			[" ", 0, 0, "Arial", 32], _
			["AZJIO", 0, 0, "Verdana", 40], _
			["for russian language translation", 0, 0, "Comic Sans MS", 32], _
			[" ", 0, 0, "Arial", 120], _
			["Press ESC to quit", 0, 0, "Latha", 30], _
			[" ", 0, 0, "Arial", 120], _
			[ChrW(9996), 0, 0, "Arial", 500]]
	#EndRegion scroller text
	$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
	Local $y = $height, $sy = 0, $aInfo
	Local Const $dy = 10

	For $z = 0 To UBound($aText) - 1
		If $aText[$z][1] Then
			$aText[$z][1] = _GDIPlus_FontFamilyCreate($aText[$z][3], $hCollection)
		Else
			$aText[$z][1] = _GDIPlus_FontFamilyCreate($aText[$z][3]) ;$hFamily
			If @error Then
				$aText[$z][1] = _GDIPlus_FontFamilyCreate("Times New Roman") ;$hFamily
			EndIf
		EndIf
		$aText[$z][2] = _GDIPlus_FontCreate($aText[$z][1], $aText[$z][4]) ;$hFont
		$aInfo = _GDIPlus_GraphicsMeasureString($hGfx, $aText[$z][0], $aText[$z][2], $tLayout, $hFormat)
		$aText[$z][5] = Floor(DllStructGetData($aInfo[0], "Width"))
		$aText[$z][6] = Floor(DllStructGetData($aInfo[0], "Height"))
;~ 		$aText[$z][7] = Floor($width / 2 - ($aText[$z][5] / 2)) ;center text
		$aText[$z][7] = Floor($width / 2) ;center text
		$aText[$z][8] = $y + $dy + $sy
		$sy += $aText[$z][6]
	Next
	$speed = 1
	$iScrollHeight = $aText[UBound($aText) - 1][8]
	#EndRegion Init Scroller

	#Region Taskbar Progress Update
	If $aero Then
		; get interfaces
		$CLSID_TaskBarlist = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
		; ITaskbarList3:  http://msdn.microsoft.com/en-us/library/dd391692(VS.85).aspx
		$IID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
		$oTB3 = ObjCreateInterface( $CLSID_TaskBarlist, _
									$IID_ITaskbarList3, _
									$tagInterface)
		$oTB3.HrInit()
		$oTB3.SetProgressState(HWnd($hGUI), $TBPF_NORMAL)
	EndIf
	#EndRegion Taskbar Progress Update

	$About_End = False
	$iFrame_Anim = -1

	GUIRegisterMsg($WM_TIMER, "DrawGDIp") ;$WM_TIMER = 0x0113
	DllCall($dll, "int", "SetTimer", "hwnd", $hGUI_About, "int", 0, "int", 60, "int", 0)

	#Region Sleep until ESC is pressed
	Local $a
	While Sleep(60) * Not _IsPressed("1B", $dll)
		If $About_End Then ExitLoop
	WEnd
	#EndRegion Sleep until ESC is pressed

	GUIRegisterMsg($WM_TIMER, "")
	If $aero Then
		$oTB3.SetProgressState(HWnd($hGUI), $TBPF_NOPROGRESS)
		$oTB3 = 0
	EndIf

	#Region Fade-out
	For $z = 0xFF - $fade To 0 Step -$fade
		WinSetTrans($hGUI_About, "", $z)
	Next

	GUISetState(@SW_HIDE, $hGUI_About)
	_WinAPI_RedrawWindow(HWnd($hGUI), 0, 0, BitOR($RDW_NOFRAME, $RDW_NOINTERNALPAINT, $RDW_NOERASE))
	GUIDelete($hGUI_About)
	_WinAPI_RedrawWindow(HWnd($hGUI), 0, 0, BitOR($RDW_NOFRAME, $RDW_NOINTERNALPAINT, $RDW_NOERASE))
	#EndRegion Fade-out

	#Region Release Resources and Exit

	GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
	GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
	GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
	GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL_GUI")

	For $z = 0 To UBound($aText) - 1
		_GDIPlus_FontDispose($aText[$z][2])
		_GDIPlus_FontFamilyDispose($aText[$z][1])
	Next
	_GDIPlus_DeletePrivateFontCollection($hCollection)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_BitmapDispose($hImage_Anim)
	_GDIPlus_BitmapDispose($hImg_A)
	_GDIPlus_BitmapDispose($hBmp_A)
	_GDIPlus_BitmapDispose($hBMP_About)
	_GDIPlus_GraphicsDispose($hCtxt)
	_GDIPlus_GraphicsDispose($hGfx)
	For $z = 0 To $bubbles - 1
		_GDIPlus_BitmapDispose($aData[$z][5])
	Next

	Free_XM($hMusic) ; this frees song
	Die_XM() ; this kills everything else (if called, it should be after all the xm music is freed)

	$tFont_Mem1 = 0
	$tFont_Mem2 = 0
	$tLayout = 0
	$_XM_Tune = 0
	$tRectF = 0
	AutoItSetOption("GUICloseOnESC", 0)
	GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
;~ 	_ReduceMemory(@AutoItPID)
	_WinAPI_EmptyWorkingSet(@AutoItPID)
	For $i = 6 To 18
		_GUICtrlMenu_SetItemEnabled($hMenu, $i)
	Next
	#EndRegion Release Resources and Exit
EndFunc   ;==>About

Func DrawGDIp()
	Local $progress, $current, $end
;~ 	_GDIPlus_GraphicsDrawImage($hCtxt, $hImg_A, 0, 0) ;draw background
	DllCall($__g_hGDIPDll, "int", "GdipDrawImageI", "handle", $hCtxt, "handle", $hImg_A, "int", 0, "int", 0)
	Local $aPath[UBound($aText)], $aResult, $hPen = _GDIPlus_PenCreate(0x60000000, 2)
	DllCall($__g_hGDIPDll, "uint", "GdipSetPenLineJoin", "handle", $hPen, "int", 2)

	For $z = 0 To UBound($aText) - 1
		$aResult = DllCall($__g_hGDIPDll, "int", "GdipCreatePath", "int", 0, "handle*", 0)
		$aPath[$z] = $aResult[2]
		If $aText[$z][8] < $height And $aText[$z][8] > -$aText[$z][6] Then
			$tLayout = _GDIPlus_RectFCreate($aText[$z][7], $aText[$z][8], 0, 0)
;~ 			_GDIPlus_GraphicsDrawStringEx($hCtxt, $aText[$z][0], $aText[$z][2], $tLayout, $hFormat, $hBrush) ;draw scroller
;~ 			DllCall($__g_hGDIPDll, "int", "GdipDrawString", "handle", $hCtxt, "wstr", $aText[$z][0], "int", -1, "handle", $aText[$z][2], "struct*", $tLayout, "handle", $hFormat, "handle", $hBrush)
			DllCall($__g_hGDIPDll, "int", "GdipAddPathString", "handle", $aPath[$z], "wstr", $aText[$z][0], "int", -1, "handle", $aText[$z][1], "int", 0, "float", $aText[$z][4], "struct*", $tLayout, "handle", $hFormat)
			DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hCtxt, "handle", $hPen, "handle", $aPath[$z])
			DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush, "handle", $aPath[$z])
		EndIf
		$aText[$z][8] -= $speed
		DllCall($__g_hGDIPDll, "int", "GdipDeletePath", "handle", $aPath[$z])
	Next
	_GDIPlus_PenDispose($hPen)

	DllCall($__g_hGDIPDll, "int", "GdipImageSelectActiveFrame", "handle", $hImage_Anim, "ptr", $pGUID, "int", $iFrame_Anim) ;get frame from the anim
	$iFrame_Anim += 1 ;increase to next anim frame
	If $iFrame_Anim > $iFrameCount_Anim Then $iFrame_Anim = -1
;~ 	_GDIPlus_GraphicsDrawImageRect($hCtxt, $hImage_Anim, $width - $iW_Anim, $height - $iH_Anim, $iW_Anim, $iH_Anim) ;draw anim to backbuffer
	DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectI", "handle", $hCtxt, "handle", $hImage_Anim, "int", $width - $iW_Anim, "int", $height - $iH_Anim, "int", $iW_Anim, "int", $iH_Anim)

	Bubble_Anim() ;draw bubbles

;~ 	_GDIPlus_GraphicsDrawImageRect($hGfx, $hBMP_About, 0, 0, $width, $height) ;copy drawn bitmap to window gui
	DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectI", "handle", $hGfx, "handle", $hBMP_About, "int", 0, "int", 0, "int", $width, "int", $height)
	$current = $aText[UBound($aText) - 1][8]
	$end = -$aText[UBound($aText) - 1][6]
	If $aero Then ;show progress when Intro will be finished
		$progress = 100 - Round(($current - $end) / ($iScrollHeight - $end) * 100, 0)
		Switch $progress
			Case 0 To 74
				$oTB3.SetProgressState(HWnd($hGUI), $TBPF_NORMAL)
			Case 75 To 95
				$oTB3.SetProgressState(HWnd($hGUI), $TBPF_PAUSED)
			Case Else
				$oTB3.SetProgressState(HWnd($hGUI), $TBPF_ERROR)
		EndSwitch
		$oTB3.SetProgressValue(HWnd($hGUI), $progress, 100)
	EndIf
	If $current < $end Then ;end Intro when end has reached automatically
		$About_End = True
		GUIRegisterMsg($WM_TIMER, "")
	EndIf
EndFunc   ;==>DrawGDIp

Func Bubble_Anim()
	Local $j
	;draw bubbles
	For $j = 0 To $bubbles - 1
;~ 		_GDIPlus_GraphicsDrawImage($hCtxt, $aData[$j][5], $aData[$j][0], $aData[$j][1])
		DllCall($__g_hGDIPDll, "int", "GdipDrawImage", "handle", $hCtxt, "handle", $aData[$j][5], "float", $aData[$j][0], "float", $aData[$j][1])
	Next
	;calculate new position incl. border collision check
	For $j = 0 To $bubbles - 1
		$aData[$j][0] += $aData[$j][2] ;increase x coordinate with appropriate slope
		$aData[$j][1] += $aData[$j][3] ;increase y coordinate with appropriate slope
		If $aData[$j][0] <= 0 Then ;border collision x left
			$aData[$j][0] = 1
			$aData[$j][2] *= -1
		ElseIf $aData[$j][0] >= $width - $aData[$j][4] Then ;border collision x right
			$aData[$j][0] = $width - ($aData[$j][4] + 1)
			$aData[$j][2] *= -1
		EndIf
		If $aData[$j][1] <= 0 Then ;border collision y top
			$aData[$j][1] = 1
			$aData[$j][3] *= -1
		ElseIf $aData[$j][1] >= $height - $aData[$j][4] - $dh Then ;border collision y bottom
			$aData[$j][1] = $height - ($aData[$j][4] + 1) - $dh
			$aData[$j][3] *= -1
		EndIf
	Next
	Collision_Check()
EndFunc   ;==>Bubble_Anim

Func Collision_Check() ;0:x, 1:y, 2:vx, 3:vy, 4:size, 5:bmp
	Local $Delta_X, $Delta_Y, $Distance, $Matrix11, $Matrix12, $Matrix21, $Matrix22, $Vp1, $Vp2, $Vs1, $Vs2
	For $i = 0 To $bubbles - 1
		For $j = $i + 1 To $bubbles - 1
			If Pixel_Distance($aData[$i][0], $aData[$i][1], $aData[$j][0], $aData[$j][1]) < ($aData[$i][4] + $aData[$j][4]) / 2 Then
				$Delta_X = $aData[$i][0] - $aData[$j][0]
				$Delta_Y = $aData[$i][1] - $aData[$j][1]
				$Distance = Sqrt($Delta_X * $Delta_X + $Delta_Y * $Delta_Y)

				$Matrix11 = $Delta_X / $Distance
				$Matrix12 = -$Delta_Y / $Distance
				$Matrix21 = $Delta_Y / $Distance
				$Matrix22 = $Delta_X / $Distance

				$Vp1 = $aData[$i][2] * $Matrix11 + $aData[$i][3] * -$Matrix12
				$Vs1 = $aData[$i][2] * -$Matrix21 + $aData[$i][3] * $Matrix22
				$Vp2 = $aData[$j][2] * $Matrix11 + $aData[$j][3] * -$Matrix12
				$Vs2 = $aData[$j][2] * -$Matrix21 + $aData[$j][3] * $Matrix22

				If $Vp1 - $Vp2 < 0 Then
					$aData[$i][2] = $Matrix11 + $Vs1 * $Matrix12
					$aData[$i][3] = $Matrix21 + $Vs1 * $Matrix22
					$aData[$j][2] = $Matrix11 + $Vs2 * $Matrix12
					$aData[$j][3] = $Matrix21 + $Vs2 * $Matrix22
				EndIf
			EndIf
		Next
	Next
EndFunc   ;==>Collision_Check

Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
	Local $a, $b
	If $x2 = $x1 And $y2 = $y1 Then Return 0
	$a = $y2 - $y1
	$b = $x2 - $x1
	Return Sqrt($a * $a + $b * $b)
EndFunc   ;==>Pixel_Distance

Func _CreateBubbleBitmap($size = 75, $gradient_start = 0xA0F0C0C0, $gradient_end = 0xA0C0F0C0, $angle1 = 90, $angle2 = 45, $pen1 = 0x85AAAAAF, $pen2 = 0x28FFFFFF)
	Local $ps1 = 1, $ps2 = Ceiling($size / 12)
	Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($size + $ps1, $size + $ps1)
	Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetPixelOffsetMode($hContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
	Local $Pen_Border = _GDIPlus_PenCreate($pen1, $ps1)
	Local $Pen_Reflection = _GDIPlus_PenCreate($pen2, $ps2)
	Local $Brush_Gradient = _GDIPlus_LineBrushCreate(0, 0, $size, $size, $gradient_start, $gradient_end)
	_GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $size, $size, $Brush_Gradient)
	_GDIPlus_GraphicsDrawArc($hContext, $size / 3, $size / 5, $size / 2, $size / 2, 10, -$angle1, $Pen_Reflection)
	_GDIPlus_GraphicsDrawArc($hContext, $size / 6, $size / 3.5, $size / 2, $size / 2, -210, -$angle2, $Pen_Reflection)
	_GDIPlus_GraphicsDrawEllipse($hContext, $ps1 / 2, $ps1 / 2, $size - $ps1 / 2, $size - $ps1 / 2, $Pen_Border)
	_GDIPlus_PenDispose($Pen_Border)
	_GDIPlus_PenDispose($Pen_Reflection)
	_GDIPlus_BrushDispose($Brush_Gradient)
	_GDIPlus_GraphicsDispose($hContext)
	Return $hBitmap
EndFunc   ;==>_CreateBubbleBitmap

Func _Random($Min, $Max, $emin, $emax, $int = 0)
	Local $r1 = Random($Min, $emin, $int)
	Local $r2 = Random($emax, $Max, $int)
	If Random(0, 1, 1) Then Return $r1
	Return $r2
EndFunc   ;==>_Random
#EndRegion About Intro

#Region Some GUI elements
Func Donate()
	Return ShellExecute("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TYGSZGVMYV8ME")
EndFunc   ;==>Donate

Func _ScriptRestart($fExit = 1) ;thanks to Yashied
	Local $pid
	If Not $__Restart Then
		If @Compiled Then
			$pid = Run(@ScriptFullPath & " " & $CmdLineRaw, @ScriptDir, Default, 1)
		Else
			$pid = Run(@AutoItExe & ' "' & @ScriptFullPath & '" ' & $CmdLineRaw, @ScriptDir, Default, 1)
		EndIf
		If @error Then
			Return SetError(@error, 0, 0)
		EndIf
		StdinWrite($pid, @AutoItPID)
	EndIf
	$__Restart = 1
	If $fExit Then
		Sleep(50)
		Exit
	EndIf
	Return 1
EndFunc   ;==>_ScriptRestart

Func Refresh_Wnd_List()
	_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($List))
	$aWnd = GetAllWindow($bSearchForChildren)
	If Not IsArray($aWnd) Then Return SetError(1, 0, 0)
	Local $i
	For $i = 0 To UBound($aWnd) - 1
		_GUICtrlListView_AddItem($List, $aWnd[$i][0])
		_GUICtrlListView_AddSubItem($List, $i, $aWnd[$i][1], 1)
	Next
	Dim $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]
;~ 	_GUICtrlListView_SimpleSort($hListView, $B_DESCENDING, 0)
;~ 	_ArraySort($aWnd, Not $B_DESCENDING[0], 0, 0, 0)
EndFunc   ;==>Refresh_Wnd_List

Func _GDIPlus_ImageResize2($hImage, $iNewWidth, $iNewHeight, $iInterpolationMode = $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)
	Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
	Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
	Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iNewWidth, $iNewHeight)
	Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetInterpolationMode($hBmpCtxt, $iInterpolationMode)
	_GDIPlus_GraphicsSetPixelOffsetMode($hBmpCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $hIA = _GDIPlus_ImageAttributesCreate()
	_GDIPlus_ImageAttributesSetImageWrapMode($hIA)
	_GDIPlus_GraphicsDrawImageRectRect($hBmpCtxt, $hImage, 0, 0, $iWidth, $iHeight, 0, 0, $iNewWidth, $iNewHeight, $hIA)
	_GDIPlus_GraphicsDispose($hBmpCtxt)
	Return $hBitmap
EndFunc   ;==>_GDIPlus_ImageResize2

Func _GDIPlus_ImageAttributesSetImageWrapMode($hImageAttributes, $iWrapMode = $GDIP_WrapModeTileFlipXY, $iColor = 0xFF000000)
	Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetImageAttributesWrapMode", "handle", $hImageAttributes, _
											"long", $iWrapMode, "uint", $iColor, "boolean", False)
	If @error Then Return SetError(@error, @extended, False)
	If $aResult[0] Then Return SetError(10, $aResult[0], False)

	Return True
EndFunc   ;==>_GDIPlus_ImageAttributesSetImageWrapMode

Func _GDIPlus_Convert2HBitmap($hBitmap, $iColor); removes alpha backround using system color and converts to gdi bitmap
	Local $iBgColor = _WinAPI_GetSysColor($iColor)
	$iBgColor = 0x10000 * BitAND($iBgColor, 0xFF) + BitAND($iBgColor, 0x00FF00) + BitShift($iBgColor, 16)
	Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
	Local $hBitmap_new = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) ;$aResult[6]
	Local $hCtx_new = _GDIPlus_ImageGetGraphicsContext($hBitmap_new)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtx_new, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $iBgColor)
	_GDIPlus_GraphicsFillRect($hCtx_new, 0, 0, $iWidth, $iHeight, $hBrush)
	_GDIPlus_GraphicsDrawImageRect($hCtx_new, $hBitmap, 0, 0, $iWidth, $iHeight)
	Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_new)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_BitmapDispose($hBitmap_new)
	_GDIPlus_GraphicsDispose($hCtx_new)
	Return $hHBITMAP
EndFunc   ;==>_GDIPlus_Convert2HBitmap

Func _GDIPlus_CreateImageAndText($hImage, $sText, $iFontSize, $sFont = "Times New Roman", $iW = 93, $iH = 76, $iTextColor = 0xFF000000)
	Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "handle*", 0)
	Local Const $hBitmap = $aResult[6]
	Local Const $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetPixelOffsetMode($hGraphic, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $iBgColor = _WinAPI_GetSysColor($COLOR_BTNFACE)
	$iBgColor = 0x10000 * BitAND($iBgColor, 0xFF) + BitAND($iBgColor, 0x00FF00) + BitShift($iBgColor, 16)
	_GDIPlus_GraphicsClear($hGraphic, 0xFF000000 + $iBgColor)
	Local Const $hBrush = _GDIPlus_BrushCreateSolid($iTextColor)
	Local Const $hFormat = _GDIPlus_StringFormatCreate()
	Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
	Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize)
	Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
	_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
	DllCall($__g_hGDIPDll, "int", "GdipSetTextRenderingHint", "handle", $hGraphic, "int", 4)

	Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
	Local Const $iW_Text = DllStructGetData($aInfo[0], "Width"), $iH_Text = DllStructGetData($aInfo[0], "Height"), $iW_Image = _GDIPlus_ImageGetWidth($hImage), $iH_Image = _GDIPlus_ImageGetHeight($hImage)
	Local Const $iX = ($iW - ($iW_Text + $iW_Image + 4)) / 2
	_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $iX, ($iH - $iW_Image) / 2, $iW_Image, $iH_Image)
	DllStructSetData($tLayout, "X", $iX + $iW_Image)
	DllStructSetData($tLayout, "Y", ($iH - $iH_Text) / 2 - 1)
	DllStructSetData($tLayout, "Width", $iW_Text)
	DllStructSetData($tLayout, "Height", $iH_Text)
	_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush)

	_GDIPlus_FontDispose($hFont)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_GraphicsDispose($hGraphic)
	Local Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
	_GDIPlus_BitmapDispose($hBitmap)
	Return $hHBITMAP
EndFunc   ;==>_GDIPlus_CreateImageAndText

Func _GDIPlus_WTOB($hImage, $text, $fName = "Arial", $fSize = -1, $x = -1, $y = -1, $alignX = 2, $alignY = 2, $fColor = 0xFFFFFFFF, $ebg = 1)
	Local $iW = _GDIPlus_ImageGetWidth($hImage)
	Local $iH = _GDIPlus_ImageGetHeight($hImage)

	Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
	Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetPixelOffsetMode($hContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
	DllCall($__g_hGDIPDll, "int", "GdipSetInterpolationMode", "handle", $hContext, "int", 7)

	$fSize = Max(5, Int($iW * 0.010))

	Local $hPinsel = _GDIPlus_BrushCreateSolid($fColor)
	Local $hFormat = _GDIPlus_StringFormatCreate()
	Local $hFamily = _GDIPlus_FontFamilyCreate($fName)
	Local $hFont = _GDIPlus_FontCreate($hFamily, $fSize, 1)
	Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
	Local $aInfo = _GDIPlus_GraphicsMeasureString($hContext, $text, $hFont, $tLayout, $hFormat)

	_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iW, $iH)

	Local $fWidth = DllStructGetData($aInfo[0], "Width")
	Local $fHeight = DllStructGetData($aInfo[0], "Height")

	If $x < 0 Then
		Switch $alignX
			Case 0 ;alignment center
				DllStructSetData($tLayout, "x", $iW / 2 - Round($fWidth / 2, 0))
			Case 1 ;alignment left
				DllStructSetData($tLayout, "x", 0)
			Case 2 ;alignment right
				DllStructSetData($tLayout, "x", $iW - $fWidth - 1)
		EndSwitch
	Else
		DllStructSetData($tLayout, "x", $x)
	EndIf

	If $y < 0 Then
		Switch $alignY
			Case 0 ;alignment center
				DllStructSetData($tLayout, "y", $iH / 2 - Floor($fHeight / 2))
			Case 1 ;alignment top
				DllStructSetData($tLayout, "y", 0)
			Case 2 ;alignment buttom
				DllStructSetData($tLayout, "y", $iH - $fHeight - 1)
		EndSwitch
	Else
		DllStructSetData($tLayout, "y", $y)
	EndIf

	Local $hBrush_back = _GDIPlus_LineBrushCreate(0, 0, 0, $fSize, 0xFF101010, 0xFF808080)
	Local $i, $fs = $fSize * 0.075
	Local $tLayout2 = _GDIPlus_RectFCreate(0, 0, 0, 0)
	DllStructSetData($tLayout2, "Width", $fWidth)
	DllStructSetData($tLayout2, "Height", $fHeight)
	If $ebg Then
		For $i = 0 To 3
			Switch $i
				Case 0
					DllStructSetData($tLayout2, "x", DllStructGetData($tLayout, "x"))
					DllStructSetData($tLayout2, "y", DllStructGetData($tLayout, "y") - $fs)
				Case 1
					DllStructSetData($tLayout2, "x", DllStructGetData($tLayout, "x") + $fs)
					DllStructSetData($tLayout2, "y", DllStructGetData($tLayout, "y"))
				Case 2
					DllStructSetData($tLayout2, "x", DllStructGetData($tLayout, "x"))
					DllStructSetData($tLayout2, "y", DllStructGetData($tLayout, "y") + $fs)
				Case 3
					DllStructSetData($tLayout2, "x", DllStructGetData($tLayout, "x") - $fs)
					DllStructSetData($tLayout2, "y", DllStructGetData($tLayout, "y"))
			EndSwitch
			_GDIPlus_GraphicsDrawStringEx($hContext, $text, $hFont, $tLayout2, $hFormat, $hBrush_back)
		Next
	EndIf
	_GDIPlus_GraphicsDrawStringEx($hContext, $text, $hFont, $tLayout, $hFormat, $hPinsel)

	_GDIPlus_ImageDispose($hImage)
	_GDIPlus_FontDispose($hFont)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_BrushDispose($hPinsel)
	_GDIPlus_BrushDispose($hBrush_back)
	_GDIPlus_GraphicsDispose($hContext)
	$tLayout = 0
	$tLayout2 = 0
	Return $hBitmap
EndFunc   ;==>_GDIPlus_WTOB

Func _GDIPlus_BitmapCreateGrayscale(ByRef $hBmp, $skip = False)
	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	If Not $undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
	$undo_chk = True
	Local $hIA = _GDIPlus_ImageAttributesCreate()
	Local Const $GDIP_RLUM = 0.3086, $GDIP_GLUM = 0.6094, $GDIP_BLUM = 0.0820
	Local $ii, $iJ, $tColorMatrix, $aLums[4] = [$GDIP_RLUM, $GDIP_GLUM, $GDIP_BLUM, 0]
	$tColorMatrix = DllStructCreate($tagGDIPCOLORMATRIX)
	For $ii = 0 To 3
		For $iJ = 1 To 3
			DllStructSetData($tColorMatrix, "m", $aLums[$ii], $ii * 5 + $iJ)
		Next
	Next
	DllStructSetData($tColorMatrix, "m", 1, 19)
	DllStructSetData($tColorMatrix, "m", 1, 25)
	Local $pColorMatrix = DllStructGetPtr($tColorMatrix)
	_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBmp, 0, 0, $bW, $bH, 0, 0, $bW, $bH, $hIA)
	_GDIPlus_ImageAttributesDispose($hIA)
	_GDIPlus_GraphicsDispose($hCtxt)
	If Not $skip Then
		Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
		_WinAPI_DeleteObject($hClipboard_Bitmap)
		$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
		_WinAPI_DeleteObject($hHBmp)
		Draw2Graphic($hBmp)
	EndIf
EndFunc   ;==>_GDIPlus_BitmapCreateGrayscale

Func _GDIPlus_BitmapCreateBnW(ByRef $hBmp, $iLight = 160, $skip = False)
	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	If Not $undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
	$undo_chk = True
	Local $hIA = _GDIPlus_ImageAttributesCreate()
	_GDIPlus_ImageAttributesSetThreshold($hIA, 0, True, $iLight)
	Local Const $GDIP_RLUM = 0.3086, $GDIP_GLUM = 0.6094, $GDIP_BLUM = 0.0820
	Local $ii, $iJ, $tColorMatrix, $aLums[4] = [$GDIP_RLUM, $GDIP_GLUM, $GDIP_BLUM, 0]
	$tColorMatrix = DllStructCreate($tagGDIPCOLORMATRIX)
	For $ii = 0 To 3
		For $iJ = 1 To 3
			DllStructSetData($tColorMatrix, "m", $aLums[$ii], $ii * 5 + $iJ)
		Next
	Next
	DllStructSetData($tColorMatrix, "m", 1, 19)
	DllStructSetData($tColorMatrix, "m", 1, 25)
	Local $pColorMatrix = DllStructGetPtr($tColorMatrix)
	_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBmp, 0, 0, $bW, $bH, 0, 0, $bW, $bH, $hIA)
	_GDIPlus_ImageAttributesDispose($hIA)
	_GDIPlus_GraphicsDispose($hCtxt)
	If Not $skip Then
		Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
		_WinAPI_DeleteObject($hClipboard_Bitmap)
		$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
		_WinAPI_DeleteObject($hHBmp)
		Draw2Graphic($hBmp)
	EndIf
EndFunc   ;==>_GDIPlus_BitmapCreateBnW

Func _GDIPlus_BitmapCreateNegative(ByRef $hBmp, $skip = False)
	_GDIPlus_BitmapDispose($undo)
	$undo = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	If Not $undo Or @error Then Return MsgBox(BitOr($MB_ICONERROR, $MB_TOPMOST), $aTranslations[15][$iLang], $aTranslations[16][$iLang] & @CRLF & @CRLF & _
			$aTranslations[17][$iLang], 20, WinGetHandle(AutoItWinGetTitle()))
	$undo_chk = True
	Local $hIA = _GDIPlus_ImageAttributesCreate()
	Local $ii, $tColorMatrix
	$tColorMatrix = _GDIPlus_ColorMatrixCreateScale(-1, -1, -1, 1)
	For $ii = 1 To 4
		DllStructSetData($tColorMatrix, "m", 1, 20 + $ii)
	Next
	Local $pColorMatrix = DllStructGetPtr($tColorMatrix)
	_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBmp, 0, 0, $bW, $bH, 0, 0, $bW, $bH, $hIA)
	_GDIPlus_ImageAttributesDispose($hIA)
	_GDIPlus_GraphicsDispose($hCtxt)
	If Not $skip Then
		Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
		_WinAPI_DeleteObject($hClipboard_Bitmap)
		$hClipboard_Bitmap = _WinAPI_CopyImage($hHBmp, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
		_WinAPI_DeleteObject($hHBmp)
		Draw2Graphic($hBmp)
	EndIf
EndFunc   ;==>_GDIPlus_BitmapCreateNegative

Func _GDIPlus_PixelateBitmap(ByRef $hBmp, $iPixelate = 8, $bSmooth = 1)
	Local $iNewW = Int($bW / $iPixelate), $iNewH = Int($bH / $iPixelate)
	Local $hBitmap_scaled = _GDIPlus_BitmapCreateFromScan0($iNewW, $iNewH)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_scaled)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $iInterpolation = 5
	If $bSmooth Then $iInterpolation = 7
	_GDIPlus_GraphicsSetInterpolationMode($hCtxt, $iInterpolation)
	_GDIPlus_GraphicsDrawImageRect($hCtxt, $hBmp, 0, 0, $iNewW, $iNewH)
	_GDIPlus_GraphicsDispose($hCtxt)
	$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetInterpolationMode($hCtxt, 5)
	_GDIPlus_GraphicsClear($hCtxt, 0x00000000)
	_GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBitmap_scaled, 0, 0, $iNewW, $iNewH, -$iPixelate, -$iPixelate, $bW + 2 * $iPixelate, $bH + 2 * $iPixelate)
	_GDIPlus_GraphicsDispose($hCtxt)
EndFunc   ;==>_GDIPlus_PixelateBitmap

Func _GDIPlus_RasterizeBitmap(ByRef $hBmp, $iColor = 0x000000, $iAlpha = 0x80)
	Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(2, 2)
	Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $hPen = _GDIPlus_PenCreate($iAlpha * 0x1000000 + $iColor)
	_GDIPlus_GraphicsDrawLine($hCtxt, 0, 0, 1, 0, $hPen)
	_GDIPlus_GraphicsDrawLine($hCtxt, 1, 1, 2, 1, $hPen)
	Local $hTexture = DllCall($__g_hGDIPDll, "int", "GdipCreateTexture", "handle", $hBitmap, "int", 0, "ptr*", 0)
	$hTexture = $hTexture[3]
	_GDIPlus_GraphicsDispose($hCtxt)
	_GDIPlus_BitmapDispose($hBitmap)
	_GDIPlus_PenDispose($hPen)
	$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $bW, $bH, $hTexture)
	_GDIPlus_GraphicsDispose($hCtxt)
	_GDIPlus_BrushDispose($hTexture)
EndFunc   ;==>_GDIPlus_RasterizeBitmap

Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
	Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
	If @error Then Return SetError(1, @extended, 0)
	Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
	If @error Then Return SetError(2, @extended, 0)
	Local $iDPI = $aResult[2]
	_GDIPlus_GraphicsDispose($hGfx)
	Local $aResults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
	Return $aResults
EndFunc   ;==>_GDIPlus_GraphicsGetDPIRatio

Func _WinAPI_GetDpiForMonitor($dpiType = $MDT_DEFAULT, $iDPIDef = 96)
	Local $aMonitors = _WinAPI_EnumDisplayMonitors()
	Local $x, $y
	Local $aRet = DllCall("Shcore.dll", "long", "GetDpiForMonitor", "long", $aMonitors[1][0], "int", $dpiType, "uint*", $x, "uint*", $y)
	If @error Or Not IsArray($aRet) Then Return SetError(1, 0, 0)
	Local $aDPI[2] = [$iDPIDef / $aRet[3], $aRet[3] / $iDPIDef]
	Return $aDPI
EndFunc   ;==>_WinAPI_GetDpiForMonitor

Func _WinAPI_SetDPIAwareness($hGUI = 0)
	Switch @OSBuild
		Case 6000 To 9199
			If Not DllCall("user32.dll", "bool", "SetProcessDPIAware") Then Return SetError(1, 0, 0)
			Return 1
		Case 9200 To 13999
			_WinAPI_SetProcessDpiAwareness($PROCESS_PER_MONITOR_DPI_AWARE)
			If @error Then Return SetError(1, 0, 0)
			Return 1
		Case @OSBuild > 13999
			#cs
				Context_Unaware = ((DPI_AWARENESS_CONTEXT)(-1)),
				Context_SystemAware = ((DPI_AWARENESS_CONTEXT)(-2)),
				Context_PerMonitorAware = ((DPI_AWARENESS_CONTEXT)(-3)),
				Context_PerMonitorAwareV2 = ((DPI_AWARENESS_CONTEXT)(-4)),
				Context_UnawareGdiScaled = ((DPI_AWARENESS_CONTEXT)(-5))
			#ce
			_WinAPI_SetProcessDpiAwarenessContext($Context_PerMonitorAwareV2, $hGUI)
			If @error Then Return SetError(3, @error, 0)
			Return 1
	EndSwitch
	Return -1
EndFunc   ;==>_WinAPI_SetDPIAwareness

Func _WinAPI_SetProcessDpiAwareness($DPIAware) ;https://docs.microsoft.com/en-us/windows/desktop/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness
	DllCall("Shcore.dll", "long", "SetProcessDpiAwareness", "int", $DPIAware)
	If @error Then Return SetError(1, 0, 0)
	Return 1
EndFunc   ;==>_WinAPI_SetProcessDpiAwareness

;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext
Func _WinAPI_SetProcessDpiAwarenessContext($DPIAwareContext = $Context_PerMonitorAware, $hGUI = 0, $iMode = 1) ;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext
	$DPIAwareContext = ($DPIAwareContext < -5) ? -5 : ($DPIAwareContext > -1) ? -1 : $DPIAwareContext
	$iMode = ($iMode < 1) ? 1 : ($iMode > 3) ? 3 : $iMode
	Switch $iMode
		Case 1
			Local $hDC = _WinAPI_GetDC($hGUI)
			Local $aResult1 = DllCall("user32.dll", "ptr", "GetDpiFromDpiAwarenessContext", "ptr", $hDC)
			If @error Or Not IsArray($aResult1) Then Return SetError(11, 0, 0)
			_WinAPI_ReleaseDC(0, $hDC)
			Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult1[0] + $DPIAwareContext)
			If @error Or Not IsArray($aResult) Then Return SetError(12, 0, 0)
		Case 2
;~ 			If Not $hGUI Then $hGUI = WinGetHandle(AutoItWinGetTitle())
			Local $aResult2 = DllCall("user32.dll", "int", "GetWindowDpiAwarenessContext", "ptr", $hGUI)
			If @error Or Not IsArray($aResult2) Then Return SetError(21, 0, 0)
			Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult2[0] + $DPIAwareContext)
			If @error Or Not IsArray($aResult) Then Return SetError(22, 0, 0)
		Case 3
			Local $aResult31 = DllCall("user32.dll", "ptr", "GetThreadDpiAwarenessContext")
			If @error Or Not IsArray($aResult31) Then Return SetError(31, 0, 0)
			Local $aResult32 = DllCall("user32.dll", "ptr", "GetAwarenessFromDpiAwarenessContext", "ptr", $aResult31[0])
			If @error Or Not IsArray($aResult32) Then Return SetError(32, 0, 0)
			Local $aResult = DllCall("user32.dll", "Bool", "SetThreadDpiAwarenessContext", "int", $aResult32[0] + $DPIAwareContext)
			If @error Or Not IsArray($aResult) Then Return SetError(33, 0, 0)
	EndSwitch

    Return 1
EndFunc   ;==>_WinAPI_SetProcessDpiAwarenessContext

Func _GDIPlus_BitmapAddShadow($hBitmap, $bBgColor = False, $iX = 18, $iY = 24)
	Local $iW = $bW + $iX * 3.1, $iH = $bH + $iY * 2.55
	Local $hBitmap_Save = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
	Local $hCtxt_Shadow = _GDIPlus_ImageGetGraphicsContext($hBitmap_Save)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Shadow, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetInterpolationMode($hCtxt_Shadow, 7)
	_GDIPlus_GraphicsSetCompositingQuality($hCtxt_Shadow, 2)
	If $bBgColor Then _GDIPlus_GraphicsClear($hCtxt_Shadow, 0xFFFFFFFF)

	Local $hBitmap_Clone = _GDIPlus_BitmapClone($hBmp, $bW, $bH)
	Local $hDDB = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Clone)
	_GDIPlus_BitmapDispose($hBitmap_Clone)

	Local $h1Bit = _WinAPI_CreateANDBitmap($hDDB)
	_WinAPI_DeleteObject($hDDB)

	$hBitmap_Clone = _GDIPlus_BitmapCreateFromHBITMAP($h1Bit)
	_WinAPI_DeleteObject($h1Bit)

	Local $hBitmap_Mask =  _GDIPlus_BitmapCreateFromScan0($iW, $iH)
	Local $hCtxt_Mask = _GDIPlus_ImageGetGraphicsContext($hBitmap_Mask)
	_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Mask, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsSetInterpolationMode($hCtxt_Mask, 7)
	Local $hIA = _GDIPlus_ImageAttributesCreate()
	Local $aRemapTable[3][2]
	$aRemapTable[0][0] = 2
	$aRemapTable[1][0] = 0xFFFFFFFF
	$aRemapTable[1][1] = 0x00000000
	$aRemapTable[2][0] = 0xFF000000
	$aRemapTable[2][1] = 0xE0404040
	_GDIPlus_ImageAttributesSetRemapTable($hIA, 1, True, $aRemapTable)
	_GDIPlus_GraphicsDrawImageRectRect($hCtxt_Mask, $hBitmap_Clone, 0, 0, $bW, $bH, $iX, $iY, $bW, $bH, $hIA)
	_GDIPlus_GraphicsDispose($hCtxt_Mask)
	_GDIPlus_ImageAttributesDispose($hIA)

	Local $hBitmap_Shadow
;~ 	If Not $aero Then
		$hBitmap_Shadow = _Blur($hBitmap_Mask, $iW, $iH, 0, 0, 0, 0, 0.07)
;~ 	Else
;~ 		$hBitmap_Shadow = _GDIPlus_BitmapCloneArea($hBitmap_Mask, 0, 0, $iW, $iH, $GDIP_PXF32ARGB) ;bad quality (border added) when freehand captured image is used
;~ 		Local Const $hEffect = _GDIPlus_EffectCreateBlur(20, True)
;~ 		_GDIPlus_BitmapApplyEffect($hBitmap_Shadow, $hEffect)
;~ 		_GDIPlus_EffectDispose($hEffect)
;~ 	EndIf

	_GDIPlus_GraphicsDrawImageRect($hCtxt_Shadow, $hBitmap_Shadow, 12, 16, $iW, $iH)
	_GDIPlus_GraphicsDrawImageRect($hCtxt_Shadow, $hBmp, $iX, $iY, $bW, $bH)
	_GDIPlus_GraphicsDispose($hCtxt_Shadow)
	_GDIPlus_BitmapDispose($hBitmap_Mask)
	_GDIPlus_BitmapDispose($hBitmap_Clone)
	_GDIPlus_BitmapDispose($hBitmap_Shadow)
	Return $hBitmap_Save
EndFunc   ;==>_GDIPlus_BitmapAddShadow

Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "PNG", $iQuality = 80, $bSave = False, $sFilename = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2013-09-14
	Local $sImgCLSID, $tGUID, $tParams, $tData
	Switch $sFormat
		Case "JPG"
			$sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
			$tGUID = _WinAPI_GUIDFromString($sImgCLSID)
			$tData = DllStructCreate("int Quality")
			DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
			Local $pData = DllStructGetPtr($tData)
			$tParams = _GDIPlus_ParamInit(1)
			_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
		Case "PNG", "BMP", "GIF", "TIF"
			$sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
			$tGUID = _WinAPI_GUIDFromString($sImgCLSID)
		Case Else
			Return SetError(1, 0, 0)
	EndSwitch
	Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
	If @error Then Return SetError(2, 0, 0)
	_GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
	If @error Then Return SetError(3, 0, 0)
	Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
	If @error Then Return SetError(4, 0, 0)
	Local $iMemSize = _MemGlobalSize($hMemory)
	If Not $iMemSize Then Return SetError(5, 0, 0)
	Local $pMem = _MemGlobalLock($hMemory)
	$tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
	Local $bData = DllStructGetData($tData, 1)

	_WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
	_MemGlobalFree($hMemory)
	If $bSave Then
		Local $hFile = FileOpen($sFilename, 18)
		If @error Then Return SetError(6, 0, $bData)
		FileWrite($hFile, $bData)
		FileClose($hFile)
	EndIf
	Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString
#EndRegion Some GUI elements

#Region external functions
#Region _WinAPI_SetGUIMinMaxAnim / _WinAPI_GetGUIMinMaxAnim
Func _WinAPI_SetGUIMinMaxAnim($bAnim = 0)
	$bAnim = ($bAnim < 0) ? 0 : ($bAnim > 1) ? 1 : $bAnim
	Local Const $SPIF_SENDCHANGE = 0x02, $SPI_SETANIMATION = 0x0049
	Local $tANIMATIONINFO = DllStructCreate("uint cbSize;int iMinAnimate")
	$tANIMATIONINFO.cbSize = DllStructGetSize($tANIMATIONINFO)
	$tANIMATIONINFO.iMinAnimate = $bAnim
	Return _WinAPI_SystemParametersInfo($SPI_SETANIMATION, 0, $tANIMATIONINFO, $SPIF_SENDCHANGE)
EndFunc   ;==>_WinAPI_SetGUIMinMaxAnim

Func _WinAPI_GetGUIMinMaxAnim()
	Local Const $SPIF_SENDCHANGE = 0x02, $SPI_GETANIMATION = 0x0048
	Local $tANIMATIONINFO = DllStructCreate("uint cbSize;int iMinAnimate")
	$tANIMATIONINFO.cbSize = DllStructGetSize($tANIMATIONINFO)
	_WinAPI_SystemParametersInfo($SPI_GETANIMATION, $tANIMATIONINFO.cbSize, $tANIMATIONINFO)
	Return $tANIMATIONINFO.iMinAnimate
EndFunc   ;==>_WinAPI_GetGUIMinMaxAnim
#EndRegion _WinAPI_SetGUIMinMaxAnim / _WinAPI_GetGUIMinMaxAnim
#Region functions from WinAPIEx.au3
Func _GetNN($hWnd)
	Local $List, $text, $ID = 0
	$text = _WinAPI_GetClassName($hWnd)
	If Not $text Then
		Return -1
	EndIf
	$List = _WinAPI_EnumChildWindows(_WinAPI_GetAncestor($hWnd, $GA_ROOT), 0)
	If @error Then
		Return -1
	EndIf
	For $i = 1 To $List[0][0]
		If $List[$i][1] = $text Then
			$ID += 1
		EndIf
		If $List[$i][0] = $hWnd Then
			ExitLoop
		EndIf
	Next
	If Not $ID Then
		Return -1
	EndIf
	Return $ID
EndFunc   ;==>_GetNN

Func _WinAPI_CreateSolidCursorFromBitmap($iW, $iH, $iColor) ;iColor in BGR format
	Local $hDC = _WinAPI_GetWindowDC(0)
	Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
	Local $hXOR = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
	Local $hSv = _WinAPI_SelectObject($hMemDC, $hXOR)
	Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
	_WinAPI_SelectObject($hMemDC, $hBrush)
	Local $tRect = DllStructCreate($tagRECT)
	DllStructSetData($tRect, "Left", 0)
	DllStructSetData($tRect, "Top", 0)
	DllStructSetData($tRect, "Right", $iW)
	DllStructSetData($tRect, "Bottom", $iH)
	_WinAPI_FillRect($hMemDC, DllStructGetPtr($tRect), $hBrush)
	_WinAPI_ReleaseDC(0, $hDC)
	_WinAPI_SelectObject($hMemDC, $hSv)
	_WinAPI_DeleteDC($hMemDC)
	_WinAPI_DeleteObject($hBrush)

	$hDC = _WinAPI_GetWindowDC(0)
	$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
	Local Const $hAND = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
	$hSv = _WinAPI_SelectObject($hMemDC, $hAND)
	$hBrush = _WinAPI_CreateSolidBrush(0x0)
	_WinAPI_SelectObject($hMemDC, $hBrush)

	_WinAPI_FillRect($hMemDC, DllStructGetPtr($tRect), $hBrush)
	_WinAPI_ReleaseDC(0, $hDC)
	_WinAPI_SelectObject($hMemDC, $hSv)
	_WinAPI_DeleteDC($hMemDC)
	_WinAPI_DeleteObject($hBrush)

	Local Const $hCursor = _WinAPI_CreateIconIndirect($hXOR, $hAND, 0, 0, 0)
	_WinAPI_DeleteObject($hXOR)
	_WinAPI_DeleteObject($hAND)
	Return $hCursor
EndFunc   ;==>_WinAPI_CreateSolidCursorFromBitmap

Func _WinAPI_SetWindowTitleIcon($sFile, $hWnd, $iW = 32, $iH = 32)
	If $sFile = "" Then Return SetError(1, 0, 0)
	If Not IsHWnd($hWnd) Then Return SetError(2, 0, 0)
	Local Const $GCL_HICON = -14, $GCL_HICONSM = -34
	Local $hImage
	If Not FileExists($sFile) Then
		If _GDIPlus_ImageGetType($sFile) = -1 Then Return SetError(3, @error, 0)
		$hImage = $sFile ;interpret $sFile as a bitmap handle
	Else
		$hImage = _GDIPlus_ImageLoadFromFile($sFile)
		If @error Then Return SetError(4, @error, 0)
	EndIf
	Local $aRes = DllCall($__g_hGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImage, "uint", $iW, "uint", $iH, "ptr*", 0, "ptr", 0, "ptr", 0)
	If @error Then Return SetError(5, @error, 0)
	Local $hImageScaled = $aRes[4]
	$aRes = DllCall($__g_hGDIPDll, "uint", "GdipCreateHICONFromBitmap", "handle", $hImageScaled, "ptr*", 0)
	If @error Then
		_GDIPlus_ImageDispose($hImage)
		_GDIPlus_ImageDispose($hImageScaled)
		Return SetError(6, @error, 0)
	EndIf
	Local $hIconNew = $aRes[2]
	_WinAPI_SetClassLongEx($hWnd, $GCL_HICONSM, $hIconNew)
	If @error Then
		_GDIPlus_ImageDispose($hImage)
		_GDIPlus_ImageDispose($hImageScaled)
		Return SetError(7, @error, 0)
	EndIf
	_GDIPlus_ImageDispose($hImage)
	_GDIPlus_ImageDispose($hImageScaled)
	Return $hIconNew
EndFunc   ;==>_WinAPI_SetWindowTitleIcon
#EndRegion functions from WinAPIEx.au3
#Region _WinAPI_EmptyWorkingSet by Yashied
Func _WinAPI_EmptyWorkingSet($pid = 0)
	If Not $pid Then $pid = @AutoItPID
	Local $__WINVER = __Ver()
	Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", ($__WINVER < 0x0600) ? 0x00000500 : 0x00001100, "int", 0, "dword", $pid)
	If (@error) Or (Not $hProcess[0]) Then Return SetError(1, 0, 0)
	Local $Ret = DllCall(@SystemDir & "\psapi.dll", "int", "EmptyWorkingSet", "ptr", $hProcess[0])
	If (@error) Or (Not $Ret[0]) Then $Ret = 0
	_WinAPI_CloseHandle($hProcess[0])
	If Not IsArray($Ret) Then Return SetError(1, 0, 0)
	Return 1
EndFunc   ;==>_WinAPI_EmptyWorkingSet

Func __Ver()
	Local $tOSVI = DllStructCreate("dword;dword;dword;dword;dword;wchar[128]")
	DllStructSetData($tOSVI, 1, DllStructGetSize($tOSVI))
	Local $Ret = DllCall("kernel32.dll", "int", "GetVersionExW", "ptr", DllStructGetPtr($tOSVI))
	If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
	Return BitOR(BitShift(DllStructGetData($tOSVI, 2), -8), DllStructGetData($tOSVI, 3))
EndFunc   ;==>__Ver
#EndRegion _WinAPI_EmptyWorkingSet by Yashied
#Region extended function for MPDF_UDF.au3 by taietel
; #FUNCTION# ====================================================================================================================
; Name ..........: _LoadResImageMem()
; Description ...: Loads an image into the pdf (if you use it multiple times it decreases the size of the pdf)
; Syntax ........: _LoadResImageMem( $sImgAlias , $bImage  )
; Parameters ....: $sImgAlias           -  an alias to identify the image in the pdf (e.g. "Cheese").
;                  $bImage              -  binary image
; Return values .: Success      - True
;                  Failure      - False
; Author(s) .....: Mihai Iancu (taietel at yahoo dot com)
; Modified ......: UEZ
; Remarks .......: Image types accepted: BMP, GIF, TIF, TIFF, PNG, JPG, JPEG (those are tested)
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/118827-create-pdf-from-your-application/
; Example .......: No
; ===============================================================================================================================
Func _LoadResImageMem($sImgAlias, $bImage, $iW, $iH, $bInterpolate = "true") ;true must be in small letters!
	Local $iObj
	If $sImgAlias = "" Then __Error("You don't have an alias for the image", @ScriptLineNumber)
	If $bImage = "" Then
		__Error("You don't have any images to insert or binary string is invalid", @ScriptLineNumber)
	Else
		$iObj = __InitObj()
;~ 		__ToBuffer("<</Type /XObject /Subtype /Image /Name /" & $sImgAlias & " /Width " & $iW & " /Height " & $iH & " /Filter /DCTDecode /ColorSpace /DeviceRGB /BitsPerComponent 8" & " /Length " & $iObj + 1 & " 0 R" & ">>")
		__ToBuffer("<</Type /XObject /Subtype /Image /Name /" & $sImgAlias & " /Width " & $iW & " /Height " & $iH & " /Filter /DCTDecode /ColorSpace /DeviceRGB /BitsPerComponent 8 /Interpolate " & $bInterpolate & " /Length " & $iObj + 1 & " 0 R" & ">>")
		__ToBuffer("stream" & @CRLF & $bImage & @CRLF & "endstream")
		__EndObj()
		$_Image &= "/" & $sImgAlias & " " & $iObj & " 0 R " & @CRLF
		__InitObj()
		__ToBuffer(BinaryLen($bImage))
		__EndObj()
	EndIf
	Return $_Image
EndFunc   ;==>_LoadResImageMem
#EndRegion extended function for MPDF_UDF.au3 by taietel
;http://msdn.microsoft.com/en-us/library/aa910369.aspx WAVE
;http://msdn.microsoft.com/en-us/library/aa909803.aspx
#Region play wave from memory by  wolf9228
Func sndPlaySound($lpszSound, $fuSound)
	Local $Type = "wstr", $aRes
	If IsPtr($lpszSound) Then $Type = "ptr"
	$aRes = DllCall("winmm.dll", "int", "sndPlaySound", $Type, $lpszSound, "dword", $fuSound)
	If @error Then Return SetError(1, 0, 0)
	Return $aRes[0]
EndFunc   ;==>sndPlaySound
#EndRegion play wave from memory by  wolf9228
#Region Blur by eukalyptus
Func _Blur($hBitmap, $iW, $iH, $dx1 = 0, $dy1 = 0, $dx2 = 0, $dy2 = 0, $fScale = 0.175, $qual = 6); by eukalyptus
	Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
	Local $hBmpSmall = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
	Local $hGfxSmall = _GDIPlus_ImageGetGraphicsContext($hBmpSmall)
	_GDIPlus_GraphicsSetPixelOffsetMode($hGfxSmall, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	Local $hBmpBig = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
	Local $hGfxBig = _GDIPlus_ImageGetGraphicsContext($hBmpBig)
	_GDIPlus_GraphicsSetPixelOffsetMode($hGfxBig, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
	_GDIPlus_GraphicsScaleTransform($hGfxSmall, $fScale, $fScale)
	_GDIPlus_GraphicsSetInterpolationMode($hGfxSmall, $qual)

	_GDIPlus_GraphicsScaleTransform($hGfxBig, 1 / $fScale, 1 / $fScale)
	_GDIPlus_GraphicsSetInterpolationMode($hGfxBig, $qual)

	_GDIPlus_GraphicsDrawImageRect($hGfxSmall, $hBitmap, 0, $dx1, $iW, $iH + $dy1)
	_GDIPlus_GraphicsDrawImageRect($hGfxBig, $hBmpSmall, 0, $dx2, $iW, $iH + $dy2)

	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_BitmapDispose($hBmpSmall)
	_GDIPlus_GraphicsDispose($hGfxSmall)
	_GDIPlus_GraphicsDispose($hGfxBig)
	Return $hBmpBig
EndFunc   ;==>_Blur
#EndRegion Blur by eukalyptus
#Region MemFont by eukalyptus
Func _GDIPlus_DeletePrivateFontCollection($hCollection)
	Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDeletePrivateFontCollection", "handle*", $hFontCollection)
	If @error Then Return SetError(1, 0, False)
	Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_DeletePrivateFontCollection

Func _GDIPlus_NewPrivateFontCollection()
	Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipNewPrivateFontCollection", "ptr*", 0)
	If @error Then Return SetError(1, 0, 0)
	Return SetError($aResult[0], 0, $aResult[1])
EndFunc   ;==>_GDIPlus_NewPrivateFontCollection

Func _GDIPlus_PrivateAddMemoryFont($hCollection, $pMemory, $iLength)
	Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipPrivateAddMemoryFont", "ptr", $hCollection, "ptr", $pMemory, "int", $iLength)
	If @error Then Return SetError(1, 0, False)
	Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_PrivateAddMemoryFont
#EndRegion MemFont by eukalyptus
#Region _GetFontInfoFromFilePtr by funkey
Func _GetFontInfoFromFilePtr($pFile, $iFlag = 1); 0=copyright;1=name;2=type ... 10=description;11=website
	;funkey 2012, May 15
	Local $ttOffsetTable = DllStructCreate($tagTT_OFFSET_TABLE, $pFile)
	DllStructSetData($ttOffsetTable, "uNumOfTables", _SwapWord(DllStructGetData($ttOffsetTable, "uNumOfTables")))
	DllStructSetData($ttOffsetTable, "uMajorVersion", _SwapWord(DllStructGetData($ttOffsetTable, "uMajorVersion")))
	DllStructSetData($ttOffsetTable, "uMinorVersion", _SwapWord(DllStructGetData($ttOffsetTable, "uMinorVersion")))
	;check is this is a true type font and the version is 1.0
	If StringFormat("%i.%i", DllStructGetData($ttOffsetTable, "uMajorVersion"), DllStructGetData($ttOffsetTable, "uMinorVersion")) <> "1.0" Then
		Return SetError(1)
	EndIf
	Local $tblDir = DllStructCreate($tagTT_TABLE_DIRECTORY)
	Local $bFound = False
	Local $sTemp
	For $i = 0 To DllStructGetData($ttOffsetTable, "uNumOfTables") - 1
		$tblDir = DllStructCreate($tagTT_TABLE_DIRECTORY, $pFile + DllStructGetSize($ttOffsetTable) + $i * DllStructGetSize($tblDir))
		If StringLeft(DllStructGetData($tblDir, "szTag"), 4) = "name" Then
			$bFound = True
			DllStructSetData($tblDir, "uLength", _SwapLong(DllStructGetData($tblDir, "uLength")))
			DllStructSetData($tblDir, "uOffset", _SwapLong(DllStructGetData($tblDir, "uOffset")))
			ExitLoop
		EndIf
	Next
	If Not $bFound Then Return SetError(2)
	Local $ttNTHeader = DllStructCreate($tagTT_NAME_TABLE_HEADER, $pFile + DllStructGetData($tblDir, "uOffset"))
	DllStructSetData($ttNTHeader, "uNRCount", _SwapWord(DllStructGetData($ttNTHeader, "uNRCount")))
	DllStructSetData($ttNTHeader, "uStorageOffset", _SwapWord(DllStructGetData($ttNTHeader, "uStorageOffset")))
	Local $ttRecord = DllStructCreate($tagTT_NAME_RECORD)
	Local $tResult, $sResult
	For $i = 0 To DllStructGetData($ttNTHeader, "uNRCount") - 1
		$ttRecord = DllStructCreate($tagTT_NAME_RECORD, $pFile + DllStructGetData($tblDir, "uOffset") + DllStructGetSize($ttNTHeader) + $i * DllStructGetSize($ttRecord))
		DllStructSetData($ttRecord, "uNameID", _SwapWord(DllStructGetData($ttRecord, "uNameID")))
		If DllStructGetData($ttRecord, "uNameID") = $iFlag Then ;1 says that this is font name. 0 for example determines copyright info
			DllStructSetData($ttRecord, "uStringLength", _SwapWord(DllStructGetData($ttRecord, "uStringLength")))
			DllStructSetData($ttRecord, "uStringOffset", _SwapWord(DllStructGetData($ttRecord, "uStringOffset")))
			$tResult = DllStructCreate("char [" & DllStructGetData($ttRecord, "uStringLength") & "]", $pFile + _
					DllStructGetData($tblDir, "uOffset") + DllStructGetData($ttRecord, "uStringOffset") + _
					DllStructGetData($ttNTHeader, "uStorageOffset"))
			$sResult = DllStructGetData($tResult, 1)
			If StringLen($sResult) > 0 Then ExitLoop
		EndIf
	Next
	Return $sResult
EndFunc   ;==>_GetFontInfoFromFilePtr

Func _SwapLong($x)
	Return _WinAPI_MakeLong(_SwapWord(_WinAPI_HiWord($x)), _SwapWord(_WinAPI_LoWord($x)))
EndFunc   ;==>_SwapLong

Func _SwapWord($x)
	Return _WinAPI_MakeWord(_WinAPI_LoByte($x), _WinAPI_HiByte($x))
EndFunc   ;==>_SwapWord
#EndRegion _GetFontInfoFromFilePtr by funkey
#Region Additional GDI+ Functions
Func _GDIPlus_FontCollectionCreate()
	Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipNewInstalledFontCollection", "ptr*", 0)
	If @error Then Return SetError(@error, @extended, 0)
	Return $aResult[1]
EndFunc   ;==>_GDIPlus_FontCollectionCreate

Func _GDIPlus_FontCollectionGetFamilyList($hFontCollection)
	Local $ii, $iCount, $tFontFamilies, $aFontFamilies[1], $aResult
	$iCount = _GDIPlus_FontCollectionGetFamilyCount($hFontCollection)
	If @error Then Return SetError(@error, @extended, -1)
	If $iCount = 0 Then
		Return -1
	EndIf
	$tFontFamilies = DllStructCreate("hwnd[" & $iCount & "]")
	$aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetFontCollectionFamilyList", "handle", $hFontCollection, "int", $iCount, "struct*", $tFontFamilies, "int*", 0)
	If @error Then Return SetError(@error, @extended, -1)
	If $aResult[0] Then
		Return -1
	EndIf
	ReDim $aFontFamilies[$iCount + 1]
	$aFontFamilies[0] = $iCount
	For $ii = 1 To $iCount
		$aFontFamilies[$ii] = DllStructGetData($tFontFamilies, 1, $ii)
	Next
	Return $aFontFamilies
EndFunc   ;==>_GDIPlus_FontCollectionGetFamilyList

Func _GDIPlus_FontCollectionGetFamilyCount($hFontCollection)
	Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetFontCollectionFamilyCount", "handle", $hFontCollection, "int*", 0)
	If @error Then Return SetError(@error, @extended, 0)
	Return $aResult[2]
EndFunc   ;==>_GDIPlus_FontCollectionGetFamilyCount

Func _GDIPlus_FontFamilyGetFamilyName($hFontFamily, $iLANGID = 0)
	Local $tName, $sName, $aResult
	$tName = DllStructCreate("wchar[" & $GDIP_LF_FACESIZE & "]")
	$aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetFamilyName", "handle", $hFontFamily, "struct*", $tName, "ushort", $iLANGID)
	If @error Then Return SetError(@error, @extended, 0)
	If $aResult[0] Then Return 0
	$sName = DllStructGetData($tName, 1)
	Return $sName
EndFunc   ;==>_GDIPlus_FontFamilyGetFamilyName
#EndRegion Additional GDI+ Functions
#Region List all window handles by Authenticity
Func GetAllWindow($bSearchForChildren = False) ;code by Authenticity - modified by UEZ
	If $bSearchForChildren Then AutoItSetOption ("WinSearchChildren", 1)
	Local $aWin = WinList(), $aWindows[1][4]
	Local $iStyle, $iEx_Style, $iCounter = 0
	Local $i, $aWinPos
	For $i = 1 To $aWin[0][0]
		If @OSBuild < 6000 And $aWin[$i][1] = $hGUI Then ContinueLoop
		$iEx_Style = BitAND(_WinAPI_GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
		$iStyle = BitAND(WinGetState(HWnd($aWin[$i][1])), 2)
		If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
			$aWinPos = WinGetPos($aWin[$i][1])
;~ 			If _hWnd_IsVisible($aWin[$i][1], _WinAPI_GetParent($aWin[$i][1])) > -1 Then
			If $aWinPos[2] > 1 And $aWinPos[3] > 1 Then
				$aWindows[$iCounter][0] = $aWin[$i][0]
				$aWindows[$iCounter][1] = $aWin[$i][1]
				$aWindows[$iCounter][2] = $aWinPos[2]
				$aWindows[$iCounter][3] = $aWinPos[3]
				$iCounter += 1
			EndIf
			ReDim $aWindows[$iCounter + 1][4]
		EndIf
	Next
	ReDim $aWindows[$iCounter][4]
;~ 	AutoItSetOption ("WinSearchChildren", 0)
	Return $aWindows
EndFunc   ;==>GetAllWindow

Func _hWnd_IsVisible($hWnd, $hWnd_ParentGui = 0) ;by KaFu

    Local $tRect_hWnd = _WinAPI_GetWindowRect($hWnd)
    Local $h_Rgn_hWnd = _WinAPI_CreateRectRgn(DllStructGetData($tRect_hWnd, 1), DllStructGetData($tRect_hWnd, 2), DllStructGetData($tRect_hWnd, 3), DllStructGetData($tRect_hWnd, 4))

    Local $tRect_hWndPrev, $h_Rgn_hWndPrev

    Local $aList = WinList()

    For $i = 1 To $aList[0][0]
        If $aList[$i][1] = $hWnd Then ExitLoop
        If BitAND(WinGetState($aList[$i][1]), 2) And $aList[$i][1] <> $hWnd_ParentGui Then
            $tRect_hWndPrev = _WinAPI_GetWindowRect($aList[$i][1])
            $h_Rgn_hWndPrev = _WinAPI_CreateRectRgn(DllStructGetData($tRect_hWndPrev, 1), DllStructGetData($tRect_hWndPrev, 2), DllStructGetData($tRect_hWndPrev, 3), DllStructGetData($tRect_hWndPrev, 4))
            _WinAPI_CombineRgn($h_Rgn_hWnd, $h_Rgn_hWnd, $h_Rgn_hWndPrev, $RGN_DIFF)
            _WinAPI_DeleteObject($h_Rgn_hWndPrev)
        EndIf

    Next

    Local $iRes = _WinAPI_GetRgnBox($h_Rgn_hWnd, $tRect_hWnd)
    _WinAPI_DeleteObject($h_Rgn_hWnd)

    Switch $iRes
        Case 1 ; $NULLREGION
            Return 0
        Case 2 ; $SIMPLEREGION
            Return 1
        Case 3 ; $COMPLEXREGION
            Return 1
        Case Else ; 0 = Error
            Return -1
    EndSwitch

EndFunc   ;==>_hWnd_IsVisible

#EndRegion List all window handles by Authenticity
#Region _Mouse_Proc by _Kurt
;http://www.autoitscript.com/forum/index.php?showtopic=81761
;~ Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events.. Made by _Kurt
;~ 	;define local vars
;~ 	Local $info, $mouseData, $Ret, $mi
;~ 	If $nCode < 0 Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
;~ 		$Ret = DllCall($dll, "long", "CallNextHookEx", "handle", $hM_Hook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
;~ 		Return $Ret[0]
;~ 	EndIf
;~ 	$info = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
;~ 	$mouseData = DllStructGetData($info, 3)
;~ 	;Find which event happened
;~ 	Select
;~ 		Case $wParam = $WM_MOUSEWHEEL And WinActive(HWnd($hGUI))
;~ 			$mi = GUIGetCursorInfo()
;~ 			If Not @error Then
;~ 				If $mi[4] <> $List Then ;activate zooming only when mouse is not hovering listview section
;~ 					If _WinAPI_HiWord($mouseData) > 0 Then
;~ 						Zoom(1)
;~ 					Else
;~ 						Zoom(0)
;~ 					EndIf
;~ 					Return 1
;~ 				EndIf
;~ 			EndIf
;~ 	EndSelect

;~ 	;This is recommended instead of Return 0
;~ 	$Ret = DllCall($dll, "long", "CallNextHookEx", "handle", $hM_Hook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam)
;~ 	Return $Ret[0]
;~ EndFunc   ;==>_Mouse_Proc
;~ #EndRegion _Mouse_Proc by _Kurt
#Region Extract icons from a DLL and display it in a gui control menu by Yashied
Func _GUICtrlMenu_CreateBitmap($file, $iIndex = 0, $iX = 16, $iY = 16) ;thanks to Yashied
	If FileExists($file) Then
		Local $aRet, $hIcon, $hBitmap
		Local $hDC, $hBackDC, $hBackSv

		$aRet = DllCall("shell32", "long", "ExtractAssociatedIcon", "int", 0, "str", $file, "word*", $iIndex)
		If @error Then Return SetError(@error, @extended, 0)
		$hIcon = $aRet[0]

		$hDC = _WinAPI_GetDC(0) ;thanks to Yashied
		$hBackDC = _WinAPI_CreateCompatibleDC($hDC)
		$hBitmap = _WinAPI_CreateSolidBitmap(0, _WinAPI_GetSysColor($COLOR_MENU), $iX, $iY)
		$hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap)
		_WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, $iX, $iY, 0, 0, 3)
		_WinAPI_DestroyIcon($hIcon)

		_WinAPI_SelectObject($hBackDC, $hBackSv)
		_WinAPI_ReleaseDC(0, $hDC)
		_WinAPI_DeleteDC($hBackDC)
		Return $hBitmap
	Else
		Return SetError(1, 0, 0)
	EndIf
EndFunc   ;==>_GUICtrlMenu_CreateBitmap
#EndRegion Extract icons from a DLL and display it in a gui control menu by Yashied
#Region AVIWriter by monoceres, progandy - extended by UEZ
;Adds a bitmap file to an already opened avi file.
;monoceres, Prog@ndy
Func _AddHBitmapToAvi(ByRef $Avi_Handle, $hBitmap)
	Local $DC = _WinAPI_GetDC(0)
	Local $hDC = _WinAPI_CreateCompatibleDC($DC)
	_WinAPI_ReleaseDC(0, $DC)

	Local $OldBMP = _WinAPI_SelectObject($hDC, $hBitmap)
	Local $bits = DllStructCreate("byte[" & DllStructGetData($Avi_Handle[3], "biSizeImage") & "]")
	_WinAPI_GetDIBits($hDC, $hBitmap, 0, Abs(DllStructGetData($Avi_Handle[3], "biHeight")), DllStructGetPtr($bits), DllStructGetPtr($Avi_Handle[3]), 0)
	_WinAPI_SelectObject($hDC, $OldBMP)
	_WinAPI_DeleteDC($hDC)

	DllCall($Avi32_Dll, "int", "AVIStreamWrite", "ptr", $Avi_Handle[1], "long", $Avi_Handle[2], "long", 1, "ptr", DllStructGetPtr($bits), _
			"long", DllStructGetSize($bits), "long", $AVIIF_KEYFRAME, "ptr*", 0, "ptr*", 0)
	$Avi_Handle[2] += 1
EndFunc   ;==>_AddHBitmapToAvi

; Init the avi library
Func _StartAviLibrary()
	$Avi32_Dll = DllOpen("Avifil32.dll")
	DllCall($Avi32_Dll, "none", "AVIFileInit")
EndFunc   ;==>_StartAviLibrary

; Release the library
Func _StopAviLibrary()
	DllCall($Avi32_Dll, "none", "AVIFileExit")
	DllClose($Avi32_Dll)
EndFunc   ;==>_StopAviLibrary

Func _CloseAvi($Avi_Handle)
	DllCall($Avi32_Dll, "int", "AVIStreamRelease", "ptr", $Avi_Handle[1])
	DllCall($Avi32_Dll, "int", "AVIStreamRelease", "ptr", $Avi_Handle[5])
	DllCall($Avi32_Dll, "int", "AVIFileRelease", "ptr", $Avi_Handle[0])
EndFunc   ;==>_CloseAvi

;monoceres, Prog@ndy, UEZ
Func _CreateAvi($sFileName, $FrameRate, $width, $height, $BitCount = 24, $mmioFOURCC = "DIB")
	Local $RetArr[6] ;avi file handle, compressed stream handle, bitmap count, bitmap info header, stride, stream handle

	Local $aRet, $pFile, $asi, $amh, $aco, $pStream, $psCompressed

	Local $Stride = BitAND(($width * ($BitCount / 8) + 3), BitNOT(3))

	Local $bi = DllStructCreate($BITMAPINFOHEADER)
	DllStructSetData($bi, "biSize", DllStructGetSize($bi))
	DllStructSetData($bi, "biWidth", $width)
	DllStructSetData($bi, "biHeight", $height)
	DllStructSetData($bi, "biPlanes", 1)
	DllStructSetData($bi, "biBitCount", $BitCount)
	DllStructSetData($bi, "biSizeImage", $Stride * $height)

	$asi = DllStructCreate($AVISTREAMINFO)
	DllStructSetData($asi, "fccType", _Create_mmioFOURCC("vids"))
	DllStructSetData($asi, "fccHandler", _Create_mmioFOURCC($mmioFOURCC))
	DllStructSetData($asi, "dwRate", $FrameRate)
	DllStructSetData($asi, "dwScale", 1)
	DllStructSetData($asi, "dwQuality", -1) ;Quality is represented as a number between 0 and 10,000. For compressed data, this typically represents the value of the quality parameter passed to the compression software. If set to &#8211;1, drivers use the default quality value.
	DllStructSetData($asi, "dwSuggestedBufferSize", $Stride * $height)
	DllStructSetData($asi, "rright", $width)
	DllStructSetData($asi, "rbottom", $height)
	$aco = DllStructCreate($AVICOMPRESSOPTIONS)
	DllStructSetData($aco, "fccType", _Create_mmioFOURCC("vids"))
	DllStructSetData($aco, "fccHandler", _Create_mmioFOURCC($mmioFOURCC))

	$aRet = DllCall($Avi32_Dll, "int", "AVIFileOpenW", "ptr*", 0, "wstr", $sFileName, "uint", $OF_CREATE, "ptr", Null)
	$pFile = $aRet[1]

	$aRet = DllCall($Avi32_Dll, "int", "AVIFileCreateStream", "ptr", $pFile, "ptr*", 0, "ptr", DllStructGetPtr($asi))
	$pStream = $aRet[2]

	If $compress_avi Then
		AdlibRegister("AviHwndOnTop")
		$aRet = DllCall($Avi32_Dll, "bool", "AVISaveOptions", "hwnd", 0, "uint", BitOR($ICMF_CHOOSE_DATARATE, $ICMF_CHOOSE_KEYFRAME), "int", 1, "ptr*", $pStream, "ptr*", DllStructGetPtr($aco))
		If $aRet[0] <> 1 Then
			$RetArr[0] = $pFile
			$RetArr[1] = $pStream
			$RetArr[2] = 0
			$RetArr[3] = $bi
			$RetArr[4] = $Stride
			$RetArr[5] = $pStream
			Return SetError(1, 0, $RetArr)
		EndIf
	EndIf

	;http://msdn.microsoft.com/en-us/library/dd756811(v=VS.85).aspx
	$aRet = DllCall($Avi32_Dll, "int", "AVIMakeCompressedStream", "ptr*", 0, "ptr", $pStream, "ptr", DllStructGetPtr($aco), "ptr", Null)
	If $aRet[0] <> $AVIERR_OK Then
		$RetArr[0] = $pFile
		$RetArr[1] = $pStream
		$RetArr[2] = 0
		$RetArr[3] = $bi
		$RetArr[4] = $Stride
		$RetArr[5] = $pStream
		Return SetError(2, 0, $RetArr)
	EndIf
	$psCompressed = $aRet[1]

	;The format for the stream is the same as BITMAPINFOHEADER
	$aRet = DllCall($Avi32_Dll, "int", "AVIStreamSetFormat", "ptr", $psCompressed, "long", 0, "ptr", DllStructGetPtr($bi), "long", DllStructGetSize($bi))
	$RetArr[0] = $pFile
	$RetArr[1] = $psCompressed
	$RetArr[2] = 0
	$RetArr[3] = $bi
	$RetArr[4] = $Stride
	$RetArr[5] = $pStream
	Return $RetArr
EndFunc   ;==>_CreateAvi

Func AviHwndOnTop()
	Local $hWnd = WinGetHandle("[CLASS:#32770]")
	If Not @error Then
		If _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) = 0x94C800C4 Then WinSetOnTop($hWnd, "", 1)
	EndIf
	AdlibUnRegister("AviHwndOnTop")
EndFunc   ;==>AviHwndOnTop

;http://www.fourcc.org/codecs.php
Func _Create_mmioFOURCC($FOURCC) ;coded by UEZ
	If StringLen($FOURCC) <> 4 Then Return SetError(1, 0, 0)
	Local $aFOURCC = StringSplit($FOURCC, "", 2)
	Return BitOR(Asc($aFOURCC[0]), BitShift(Asc($aFOURCC[1]), -8), BitShift(Asc($aFOURCC[2]), -16), BitShift(Asc($aFOURCC[3]), -24))
EndFunc   ;==>_Create_mmioFOURCC

Func _DecodeFOURCC($iFOURCC) ;coded by UEZ
	If Not IsInt($iFOURCC) Then Return SetError(1, 0, 0)
	Return Chr(BitAND($iFOURCC, 0xFF)) & Chr(BitShift(BitAND(0x0000FF00, $iFOURCC), 8)) & Chr(BitShift(BitAND(0x00FF0000, $iFOURCC), 16)) & Chr(BitShift($iFOURCC, 24))
EndFunc   ;==>_DecodeFOURCC
#EndRegion AVIWriter by monoceres, progandy - extended by UEZ
#Region Debug
 Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType)
    Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", StringReplace($sTitle, "AutoIt", @ScriptName), _
            "uint", $iType)
    If @error Or Not $aCall[0] Then Return 0
    Return $aCall[0]
 EndFunc

 ;The magic is down below
Func AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "")
    Local Static $pImportDirectory, $hInstance
    Local Const $IMAGE_DIRECTORY_ENTRY_IMPORT = 1
    If Not $pImportDirectory Then
        $hInstance = _WinAPI_GetModuleHandle(0)
        $pImportDirectory = ImageDirectoryEntryToData($hInstance, $IMAGE_DIRECTORY_ENTRY_IMPORT)
        If @error Then Return SetError(1, 0, 0)
    EndIf
    Local $iIsInt = IsInt($vFunctionName)
    Local $iRestore = Not IsString($vNewFunction)
    Local $tIMAGE_IMPORT_MODULE_DIRECTORY
    Local $pDirectoryOffset = $pImportDirectory
    Local $tModuleName
    Local $iInitialOffset, $iInitialOffset2
    Local $iOffset2
    Local $tBufferOffset2, $iBufferOffset2
    Local $tBuffer, $tFunctionOffset, $pOld, $fMatch, $pModuleName, $pFuncName
    Local Const $PAGE_READWRITE = 0x04
    While 1
        $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _
                "dword TimeDateStamp;" & _
                "dword ForwarderChain;" & _
                "dword RVAModuleName;" & _
                "dword RVAFirstThunk", _
                $pDirectoryOffset)
        If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop
        $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName")
        $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $pModuleName)
        If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module
            $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk")
            $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk")
            If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset
            $iOffset2 = 0
            While 1
                $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2)
                $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1)
                If Not $iBufferOffset2 Then ExitLoop
                If $iIsInt Then
                    If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True; wanted function
                Else
                    $pFuncName = $hInstance + $iBufferOffset2 + 2 ; 2 is size od "word", see line below...
                    $tBuffer = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2)
                    If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True; wanted function
                EndIf
                If $fMatch Then
                    $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2)
                    VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE)
                    If @error Then Return SetError(3, 0, 0)
                    $pOld = DllStructGetData($tFunctionOffset, 1)
                    If $iRestore Then
                        DllStructSetData($tFunctionOffset, 1, $vNewFunction)
                    Else
                        DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams)))
                    EndIf
                    Return $pOld
                EndIf
                $iOffset2 += DllStructGetSize($tBufferOffset2)
            WEnd
            ExitLoop
        EndIf
        $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY
    WEnd
    Return SetError(4, 0, 0)
EndFunc

Func VirtualProtect($pAddress, $iSize, $iProtection)
    Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc

Func ImageDirectoryEntryToData($hInstance, $iDirectoryEntry)
    ; Get pointer to data
    Local $pPointer = $hInstance
    ; Start processing passed binary data. 'Reading' PE format follows.
    Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _
            "word BytesOnLastPage;" & _
            "word Pages;" & _
            "word Relocations;" & _
            "word SizeofHeader;" & _
            "word MinimumExtra;" & _
            "word MaximumExtra;" & _
            "word SS;" & _
            "word SP;" & _
            "word Checksum;" & _
            "word IP;" & _
            "word CS;" & _
            "word Relocation;" & _
            "word Overlay;" & _
            "char Reserved[8];" & _
            "word OEMIdentifier;" & _
            "word OEMInformation;" & _
            "char Reserved2[20];" & _
            "dword AddressOfNewExeHeader", _
            $pPointer)
    Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic")
    ; Check if it's valid format
    If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know.
    ; Move pointer
    $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header
    ; In place of IMAGE_NT_SIGNATURE structure
    Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer)
    ; Check signature
    If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE
        Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword.
    EndIf
    ; Move pointer
    $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure
    ; In place of IMAGE_FILE_HEADER structure
    ; Move pointer
    $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure
    ; Determine the type
    Local $tMagic = DllStructCreate("word Magic;", $pPointer)
    Local $iMagic = DllStructGetData($tMagic, 1)
    Local $tIMAGE_OPTIONAL_HEADER
    If $iMagic = 267 Then ; x86 version
        ; Move pointer
        $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER
    ElseIf $iMagic = 523 Then ; x64 version
        ; Move pointer
        $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER
    Else
        Return SetError(3, 0, 0) ; unsupported module type
    EndIf
    ; Validate input by checking available number of structures that are in the module
    Local Const $IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16 ; predefined value that PE modules always use (AutoIt certainly)
    If $iDirectoryEntry > $IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1 Then Return SetError(4, 0, 0) ; invalid input
    ; Calculate the offset to wanted entry (every entry is 8 bytes)
    $pPointer += 8 * $iDirectoryEntry
    ; At place of correst directory entry
    Local $tIMAGE_DIRECTORY_ENTRY = DllStructCreate("dword VirtualAddress; dword Size", $pPointer)
    ; Collect data
    Local $pAddress = DllStructGetData($tIMAGE_DIRECTORY_ENTRY, "VirtualAddress")
    If $pAddress = 0 Then Return SetError(5, 0, 0) ; invalid input
    ; $pAddress is RVA, add it to base address
    Return $hInstance + $pAddress
EndFunc
#EndRegion
#EndRegion external functions