#RequireAdmin Global Const $tagGDIPENCODERPARAM = "struct;byte GUID[16];ulong NumberOfValues;ulong Type;ptr Values;endstruct" Global Const $tagGDIPENCODERPARAMS = "uint Count;" & $tagGDIPENCODERPARAM Global Const $tagGDIPSTARTUPINPUT = "uint Version;ptr Callback;bool NoThread;bool NoCodecs" Global Const $tagGDIPIMAGECODECINFO = "byte CLSID[16];byte FormatID[16];ptr CodecName;ptr DllName;ptr FormatDesc;ptr FileExt;" & "ptr MimeType;dword Flags;dword Version;dword SigCount;dword SigSize;ptr SigPattern;ptr SigMask" Global Const $tagGUID = "struct;ulong Data1;ushort Data2;ushort Data3;byte Data4[8];endstruct" Global Const $tagOSVERSIONINFO = 'struct;dword OSVersionInfoSize;dword MajorVersion;dword MinorVersion;dword BuildNumber;dword PlatformId;wchar CSDVersion[128];endstruct' Global Const $__tagCURSORINFO = "dword Size;dword Flags;handle hCursor;" & "struct;long X;long Y;endstruct" Global Const $__WINVER = __WINVER() Func _WinAPI_GetCursorInfo() Local $tCursor = DllStructCreate($__tagCURSORINFO) Local $iCursor = DllStructGetSize($tCursor) DllStructSetData($tCursor, "Size", $iCursor) Local $aRet = DllCall("user32.dll", "bool", "GetCursorInfo", "struct*", $tCursor) If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) Local $aCursor[5] $aCursor[0] = True $aCursor[1] = DllStructGetData($tCursor, "Flags") <> 0 $aCursor[2] = DllStructGetData($tCursor, "hCursor") $aCursor[3] = DllStructGetData($tCursor, "X") $aCursor[4] = DllStructGetData($tCursor, "Y") Return $aCursor EndFunc Func __WINVER() Local $tOSVI = DllStructCreate($tagOSVERSIONINFO) DllStructSetData($tOSVI, 1, DllStructGetSize($tOSVI)) Local $aRet = DllCall('kernel32.dll', 'bool', 'GetVersionExW', 'struct*', $tOSVI) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) Return BitOR(BitShift(DllStructGetData($tOSVI, 2), -8), DllStructGetData($tOSVI, 3)) EndFunc Func _WinAPI_DeleteObject($hObject) Local $aResult = DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hObject) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_SelectObject($hDC, $hGDIObj) Local $aResult = DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _NowCalcDate() Return @YEAR & "/" & @MON & "/" & @MDAY EndFunc Global $__g_aArrayDisplay_SortInfo[11] Global Const $_ARRAYCONSTANT_tagLVITEM = "struct;uint Mask;int Item;int SubItem;uint State;uint StateMask;ptr Text;int TextMax;int Image;lparam Param;" & "int Indent;int GroupID;uint Columns;ptr pColumns;ptr piColFmt;int iGroup;endstruct" #Au3Stripper_Ignore_Funcs=__ArrayDisplay_SortCallBack Func __ArrayDisplay_SortCallBack($nItem1, $nItem2, $hWnd) If $__g_aArrayDisplay_SortInfo[3] = $__g_aArrayDisplay_SortInfo[4] Then If Not $__g_aArrayDisplay_SortInfo[7] Then $__g_aArrayDisplay_SortInfo[5] *= -1 $__g_aArrayDisplay_SortInfo[7] = 1 EndIf Else $__g_aArrayDisplay_SortInfo[7] = 1 EndIf $__g_aArrayDisplay_SortInfo[6] = $__g_aArrayDisplay_SortInfo[3] Local $sVal1 = __ArrayDisplay_GetItemText($hWnd, $nItem1, $__g_aArrayDisplay_SortInfo[3]) Local $sVal2 = __ArrayDisplay_GetItemText($hWnd, $nItem2, $__g_aArrayDisplay_SortInfo[3]) If $__g_aArrayDisplay_SortInfo[8] = 1 Then If(StringIsFloat($sVal1) Or StringIsInt($sVal1)) Then $sVal1 = Number($sVal1) If(StringIsFloat($sVal2) Or StringIsInt($sVal2)) Then $sVal2 = Number($sVal2) EndIf Local $nResult If $__g_aArrayDisplay_SortInfo[8] < 2 Then $nResult = 0 If $sVal1 < $sVal2 Then $nResult = -1 ElseIf $sVal1 > $sVal2 Then $nResult = 1 EndIf Else $nResult = DllCall('shlwapi.dll', 'int', 'StrCmpLogicalW', 'wstr', $sVal1, 'wstr', $sVal2)[0] EndIf $nResult = $nResult * $__g_aArrayDisplay_SortInfo[5] Return $nResult EndFunc Func __ArrayDisplay_GetItemText($hWnd, $iIndex, $iSubItem = 0) Local $tBuffer = DllStructCreate("wchar Text[4096]") Local $pBuffer = DllStructGetPtr($tBuffer) Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM) DllStructSetData($tItem, "SubItem", $iSubItem) DllStructSetData($tItem, "TextMax", 4096) DllStructSetData($tItem, "Text", $pBuffer) If IsHWnd($hWnd) Then DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x1073, "wparam", $iIndex, "struct*", $tItem) Else Local $pItem = DllStructGetPtr($tItem) GUICtrlSendMsg($hWnd, 0x1073, $iIndex, $pItem) EndIf Return DllStructGetData($tBuffer, "Text") EndFunc Global Const $GDIP_EPGCOLORDEPTH = '{66087055-AD66-4C7C-9A18-38A2310B8337}' Global Const $GDIP_EPGCOMPRESSION = '{E09D739D-CCD4-44EE-8EBA-3FBF8BE4FC58}' Global Const $GDIP_EPGQUALITY = '{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}' Func _WinAPI_GUIDFromString($sGUID) Local $tGUID = DllStructCreate($tagGUID) _WinAPI_GUIDFromStringEx($sGUID, $tGUID) If @error Then Return SetError(@error + 10, @extended, 0) Return $tGUID EndFunc Func _WinAPI_GUIDFromStringEx($sGUID, $tGUID) Local $aResult = DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_StringFromGUID($tGUID) Local $aResult = DllCall("ole32.dll", "int", "StringFromGUID2", "struct*", $tGUID, "wstr", "", "int", 40) If @error Or Not $aResult[0] Then Return SetError(@error, @extended, "") Return SetExtended($aResult[0], $aResult[2]) EndFunc Func _WinAPI_WideCharToMultiByte($vUnicode, $iCodePage = 0, $bRetNoStruct = True, $bRetBinary = False) Local $sUnicodeType = "wstr" If Not IsString($vUnicode) Then $sUnicodeType = "struct*" Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", $iCodePage, "dword", 0, $sUnicodeType, $vUnicode, "int", -1, "ptr", 0, "int", 0, "ptr", 0, "ptr", 0) If @error Or Not $aResult[0] Then Return SetError(@error + 20, @extended, "") Local $tMultiByte = DllStructCreate((($bRetBinary) ?("byte") :("char")) & "[" & $aResult[0] & "]") $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", $iCodePage, "dword", 0, $sUnicodeType, $vUnicode, "int", -1, "struct*", $tMultiByte, "int", $aResult[0], "ptr", 0, "ptr", 0) If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, "") If $bRetNoStruct Then Return DllStructGetData($tMultiByte, 1) Return $tMultiByte EndFunc Func _WinAPI_BitBlt($hDestDC, $iXDest, $iYDest, $iWidth, $iHeight, $hSrcDC, $iXSrc, $iYSrc, $iROP) Local $aResult = DllCall("gdi32.dll", "bool", "BitBlt", "handle", $hDestDC, "int", $iXDest, "int", $iYDest, "int", $iWidth, "int", $iHeight, "handle", $hSrcDC, "int", $iXSrc, "int", $iYSrc, "dword", $iROP) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) Local $aResult = DllCall("gdi32.dll", "handle", "CreateCompatibleBitmap", "handle", $hDC, "int", $iWidth, "int", $iHeight) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _WinAPI_CreateCompatibleDC($hDC) Local $aResult = DllCall("gdi32.dll", "handle", "CreateCompatibleDC", "handle", $hDC) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _WinAPI_DeleteDC($hDC) Local $aResult = DllCall("gdi32.dll", "bool", "DeleteDC", "handle", $hDC) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_DrawIcon($hDC, $iX, $iY, $hIcon) Local $aResult = DllCall("user32.dll", "bool", "DrawIcon", "handle", $hDC, "int", $iX, "int", $iY, "handle", $hIcon) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_GetDC($hWnd) Local $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _WinAPI_ReleaseDC($hWnd, $hDC) Local $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDC) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Global Const $tagICONINFO = "bool Icon;dword XHotSpot;dword YHotSpot;handle hMask;handle hColor" Func _WinAPI_CopyIcon($hIcon) Local $aResult = DllCall("user32.dll", "handle", "CopyIcon", "handle", $hIcon) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _WinAPI_DestroyIcon($hIcon) Local $aResult = DllCall("user32.dll", "bool", "DestroyIcon", "handle", $hIcon) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc Func _WinAPI_GetIconInfo($hIcon) Local $tInfo = DllStructCreate($tagICONINFO) Local $aRet = DllCall("user32.dll", "bool", "GetIconInfo", "handle", $hIcon, "struct*", $tInfo) If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) Local $aIcon[6] $aIcon[0] = True $aIcon[1] = DllStructGetData($tInfo, "Icon") <> 0 $aIcon[2] = DllStructGetData($tInfo, "XHotSpot") $aIcon[3] = DllStructGetData($tInfo, "YHotSpot") $aIcon[4] = DllStructGetData($tInfo, "hMask") $aIcon[5] = DllStructGetData($tInfo, "hColor") Return $aIcon EndFunc Global $__g_hGDIPDll = 0 Global $__g_iGDIPRef = 0 Global $__g_iGDIPToken = 0 Global $__g_bGDIP_V1_0 = True Func _GDIPlus_BitmapCloneArea($hBitmap, $nLeft, $nTop, $nWidth, $nHeight, $iFormat = 0x00021808) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipCloneBitmapArea", "float", $nLeft, "float", $nTop, "float", $nWidth, "float", $nHeight, "int", $iFormat, "handle", $hBitmap, "handle*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $aResult[7] EndFunc Func _GDIPlus_BitmapCreateFromHBITMAP($hBitmap, $hPal = 0) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipCreateBitmapFromHBITMAP", "handle", $hBitmap, "handle", $hPal, "handle*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $aResult[3] EndFunc Func _GDIPlus_Encoders() Local $iCount = _GDIPlus_EncodersGetCount() Local $iSize = _GDIPlus_EncodersGetSize() Local $tBuffer = DllStructCreate("byte[" & $iSize & "]") Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageEncoders", "uint", $iCount, "uint", $iSize, "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Local $pBuffer = DllStructGetPtr($tBuffer) Local $tCodec, $aInfo[$iCount + 1][14] $aInfo[0][0] = $iCount For $iI = 1 To $iCount $tCodec = DllStructCreate($tagGDIPIMAGECODECINFO, $pBuffer) $aInfo[$iI][1] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "CLSID")) $aInfo[$iI][2] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "FormatID")) $aInfo[$iI][3] = _WinAPI_WideCharToMultiByte(DllStructGetData($tCodec, "CodecName")) $aInfo[$iI][4] = _WinAPI_WideCharToMultiByte(DllStructGetData($tCodec, "DllName")) $aInfo[$iI][5] = _WinAPI_WideCharToMultiByte(DllStructGetData($tCodec, "FormatDesc")) $aInfo[$iI][6] = _WinAPI_WideCharToMultiByte(DllStructGetData($tCodec, "FileExt")) $aInfo[$iI][7] = _WinAPI_WideCharToMultiByte(DllStructGetData($tCodec, "MimeType")) $aInfo[$iI][8] = DllStructGetData($tCodec, "Flags") $aInfo[$iI][9] = DllStructGetData($tCodec, "Version") $aInfo[$iI][10] = DllStructGetData($tCodec, "SigCount") $aInfo[$iI][11] = DllStructGetData($tCodec, "SigSize") $aInfo[$iI][12] = DllStructGetData($tCodec, "SigPattern") $aInfo[$iI][13] = DllStructGetData($tCodec, "SigMask") $pBuffer += DllStructGetSize($tCodec) Next Return $aInfo EndFunc Func _GDIPlus_EncodersGetCLSID($sFileExtension) Local $aEncoders = _GDIPlus_Encoders() If @error Then Return SetError(@error, 0, "") For $iI = 1 To $aEncoders[0][0] If StringInStr($aEncoders[$iI][6], "*." & $sFileExtension) > 0 Then Return $aEncoders[$iI][1] Next Return SetError(-1, -1, "") EndFunc Func _GDIPlus_EncodersGetCount() Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageEncodersSize", "uint*", 0, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], -1) Return $aResult[1] EndFunc Func _GDIPlus_EncodersGetSize() Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageEncodersSize", "uint*", 0, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], -1) Return $aResult[2] EndFunc Func _GDIPlus_ImageDispose($hImage) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDisposeImage", "handle", $hImage) If @error Then Return SetError(@error, @extended, False) If $aResult[0] Then Return SetError(10, $aResult[0], False) Return True EndFunc Func _GDIPlus_ImageGetHeight($hImage) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageHeight", "handle", $hImage, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], -1) Return $aResult[2] EndFunc Func _GDIPlus_ImageGetWidth($hImage) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageWidth", "handle", $hImage, "uint*", -1) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], -1) Return $aResult[2] EndFunc Func _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sEncoder, $tParams = 0) Local $tGUID = _WinAPI_GUIDFromString($sEncoder) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSaveImageToFile", "handle", $hImage, "wstr", $sFileName, "struct*", $tGUID, "struct*", $tParams) If @error Then Return SetError(@error, @extended, False) If $aResult[0] Then Return SetError(10, $aResult[0], False) Return True EndFunc Func _GDIPlus_ParamAdd(ByRef $tParams, $sGUID, $iNbOfValues, $iType, $pValues) Local $iCount = DllStructGetData($tParams, "Count") Local $pGUID = DllStructGetPtr($tParams, "GUID") +($iCount * _GDIPlus_ParamSize()) Local $tParam = DllStructCreate($tagGDIPENCODERPARAM, $pGUID) _WinAPI_GUIDFromStringEx($sGUID, $pGUID) DllStructSetData($tParam, "Type", $iType) DllStructSetData($tParam, "NumberOfValues", $iNbOfValues) DllStructSetData($tParam, "Values", $pValues) DllStructSetData($tParams, "Count", $iCount + 1) EndFunc Func _GDIPlus_ParamInit($iCount) Local $sStruct = $tagGDIPENCODERPARAMS For $i = 2 To $iCount $sStruct &= ";struct;byte[16];ulong;ulong;ptr;endstruct" Next Return DllStructCreate($sStruct) EndFunc Func _GDIPlus_ParamSize() Local $tParam = DllStructCreate($tagGDIPENCODERPARAM) Return DllStructGetSize($tParam) EndFunc Func _GDIPlus_Shutdown() If $__g_hGDIPDll = 0 Then Return SetError(-1, -1, False) $__g_iGDIPRef -= 1 If $__g_iGDIPRef = 0 Then DllCall($__g_hGDIPDll, "none", "GdiplusShutdown", "ulong_ptr", $__g_iGDIPToken) DllClose($__g_hGDIPDll) $__g_hGDIPDll = 0 EndIf Return True EndFunc Func _GDIPlus_Startup($sGDIPDLL = Default, $bRetDllHandle = False) $__g_iGDIPRef += 1 If $__g_iGDIPRef > 1 Then Return True If $sGDIPDLL = Default Then $sGDIPDLL = "gdiplus.dll" $__g_hGDIPDll = DllOpen($sGDIPDLL) If $__g_hGDIPDll = -1 Then $__g_iGDIPRef = 0 Return SetError(1, 2, False) EndIf Local $sVer = FileGetVersion($sGDIPDLL) $sVer = StringSplit($sVer, ".") If $sVer[1] > 5 Then $__g_bGDIP_V1_0 = False Local $tInput = DllStructCreate($tagGDIPSTARTUPINPUT) Local $tToken = DllStructCreate("ulong_ptr Data") DllStructSetData($tInput, "Version", 1) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdiplusStartup", "struct*", $tToken, "struct*", $tInput, "ptr", 0) If @error Then Return SetError(@error, @extended, False) If $aResult[0] Then Return SetError(10, $aResult[0], False) $__g_iGDIPToken = DllStructGetData($tToken, "Data") If $bRetDllHandle Then Return $__g_hGDIPDll Return SetExtended($sVer[1], True) EndFunc Func __GDIPlus_ExtractFileExt($sFileName, $bNoDot = True) Local $iIndex = __GDIPlus_LastDelimiter(".\:", $sFileName) If($iIndex > 0) And(StringMid($sFileName, $iIndex, 1) = '.') Then If $bNoDot Then Return StringMid($sFileName, $iIndex + 1) Else Return StringMid($sFileName, $iIndex) EndIf Else Return "" EndIf EndFunc Func __GDIPlus_LastDelimiter($sDelimiters, $sString) Local $sDelimiter, $iN For $iI = 1 To StringLen($sDelimiters) $sDelimiter = StringMid($sDelimiters, $iI, 1) $iN = StringInStr($sString, $sDelimiter, 2, -1) If $iN > 0 Then Return $iN Next EndFunc Func _WinAPI_GetDesktopWindow() Local $aResult = DllCall("user32.dll", "hwnd", "GetDesktopWindow") If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _WinAPI_GetSystemMetrics($iIndex) Local $aResult = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $iIndex) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Global $__g_iBMPFormat = 0x00021808 Global $__g_iJPGQuality = 100 Global $__g_iTIFColorDepth = 24 Global $__g_iTIFCompression = 2 Global Const $__SCREENCAPTURECONSTANT_SRCCOPY = 0x00CC0020 Func _ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $bCursor = True) Local $bRet = False If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics(0) - 1 If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics(1) - 1 If $iRight < $iLeft Then Return SetError(-1, 0, $bRet) If $iBottom < $iTop Then Return SetError(-2, 0, $bRet) 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, $__SCREENCAPTURECONSTANT_SRCCOPY) If $bCursor Then Local $aCursor = _WinAPI_GetCursorInfo() If Not @error And $aCursor[1] Then $bCursor = True Local $hIcon = _WinAPI_CopyIcon($aCursor[2]) Local $aIcon = _WinAPI_GetIconInfo($hIcon) If Not @error Then _WinAPI_DeleteObject($aIcon[4]) If $aIcon[5] <> 0 Then _WinAPI_DeleteObject($aIcon[5]) _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon) EndIf _WinAPI_DestroyIcon($hIcon) EndIf EndIf _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) If $sFileName = "" Then Return $hBMP $bRet = _ScreenCapture_SaveImage($sFileName, $hBMP, True) Return SetError(@error, @extended, $bRet) EndFunc Func _ScreenCapture_SaveImage($sFileName, $hBitmap, $bFreeBmp = True) _GDIPlus_Startup() If @error Then Return SetError(-1, -1, False) Local $sExt = StringUpper(__GDIPlus_ExtractFileExt($sFileName)) Local $sCLSID = _GDIPlus_EncodersGetCLSID($sExt) If $sCLSID = "" Then Return SetError(-2, -2, False) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) If @error Then Return SetError(-3, -3, False) Local $tData, $tParams Switch $sExt Case "BMP" Local $iX = _GDIPlus_ImageGetWidth($hImage) Local $iY = _GDIPlus_ImageGetHeight($hImage) Local $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $__g_iBMPFormat) _GDIPlus_ImageDispose($hImage) $hImage = $hClone Case "JPG", "JPEG" $tParams = _GDIPlus_ParamInit(1) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $__g_iJPGQuality) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, 4, DllStructGetPtr($tData)) Case "TIF", "TIFF" $tParams = _GDIPlus_ParamInit(2) $tData = DllStructCreate("int ColorDepth;int Compression") DllStructSetData($tData, "ColorDepth", $__g_iTIFColorDepth) DllStructSetData($tData, "Compression", $__g_iTIFCompression) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, 4, DllStructGetPtr($tData, "ColorDepth")) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, 4, DllStructGetPtr($tData, "Compression")) EndSwitch Local $pParams = 0 If IsDllStruct($tParams) Then $pParams = $tParams Local $bRet = _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sCLSID, $pParams) _GDIPlus_ImageDispose($hImage) If $bFreeBmp Then _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() Return SetError($bRet = False, 0, $bRet) EndFunc Opt("MustDeclareVars", 1) Opt("WinWaitDelay", 250) Func TDDefault(ByRef $sPath, ByRef $syyyymmddDash) Local $sTMP = EnvGet("TMP") $sPath = $sTMP & "\TDAmeritrade" Local $sDate = _NowCalcDate() $syyyymmddDash = StringReplace($sDate, "/", "-") EndFunc Func TDClearSlate($sPath, $syyyymmddDash, $sEndTag, $sDeleteAllFiles = True) Local $sFullPath If $sDeleteAllFiles Then $sFullPath = $sPath & "\*" & $sEndTag Else $sFullPath = $sPath & "\" & $syyyymmddDash & "-" & $sEndTag EndIf Local $iDelete = FileDelete($sFullPath) Return SetError(@error, "", $iDelete) EndFunc Func TDFileExists($sFullPath) Local $iExists Do Sleep(250) $iExists = FileExists($sFullPath) Until $iExists = 1 Return SetError(@error, "", $iExists) EndFunc Func TDExporttoFile($sWinWait, $sFileName, $sConfirm = False, $timeout = 0) KillWindows() Local $success Do Local $hWin = WinWait($sWinWait, "", $timeout) If $hWin Then KillWindows() WinActivate($hWin) Local $FileName = ControlGetText($hWin, "", "[ID:1001]") If StringLeft($FileName, 10) == StringRegExp($sFileName, "([0-9\-]{10})", 1)[0] Then $success = ControlSetText($hWin, "", "[ID:1001]", $sFileName) If $success = 0 Then MsgBox(4096, "file name", "failing to put in text by [ID:1001]") EndIf Else Return SetError(6, "", 6) EndIf Local $hConfirm KillWindows() $success = ControlClick($hWin, "", "[ID:1]") If $success = 0 Then MsgBox(4096, "Save button", "not found by [CLASS:Button; TEXT:&Save]") Return SetError(2, "", 2) Else If $sConfirm Then $hConfirm = WinWait("Confirm Save As", "", 8) WinActivate($hConfirm) SendKeepActive($hConfirm) If $hConfirm Then $success = ControlClick($hConfirm, "", "[CLASS:Button; TEXT:&Yes]") If $success = 0 Then MsgBox(4096, "Yes button", "not found by [CLASS:Button; TEXT:&Yes]") Return SetError(4, "", 4) Else Return SetError(0, "", 0) EndIf Else Return SetError(3, "", 3) EndIf Else KillWindows() $hConfirm = WinWait("Confirm Save As", "", 2) If $hConfirm Then Return SetError(5, "", 5) Else Return SetError(0, "", 0) EndIf EndIf EndIf Else Local $response = 2 If $response = 2 Then Return SetError(1, "", 1) EndIf EndIf Until $response = 2 EndFunc Func GetXYCoords($sTag, $iNum = 16) Local $iTag Select Case $sTag = "tosPosn" $iTag = 0 Case $sTag = "expMessage" $iTag = 1 Case $sTag = "MRGMargin" $iTag = 2 Case $sTag = "expOptionPosn" $iTag = 2 Case $sTag = "getRelErnsDates" $iTag = 3 Case $sTag = "earningsEOD" $iTag = 4 Case $sTag = "OnDemandHist" $iTag = 5 Case $sTag = "StackupTrades" $iTag = 6 Case $sTag = "startTos" $iTag = 7 Case $sTag = "MRGBlastAll" $iTag = 8 Case $sTag = "OptionQuotes" $iTag = 9 Case $sTag = "RTD" $iTag = 9 Case Else Return SetError(1, "", 1) EndSelect Local $aGrid[3][10] = [ ["0,0,1310,1400,1301,0,1006,1407,1301,466,1006,640,2291,0,1156,1407,1301,1072,1006,335", "920,20,1060,48,1060,200", "1400,88,2280,156,2220,524,1308,1400,0,340,1372,98,1436,112,1,1", "2334,72,2992,64,3264,740,2924,520,2924,532,3096,960,3124,916", "1160,102,1280,184,1288,64,1250,268", "0,0,1060,60,1060,284,1136,284,1288,80,1288,256,1424,256,5,5,64,36", "2291,67,1006,335,2291,402,1006,335,2291,737,1006,335,2291,1072,1006,335", "32, 124, 32, 236", "3320,1332,3190,1332", "0,0,1288,64,1288,232,1416,232" ], ["0, 0, 1504, 963, 0, 0, 1504, 963, 316, 0, 1195, 968,0, 0, 1504, 963, 316, 560, 1195, 408", "1088,16,1272,48,1272,268", "100,100,1472,228,1480,752,188,963,0,364,150,180,268,224,1,1", "72,72,888,72,1312,360,832,216,832,236,1056,828,1096,760", "1352,128,1472,236,1488,76,1488,368", "0,26,1160,76,1124,351,1251,351,1472,100,1288,352,1048,352,5,5,88,48", "" , "36, 184, 30, 184", "3320,1332,3190,1332", "0,26,1472,84,1472,328,1180,328" ], [" -4,-1152,925,1111, 907,-1152,931,1111, 9999,9999,9999,9999, 1823,-1152,932,1111, 9999,9999,867,516", "1500,16,1688,52,1688,272", "924,-1068,1812,-1000,1812,-624,907,-727,930,684,976,-1052,1252,-836,1.5,1.00", "688,72,1300,72,1842,396,1364,260,1364,276,1588,868,1628,804", "1780,128,1888,236,1888,76,1888,368", "0,0,1140,44,1100,272,1212,272,1348,68,1348,240,1088,240", "" , "40,96,32,132", "3320,1332,3190,1332", "0,26,1472,84,1472,328,1180,328" ]] Local $i = getMachineID() Local $sResult = $aGrid[$i][$iTag] Local $aXY = StringSplit($sResult, ",") If $iNum = UBound($aXY) - 1 Then Return SetError(0, "", $aXY) Else Return SetError(3, "", "Array not expected: " & $iNum & " is expected while " & UBound($aXY) & " is returned") EndIf EndFunc Func getMachineID() Local $Machine = EnvGet("Computername") Local $i Select Case $Machine = "TOWER_K330" $i = 0 Case $Machine = "BLUE" $i = 1 Case $Machine = "LG" $i = 2 Case Else EndSelect Return $i EndFunc Func captureTextviaImage($Name, $i, $aXY, $expectvaluearr, $Debug = "No", $OCR = 10, $space = "all") Local $iTimes Local $fullName = @TempDir & "\Image_" & $Name & ".jpg" Do _ScreenCapture_Capture($fullName, $aXY[$i][0], $aXY[$i][1], $aXY[$i][2], $aXY[$i][3], False) Local $iReturn = ShellExecuteWait("C:\Program Files\Capture2Text\Capture2Text_CLI.exe", "-i """ & $fullName & """ --clipboard") If $space = "all" Then Local $captured = StringStripWS(ClipGet(), 8) Else Local $captured = StringStripWS(ClipGet(), 1 + 2 + 4) Endif Local $found = expectedvalue($captured, $expectvaluearr) $iTimes = $iTimes + 1 Until $found[0] > 0 Or $iTimes = $OCR If $Debug = "Yes" Then MsgBox(4096, $Name, $captured & " with length: " & StringLen($captured)) EndIf Return $found EndFunc Func expectedvalue($s, $expectvaluearr) Local $arr[4] Local $idx For $idx = 0 To UBound($expectvaluearr) -1 Step +1 Local $pos = StringInStr($s,$expectvaluearr[$idx], 0) If $pos > 0 Then $arr[0] = 1 $arr[1] = $s $arr[2] = $expectvaluearr[$idx] $arr[3] = $idx return $arr EndIf Next $arr[0] = 0 return $arr EndFunc Func KillWindows() WinKill("Performance problem") WinKill("Performance problem") WinKill("Performance problem") WinKill("Performance problem") WinKill("Performance problem") WinKill("System error") WinKill("System error") WinKill("System error") WinKill("System error") WinKill("System error") Return True EndFunc Func _MouseClick($btn,$x,$y) Local $res = 1 Local $xa = Int($x/$res) Local $ya = Int($y/$res) DllCall("user32.dll", "bool", "SetCursorPos", "int", $xa, "int", $ya) MouseClick($btn) EndFunc Local $Sleep1 = 250 Local $sPath Local $syyyymmddDash TDDefault($sPath, $syyyymmddDash) TDClearSlate($sPath, $syyyymmddDash, "PositionStatement.csv", False) Local $i = getMachineID() Local $aXY = GetXYCoords("MRGMargin", 16) If @error Then MsgBox(4096, Default, "Return value = " & $aXY & @CRLF & "Value of @error is: " & @error & @CRLF & "Value of @extended is: " & @extended) Else Local $sReturn $sReturn = Export() If @error Then SetError(1) Else TDFileExists($sPath & "\" & $syyyymmddDash & "-" & "PositionStatement.csv") SetError(0) EndIf EndIf Func Export() Local $hWndActivity = WinActivate("Activity and Positions -", "") SendKeepActive($hWndActivity) If $i = 2 Then Opt("MouseCoordMode", 1) collapseWorkingOrder($i, "No") Local $rc = _MouseClick("primary", $aXY[3], $aXY[4]) Sleep($Sleep1 * 4) $rc = _MouseClick("primary", $aXY[5], $aXY[6]) Sleep($Sleep1 * 2) Local $sReturn = TDExporttoFile("Position Statement for", $sPath & "\" & $syyyymmddDash & "-" & "PositionStatement.csv", False, 8) Local $sError = @error Else Opt("MouseCoordMode", 1) If StringLower(StringLeft(findText($aXY, 11), 1)) = StringLower("Time Place") Then Local $rc = _MouseClick("primary", $aXY[1], $aXY[2]) EndIf Local $rc = _MouseClick("primary", $aXY[3], $aXY[4]) Sleep($Sleep1 * 4) $rc = _MouseClick("primary", $aXY[5], $aXY[6]) Sleep($Sleep1 * 2) Local $sReturn = TDExporttoFile("Position Statement for", $sPath & "\" & $syyyymmddDash & "-" & "PositionStatement.csv", False, 8) Local $sError = @error EndIf Return SetError($sError, "", $sReturn) EndFunc Func findText($aXY, $beg) Local $screen = $aXY[$beg] & " " & $aXY[$beg + 1] & " " & $aXY[$beg + 2] & " " & $aXY[$beg + 3] ShellExecuteWait("C:\Program Files\Capture2Text\Capture2Text_CLI.exe", "-s """ & $screen & """ --clipboard") Return ClipGet() EndFunc Func collapseWorkingOrder($i,$Debug) Local $aXYWorkingOrder = [[], [], [1085, -1350, 1260, -1290, 924, -1068]] Local $expectvalue = ["vWor", "xWor", ">Wor", ")Wor"] Local $captured = captureTextviaImage("WorkingOrder", $i, $aXYWorkingOrder, $expectvalue, $Debug) If $captured[0] = 1 and $captured[3] < 2 Then _MouseClick("primary",$aXYWorkingOrder[$i][4], $aXYWorkingOrder[$i][5]) If $Debug = "Yes" Then Local $rc = MsgBox(4096+2,"WorkingOrder ", "Found: " & $captured[2]) EndIf Sleep(1000) EndIf Return True EndFunc