diff --git a/src/include/Array.au3 b/src/include/Array.au3 new file mode 100644 index 0000000..1064a0f --- /dev/null +++ b/src/include/Array.au3 @@ -0,0 +1,2616 @@ +#include-Once + +#include "AutoItConstants.au3" +#include "MsgBoxConstants.au3" +#include "StringConstants.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: Array +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions for manipulating arrays. +; Author(s) .....: JdeB, Erik Pilsits, Ultima, Dale (Klaatu) Thompson, Cephas,randallc, Gary Frost, GEOSoft, +; Helias Gerassimou(hgeras), Brian Keene, Michael Michta, gcriaco, LazyCoder, Tylo, David Nuttall, +; Adam Moore (redndahead), SmOke_N, litlmike, Valik, Melba23 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _ArrayAdd +; _ArrayBinarySearch +; _ArrayColDelete +; _ArrayColInsert +; _ArrayCombinations +; _ArrayConcatenate +; _ArrayDelete +; _ArrayDisplay +; _ArrayExtract +; _ArrayFindAll +; _ArrayInsert +; _ArrayMax +; _ArrayMaxIndex +; _ArrayMin +; _ArrayMinIndex +; _ArrayPermute +; _ArrayPop +; _ArrayPush +; _ArrayReverse +; _ArraySearch +; _ArrayShuffle +; _ArraySort +; _ArraySwap +; _ArrayToClip +; _ArrayToString +; _ArrayTranspose +; _ArrayTrim +; _ArrayUnique +; _Array1DToHistogram +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; __Array_Combinations +; __Array_ExeterInternal +; __Array_GetNext +; __Array_GreaterThan +; __Array_LessThan +; __Array_MinMaxIndex +; __Array_StringRepeat +; __ArrayDualPivotSort +; __ArrayQuickSort1D +; __ArrayQuickSort2D +; __ArrayUnique_AutoErrFunc +; =============================================================================================================================== + +; #GLOBAL CONSTANTS# ============================================================================================================ +Global Enum $ARRAYFILL_FORCE_DEFAULT, $ARRAYFILL_FORCE_SINGLEITEM, $ARRAYFILL_FORCE_INT, $ARRAYFILL_FORCE_NUMBER, $ARRAYFILL_FORCE_PTR, $ARRAYFILL_FORCE_HWND, $ARRAYFILL_FORCE_STRING +Global Enum $ARRAYUNIQUE_NOCOUNT, $ARRAYUNIQUE_COUNT +Global Enum $ARRAYUNIQUE_AUTO, $ARRAYUNIQUE_FORCE32, $ARRAYUNIQUE_FORCE64, $ARRAYUNIQUE_MATCH, $ARRAYUNIQUE_DISTINCT +; =============================================================================================================================== + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jos +; Modified.......: Ultima - code cleanup; Melba23 - added 2D support & multiple addition +; =============================================================================================================================== +Func _ArrayAdd(ByRef $aArray, $vValue, $iStart = 0, $sDelim_Item = "|", $sDelim_Row = @CRLF, $iForce = $ARRAYFILL_FORCE_DEFAULT) + + If $iStart = Default Then $iStart = 0 + If $sDelim_Item = Default Then $sDelim_Item = "|" + If $sDelim_Row = Default Then $sDelim_Row = @CRLF + If $iForce = Default Then $iForce = $ARRAYFILL_FORCE_DEFAULT + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) + Local $hDataType = 0 + Switch $iForce + Case $ARRAYFILL_FORCE_INT + $hDataType = Int + Case $ARRAYFILL_FORCE_NUMBER + $hDataType = Number + Case $ARRAYFILL_FORCE_PTR + $hDataType = Ptr + Case $ARRAYFILL_FORCE_HWND + $hDataType = Hwnd + Case $ARRAYFILL_FORCE_STRING + $hDataType = String + EndSwitch + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $iForce = $ARRAYFILL_FORCE_SINGLEITEM Then + ReDim $aArray[$iDim_1 + 1] + $aArray[$iDim_1] = $vValue + Return $iDim_1 + EndIf + If IsArray($vValue) Then + If UBound($vValue, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(5, 0, -1) + $hDataType = 0 + Else + Local $aTmp = StringSplit($vValue, $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT) + If UBound($aTmp, $UBOUND_ROWS) = 1 Then + $aTmp[0] = $vValue + EndIf + $vValue = $aTmp + EndIf + Local $iAdd = UBound($vValue, $UBOUND_ROWS) + ReDim $aArray[$iDim_1 + $iAdd] + For $i = 0 To $iAdd - 1 + If IsFunc($hDataType) Then + $aArray[$iDim_1 + $i] = $hDataType($vValue[$i]) + Else + $aArray[$iDim_1 + $i] = $vValue[$i] + EndIf + Next + Return $iDim_1 + $iAdd - 1 + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) + If $iStart < 0 Or $iStart > $iDim_2 - 1 Then Return SetError(4, 0, -1) + Local $iValDim_1, $iValDim_2 = 0, $iColCount + If IsArray($vValue) Then + If UBound($vValue, $UBOUND_DIMENSIONS) <> 2 Then Return SetError(5, 0, -1) + $iValDim_1 = UBound($vValue, $UBOUND_ROWS) + $iValDim_2 = UBound($vValue, $UBOUND_COLUMNS) + $hDataType = 0 + Else + ; Convert string to 2D array + Local $aSplit_1 = StringSplit($vValue, $sDelim_Row, $STR_NOCOUNT + $STR_ENTIRESPLIT) + $iValDim_1 = UBound($aSplit_1, $UBOUND_ROWS) + Local $aTmp[$iValDim_1][0], $aSplit_2 + For $i = 0 To $iValDim_1 - 1 + $aSplit_2 = StringSplit($aSplit_1[$i], $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT) + $iColCount = UBound($aSplit_2) + If $iColCount > $iValDim_2 Then + ; Increase array size to fit max number of items on line + $iValDim_2 = $iColCount + ReDim $aTmp[$iValDim_1][$iValDim_2] + EndIf + For $j = 0 To $iColCount - 1 + $aTmp[$i][$j] = $aSplit_2[$j] + Next + Next + $vValue = $aTmp + EndIf + ; Check if too many columns to fit + If UBound($vValue, $UBOUND_COLUMNS) + $iStart > UBound($aArray, $UBOUND_COLUMNS) Then Return SetError(3, 0, -1) + ReDim $aArray[$iDim_1 + $iValDim_1][$iDim_2] + For $iWriteTo_Index = 0 To $iValDim_1 - 1 + For $j = 0 To $iDim_2 - 1 + If $j < $iStart Then + $aArray[$iWriteTo_Index + $iDim_1][$j] = "" + ElseIf $j - $iStart > $iValDim_2 - 1 Then + $aArray[$iWriteTo_Index + $iDim_1][$j] = "" + Else + If IsFunc($hDataType) Then + $aArray[$iWriteTo_Index + $iDim_1][$j] = $hDataType($vValue[$iWriteTo_Index][$j - $iStart]) + Else + $aArray[$iWriteTo_Index + $iDim_1][$j] = $vValue[$iWriteTo_Index][$j - $iStart] + EndIf + EndIf + Next + Next + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return UBound($aArray, $UBOUND_ROWS) - 1 + +EndFunc ;==>_ArrayAdd + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jos +; Modified.......: Ultima - added $iEnd as parameter, code cleanup; Melba23 - added support for empty & 2D arrays +; =============================================================================================================================== +Func _ArrayBinarySearch(Const ByRef $aArray, $vValue, $iStart = 0, $iEnd = 0, $iColumn = 0) + + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iColumn = Default Then $iColumn = 0 + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + + ; Bounds checking + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) + If $iDim_1 = 0 Then Return SetError(6, 0, -1) + + If $iEnd < 1 Or $iEnd > $iDim_1 - 1 Then $iEnd = $iDim_1 - 1 + If $iStart < 0 Then $iStart = 0 + If $iStart > $iEnd Then Return SetError(4, 0, -1) + Local $iMid = Int(($iEnd + $iStart) / 2) + + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $aArray[$iStart] > $vValue Or $aArray[$iEnd] < $vValue Then Return SetError(2, 0, -1) + ; Search + While $iStart <= $iMid And $vValue <> $aArray[$iMid] + If $vValue < $aArray[$iMid] Then + $iEnd = $iMid - 1 + Else + $iStart = $iMid + 1 + EndIf + $iMid = Int(($iEnd + $iStart) / 2) + WEnd + If $iStart > $iEnd Then Return SetError(3, 0, -1) ; Entry not found + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iColumn < 0 Or $iColumn > $iDim_2 Then Return SetError(7, 0, -1) + If $aArray[$iStart][$iColumn] > $vValue Or $aArray[$iEnd][$iColumn] < $vValue Then Return SetError(2, 0, -1) + ; Search + While $iStart <= $iMid And $vValue <> $aArray[$iMid][$iColumn] + If $vValue < $aArray[$iMid][$iColumn] Then + $iEnd = $iMid - 1 + Else + $iStart = $iMid + 1 + EndIf + $iMid = Int(($iEnd + $iStart) / 2) + WEnd + If $iStart > $iEnd Then Return SetError(3, 0, -1) ; Entry not found + Case Else + Return SetError(5, 0, -1) + EndSwitch + + Return $iMid +EndFunc ;==>_ArrayBinarySearch + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 +; Modified.......: +; =============================================================================================================================== +Func _ArrayColDelete(ByRef $aArray, $iColumn, $bConvert = False) + + If $bConvert = Default Then $bConvert = False + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) + If UBound($aArray, $UBOUND_DIMENSIONS) <> 2 Then Return SetError(2, 0, -1) + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) + Switch $iDim_2 + Case 2 + If $iColumn < 0 Or $iColumn > 1 Then Return SetError(3, 0, -1) + If $bConvert Then + Local $aTempArray[$iDim_1] + For $i = 0 To $iDim_1 - 1 + $aTempArray[$i] = $aArray[$i][(Not $iColumn)] + Next + $aArray = $aTempArray + Else + ContinueCase + EndIf + Case Else + If $iColumn < 0 Or $iColumn > $iDim_2 - 1 Then Return SetError(3, 0, -1) + For $i = 0 To $iDim_1 - 1 + For $j = $iColumn To $iDim_2 - 2 + $aArray[$i][$j] = $aArray[$i][$j + 1] + Next + Next + ReDim $aArray[$iDim_1][$iDim_2 - 1] + EndSwitch + + Return UBound($aArray, $UBOUND_COLUMNS) +EndFunc ;==>_ArrayColDelete + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 +; Modified.......: +; =============================================================================================================================== +Func _ArrayColInsert(ByRef $aArray, $iColumn) + + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + Local $aTempArray[$iDim_1][2] + Switch $iColumn + Case 0, 1 + For $i = 0 To $iDim_1 - 1 + $aTempArray[$i][(Not $iColumn)] = $aArray[$i] + Next + Case Else + Return SetError(3, 0, -1) + EndSwitch + $aArray = $aTempArray + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) + If $iColumn < 0 Or $iColumn > $iDim_2 Then Return SetError(3, 0, -1) + ReDim $aArray[$iDim_1][$iDim_2 + 1] + For $i = 0 To $iDim_1 - 1 + For $j = $iDim_2 To $iColumn + 1 Step -1 + $aArray[$i][$j] = $aArray[$i][$j - 1] + Next + $aArray[$i][$iColumn] = "" + Next + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return UBound($aArray, $UBOUND_COLUMNS) +EndFunc ;==>_ArrayColInsert + +; #FUNCTION# ==================================================================================================================== +; Author ........: Erik Pilsits +; Modified.......: 07/08/2008 +; =============================================================================================================================== +Func _ArrayCombinations(Const ByRef $aArray, $iSet, $sDelimiter = "") + + If $sDelimiter = Default Then $sDelimiter = "" + If Not IsArray($aArray) Then Return SetError(1, 0, 0) + If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(2, 0, 0) + + Local $iN = UBound($aArray) + Local $iR = $iSet + Local $aIdx[$iR] + For $i = 0 To $iR - 1 + $aIdx[$i] = $i + Next + Local $iTotal = __Array_Combinations($iN, $iR) + Local $iLeft = $iTotal + Local $aResult[$iTotal + 1] + $aResult[0] = $iTotal + + Local $iCount = 1 + While $iLeft > 0 + __Array_GetNext($iN, $iR, $iLeft, $iTotal, $aIdx) + For $i = 0 To $iSet - 1 + $aResult[$iCount] &= $aArray[$aIdx[$i]] & $sDelimiter + Next + If $sDelimiter <> "" Then $aResult[$iCount] = StringTrimRight($aResult[$iCount], 1) + $iCount += 1 + WEnd + Return $aResult +EndFunc ;==>_ArrayCombinations + +; #FUNCTION# ==================================================================================================================== +; Author ........: Ultima +; Modified.......: Partypooper - added target start index; Melba23 - add 2D support +; =============================================================================================================================== +Func _ArrayConcatenate(ByRef $aArrayTarget, Const ByRef $aArraySource, $iStart = 0) + + If $iStart = Default Then $iStart = 0 + If Not IsArray($aArrayTarget) Then Return SetError(1, 0, -1) + If Not IsArray($aArraySource) Then Return SetError(2, 0, -1) + Local $iDim_Total_Tgt = UBound($aArrayTarget, $UBOUND_DIMENSIONS) + Local $iDim_Total_Src = UBound($aArraySource, $UBOUND_DIMENSIONS) + Local $iDim_1_Tgt = UBound($aArrayTarget, $UBOUND_ROWS) + Local $iDim_1_Src = UBound($aArraySource, $UBOUND_ROWS) + If $iStart < 0 Or $iStart > $iDim_1_Src - 1 Then Return SetError(6, 0, -1) + Switch $iDim_Total_Tgt + Case 1 + If $iDim_Total_Src <> 1 Then Return SetError(4, 0, -1) + ReDim $aArrayTarget[$iDim_1_Tgt + $iDim_1_Src - $iStart] + For $i = $iStart To $iDim_1_Src - 1 + $aArrayTarget[$iDim_1_Tgt + $i - $iStart] = $aArraySource[$i] + Next + Case 2 + If $iDim_Total_Src <> 2 Then Return SetError(4, 0, -1) + Local $iDim_2_Tgt = UBound($aArrayTarget, $UBOUND_COLUMNS) + If UBound($aArraySource, $UBOUND_COLUMNS) <> $iDim_2_Tgt Then Return SetError(5, 0, -1) + ReDim $aArrayTarget[$iDim_1_Tgt + $iDim_1_Src - $iStart][$iDim_2_Tgt] + For $i = $iStart To $iDim_1_Src - 1 + For $j = 0 To $iDim_2_Tgt - 1 + $aArrayTarget[$iDim_1_Tgt + $i - $iStart][$j] = $aArraySource[$i][$j] + Next + Next + Case Else + Return SetError(3, 0, -1) + EndSwitch + Return UBound($aArrayTarget, $UBOUND_ROWS) +EndFunc ;==>_ArrayConcatenate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - array passed ByRef, jaberwocky6669, Melba23 - added 2D support & multiple deletion +; =============================================================================================================================== +Func _ArrayDelete(ByRef $aArray, $vRange) + + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + If IsArray($vRange) Then + If UBound($vRange, $UBOUND_DIMENSIONS) <> 1 Or UBound($vRange, $UBOUND_ROWS) < 2 Then Return SetError(4, 0, -1) + Else + ; Expand range + Local $iNumber, $aSplit_1, $aSplit_2 + $vRange = StringStripWS($vRange, 8) + $aSplit_1 = StringSplit($vRange, ";") + $vRange = "" + For $i = 1 To $aSplit_1[0] + ; Check for correct range syntax + If Not StringRegExp($aSplit_1[$i], "^\d+(-\d+)?$") Then Return SetError(3, 0, -1) + $aSplit_2 = StringSplit($aSplit_1[$i], "-") + Switch $aSplit_2[0] + Case 1 + $vRange &= $aSplit_2[1] & ";" + Case 2 + If Number($aSplit_2[2]) >= Number($aSplit_2[1]) Then + $iNumber = $aSplit_2[1] - 1 + Do + $iNumber += 1 + $vRange &= $iNumber & ";" + Until $iNumber = $aSplit_2[2] + EndIf + EndSwitch + Next + $vRange = StringSplit(StringTrimRight($vRange, 1), ";") + EndIf + If $vRange[1] < 0 Or $vRange[$vRange[0]] > $iDim_1 Then Return SetError(5, 0, -1) + ; Remove rows + Local $iCopyTo_Index = 0 + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + ; Loop through array flagging elements to be deleted + For $i = 1 To $vRange[0] + $aArray[$vRange[$i]] = ChrW(0xFAB1) + Next + ; Now copy rows to keep to fill deleted rows + For $iReadFrom_Index = 0 To $iDim_1 + If $aArray[$iReadFrom_Index] == ChrW(0xFAB1) Then + ContinueLoop + Else + If $iReadFrom_Index <> $iCopyTo_Index Then + $aArray[$iCopyTo_Index] = $aArray[$iReadFrom_Index] + EndIf + $iCopyTo_Index += 1 + EndIf + Next + ReDim $aArray[$iDim_1 - $vRange[0] + 1] + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + ; Loop through array flagging elements to be deleted + For $i = 1 To $vRange[0] + $aArray[$vRange[$i]][0] = ChrW(0xFAB1) + Next + ; Now copy rows to keep to fill deleted rows + For $iReadFrom_Index = 0 To $iDim_1 + If $aArray[$iReadFrom_Index][0] == ChrW(0xFAB1) Then + ContinueLoop + Else + If $iReadFrom_Index <> $iCopyTo_Index Then + For $j = 0 To $iDim_2 + $aArray[$iCopyTo_Index][$j] = $aArray[$iReadFrom_Index][$j] + Next + EndIf + $iCopyTo_Index += 1 + EndIf + Next + ReDim $aArray[$iDim_1 - $vRange[0] + 1][$iDim_2 + 1] + Case Else + Return SetError(2, 0, False) + EndSwitch + + Return UBound($aArray, $UBOUND_ROWS) + +EndFunc ;==>_ArrayDelete + +; #FUNCTION# ==================================================================================================================== +; Author ........: randallc, Ultima +; Modified.......: Gary Frost (gafrost), Ultima, Zedna, jpm, Melba23, AZJIO, UEZ +; =============================================================================================================================== +Func _ArrayDisplay(Const ByRef $aArray, $sTitle = Default, $sArrayRange = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $iAlt_Color = Default, $hUser_Function = Default) + + ; Default values + If $sTitle = Default Then $sTitle = "ArrayDisplay" + If $sArrayRange = Default Then $sArrayRange = "" + If $iFlags = Default Then $iFlags = 0 + If $vUser_Separator = Default Then $vUser_Separator = "" + If $sHeader = Default Then $sHeader = "" + If $iMax_ColWidth = Default Then $iMax_ColWidth = 350 + If $iAlt_Color = Default Then $iAlt_Color = 0 + If $hUser_Function = Default Then $hUser_Function = 0 + + ; Check for transpose, column align, verbosity and button and "Row" column visibility + Local $iTranspose = BitAND($iFlags, 1) + Local $iColAlign = BitAND($iFlags, 6) ; 0 = Left (default); 2 = Right; 4 = Center + Local $iVerbose = BitAND($iFlags, 8) + Local $iButtonMargin = ((BitAND($iFlags, 32)) ? (0) : ((BitAND($iFlags, 16)) ? (20) : (40))) ; Flag 32 = 0; flag 16 = 20; neither flag = 40 + Local $iNoRow = BitAND($iFlags, 64) + + ; Check valid array + Local $sMsg = "", $iRet = 1 + If IsArray($aArray) Then + ; Dimension checking + Local $iDimension = UBound($aArray, $UBOUND_DIMENSIONS), $iRowCount = UBound($aArray, $UBOUND_ROWS), $iColCount = UBound($aArray, $UBOUND_COLUMNS) + If $iDimension > 2 Then + $sMsg = "Larger than 2D array passed to function" + $iRet = 2 + EndIf + Else + $sMsg = "No array variable passed to function" + EndIf + If $sMsg Then + If $iVerbose And MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR + $MB_YESNO, _ + "ArrayDisplay Error: " & $sTitle, $sMsg & @CRLF & @CRLF & "Exit the script?") = $IDYES Then + Exit + Else + Return SetError($iRet, 0, "") + EndIf + EndIf + + ; Determine copy separator + Local $iCW_ColWidth = Number($vUser_Separator) + + ; Separator handling + Local $sAD_Separator = ChrW(0xFAB1) + ; Set separator to use in this UDF and store existing one + Local $sCurr_Separator = Opt("GUIDataSeparatorChar", $sAD_Separator) + ; Set default user separator if required + If $vUser_Separator = "" Then $vUser_Separator = $sCurr_Separator + + ; Declare variables + Local $vTmp, $iRowLimit = 65525, $iColLimit = 250 ; Row = AutoIt 64k limit minus UDF controls; Column - arbitrary limit + + ; Set original dimensions for data display + Local $iDataRow = $iRowCount + Local $iDataCol = $iColCount + + ; Set display limits for dimensions - column value only set for 2D arrays + Local $iItem_Start = 0, $iItem_End = $iRowCount - 1, $iSubItem_Start = 0, $iSubItem_End = (($iDimension = 2) ? ($iColCount - 1) : (0)) + ; Flag to determine if range set + Local $bRange_Flag = False, $avRangeSplit + ; Check for range settings + If $sArrayRange Then + ; Split into separate dimension sections + Local $aArray_Range = StringRegExp($sArrayRange & "||", "(?U)(.*)\|", 3) + ; Dimension 1 + If $aArray_Range[0] Then + $avRangeSplit = StringSplit($aArray_Range[0], ":") + If @error Then + $iItem_End = Number($avRangeSplit[1]) + Else + $iItem_Start = Number($avRangeSplit[1]) + $iItem_End = Number($avRangeSplit[2]) + EndIf + EndIf + ; Check row bounds + If $iItem_Start > $iItem_End Then + $vTmp = $iItem_Start + $iItem_Start = $iItem_End + $iItem_End = $vTmp + EndIf + If $iItem_Start < 0 Then $iItem_Start = 0 + If $iItem_End > $iRowCount - 1 Then $iItem_End = $iRowCount - 1 + ; Check if range set + If $iItem_Start <> 0 Or $iItem_End <> $iRowCount - 1 Then $bRange_Flag = True + ; Dimension 2 + If $iDimension = 2 And $aArray_Range[1] Then + $avRangeSplit = StringSplit($aArray_Range[1], ":") + If @error Then + $iSubItem_End = Number($avRangeSplit[1]) + Else + $iSubItem_Start = Number($avRangeSplit[1]) + $iSubItem_End = Number($avRangeSplit[2]) + EndIf + ; Check column bounds + If $iSubItem_Start > $iSubItem_End Then + $vTmp = $iSubItem_Start + $iSubItem_Start = $iSubItem_End + $iSubItem_End = $vTmp + EndIf + If $iSubItem_Start < 0 Then $iSubItem_Start = 0 + If $iSubItem_End > $iColCount - 1 Then $iSubItem_End = $iColCount - 1 + ; Check if range set + If $iSubItem_Start <> 0 Or $iSubItem_End <> $iColCount - 1 Then $bRange_Flag = True + EndIf + EndIf + + ; Create data display + Local $sDisplayData = "[" & $iDataRow + ; Check if rows will be truncated + Local $bTruncated = False + If $iTranspose Then + If $iItem_End - $iItem_Start > $iColLimit Then + $bTruncated = True + $iItem_End = $iItem_Start + $iColLimit - 1 + EndIf + Else + If $iItem_End - $iItem_Start > $iRowLimit Then + $bTruncated = True + $iItem_End = $iItem_Start + $iRowLimit - 1 + EndIf + EndIf + If $bTruncated Then + $sDisplayData &= "*]" + Else + $sDisplayData &= "]" + EndIf + If $iDimension = 2 Then + $sDisplayData &= " [" & $iDataCol + If $iTranspose Then + If $iSubItem_End - $iSubItem_Start > $iRowLimit Then + $bTruncated = True + $iSubItem_End = $iSubItem_Start + $iRowLimit - 1 + EndIf + Else + If $iSubItem_End - $iSubItem_Start > $iColLimit Then + $bTruncated = True + $iSubItem_End = $iSubItem_Start + $iColLimit - 1 + EndIf + EndIf + If $bTruncated Then + $sDisplayData &= "*]" + Else + $sDisplayData &= "]" + EndIf + EndIf + ; Create tooltip data + Local $sTipData = "" + If $bTruncated Then $sTipData &= "Truncated" + If $bRange_Flag Then + If $sTipData Then $sTipData &= " - " + $sTipData &= "Range set" + EndIf + If $iTranspose Then + If $sTipData Then $sTipData &= " - " + $sTipData &= "Transposed" + EndIf + + ; Split custom header on separator + Local $asHeader = StringSplit($sHeader, $sCurr_Separator, $STR_NOCOUNT) ; No count element + If UBound($asHeader) = 0 Then Local $asHeader[1] = [""] + $sHeader = "Row" + Local $iIndex = $iSubItem_Start + If $iTranspose Then + ; All default headers + For $j = $iItem_Start To $iItem_End + $sHeader &= $sAD_Separator & "Col " & $j + Next + Else + ; Create custom header with available items + If $asHeader[0] Then + ; Set as many as available + For $iIndex = $iSubItem_Start To $iSubItem_End + ; Check custom header available + If $iIndex >= UBound($asHeader) Then ExitLoop + $sHeader &= $sAD_Separator & $asHeader[$iIndex] + Next + EndIf + ; Add default headers to fill to end + For $j = $iIndex To $iSubItem_End + $sHeader &= $sAD_Separator & "Col " & $j + Next + EndIf + ; Remove "Row" header if not needed + If $iNoRow Then $sHeader = StringTrimLeft($sHeader, 4) + + ; Display splash dialog if required + If $iVerbose And ($iItem_End - $iItem_Start + 1) * ($iSubItem_End - $iSubItem_Start + 1) > 10000 Then + SplashTextOn("ArrayDisplay", "Preparing display" & @CRLF & @CRLF & "Please be patient", 300, 100) + EndIf + + ; Convert array into ListViewItem compatible lines + Local $iBuffer = 4094 ; Max characters a ListView will display (Windows limitation) + If $iTranspose Then + ; Swap dimensions + $vTmp = $iItem_Start + $iItem_Start = $iSubItem_Start + $iSubItem_Start = $vTmp + $vTmp = $iItem_End + $iItem_End = $iSubItem_End + $iSubItem_End = $vTmp + EndIf + Local $avArrayText[$iItem_End - $iItem_Start + 1] + For $i = $iItem_Start To $iItem_End + ; Add row number if required + If Not $iNoRow Then $avArrayText[$i - $iItem_Start] = "[" & $i & "]" + For $j = $iSubItem_Start To $iSubItem_End + If $iDimension = 1 Then + If $iTranspose Then + Switch VarGetType($aArray[$j]) + Case "Array" + $vTmp = "{Array}" + Case Else + $vTmp = $aArray[$j] + EndSwitch + Else + Switch VarGetType($aArray[$i]) + Case "Array" + $vTmp = "{Array}" + Case Else + $vTmp = $aArray[$i] + EndSwitch + EndIf + Else + If $iTranspose Then + Switch VarGetType($aArray[$j][$i]) + Case "Array" + $vTmp = "{Array}" + Case Else + $vTmp = $aArray[$j][$i] + EndSwitch + Else + Switch VarGetType($aArray[$i][$j]) + Case "Array" + $vTmp = "{Array}" + Case Else + $vTmp = $aArray[$i][$j] + EndSwitch + EndIf + EndIf + ; Truncate if required so ListView will display + If StringLen($vTmp) > $iBuffer Then $vTmp = StringLeft($vTmp, $iBuffer) + $avArrayText[$i - $iItem_Start] &= $sAD_Separator & $vTmp + Next + ; Remove leading delimiter if no "Row" column + If $iNoRow Then $avArrayText[$i - $iItem_Start] = StringTrimLeft($avArrayText[$i - $iItem_Start], 1) + Next + + ; GUI Constants + Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 64 + Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 102 + Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 512 + Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 2 + Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 4 + Local Const $_ARRAYCONSTANT_GUI_DOCKHCENTER = 8 + Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3 + Local Const $_ARRAYCONSTANT_GUI_FOCUS = 256 + Local Const $_ARRAYCONSTANT_GUI_BKCOLOR_LV_ALTERNATE = 0xFE000000 + Local Const $_ARRAYCONSTANT_SS_CENTER = 0x1 + Local Const $_ARRAYCONSTANT_SS_CENTERIMAGE = 0x0200 + Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4) + Local Const $_ARRAYCONSTANT_LVM_GETITEMRECT = (0x1000 + 14) + Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29) + Local Const $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH = (0x1000 + 30) + Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44) + Local Const $_ARRAYCONSTANT_LVM_GETSELECTEDCOUNT = (0x1000 + 50) + Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54) + Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1 + Local Const $_ARRAYCONSTANT_LVIS_SELECTED = 0x2 + Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8 + Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20 + Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200 + Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000 + Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000 + Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000 + Local Const $_ARRAYCONSTANT_WM_SETREDRAW = 11 + Local Const $_ARRAYCONSTANT_LVSCW_AUTOSIZE = -1 + + ; Set coord mode 1 + Local $iCoordMode = Opt("GUICoordMode", 1) + + ; Create GUI + Local $iOrgWidth = 210, $iHeight = 200, $iMinSize = 250 + Local $hGUI = GUICreate($sTitle, $iOrgWidth, $iHeight, Default, Default, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX)) + Local $aiGUISize = WinGetClientSize($hGUI) + Local $iButtonWidth_2 = $aiGUISize[0] / 2 + Local $iButtonWidth_3 = $aiGUISize[0] / 3 + ; Create ListView + Local $idListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - $iButtonMargin, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS) + GUICtrlSetBkColor($idListView, $_ARRAYCONSTANT_GUI_BKCOLOR_LV_ALTERNATE) + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES) + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT) + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE) + Local $idCopy_ID = 9999, $idCopy_Data = 99999, $idData_Label = 99999, $idUser_Func = 99999, $idExit_Script = 99999 + ; Check if any buttons required + If $iButtonMargin Then + ; Create Copy buttons + $idCopy_ID = GUICtrlCreateButton("Copy Data && Hdr/Row", 0, $aiGUISize[1] - $iButtonMargin, $iButtonWidth_2, 20) + $idCopy_Data = GUICtrlCreateButton("Copy Data Only", $iButtonWidth_2, $aiGUISize[1] - $iButtonMargin, $iButtonWidth_2, 20) + ; Check if other buttons are required + If $iButtonMargin = 40 Then + Local $iButtonWidth_Var = $iButtonWidth_2 + Local $iOffset = $iButtonWidth_2 + If IsFunc($hUser_Function) Then + ; Create UserFunc button if function passed + $idUser_Func = GUICtrlCreateButton("Run User Func", $iButtonWidth_3, $aiGUISize[1] - 20, $iButtonWidth_3, 20) + $iButtonWidth_Var = $iButtonWidth_3 + $iOffset = $iButtonWidth_3 * 2 + EndIf + ; Create Exit button and data label + $idExit_Script = GUICtrlCreateButton("Exit Script", $iOffset, $aiGUISize[1] - 20, $iButtonWidth_Var, 20) + $idData_Label = GUICtrlCreateLabel($sDisplayData, 0, $aiGUISize[1] - 20, $iButtonWidth_Var, 18, BitOR($_ARRAYCONSTANT_SS_CENTER, $_ARRAYCONSTANT_SS_CENTERIMAGE)) + ; Change label colour and create tooltip if required + Select + Case $bTruncated Or $iTranspose Or $bRange_Flag + GUICtrlSetColor($idData_Label, 0xFF0000) + GUICtrlSetTip($idData_Label, $sTipData) + EndSelect + EndIf + EndIf + ; Set resizing + GUICtrlSetResizing($idListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS) + GUICtrlSetResizing($idCopy_ID, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) + GUICtrlSetResizing($idCopy_Data, $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) + GUICtrlSetResizing($idData_Label, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) + GUICtrlSetResizing($idUser_Func, $_ARRAYCONSTANT_GUI_DOCKHCENTER + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) + GUICtrlSetResizing($idExit_Script, $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) + + ; Start ListView update + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_WM_SETREDRAW, 0, 0) + + ; Fill listview + Local $idItem + For $i = 0 To UBound($avArrayText) - 1 + $idItem = GUICtrlCreateListViewItem($avArrayText[$i], $idListView) + If $iAlt_Color Then + GUICtrlSetBkColor($idItem, $iAlt_Color) + EndIf + Next + + ; Align columns if required - $iColAlign = 2 for Right and 4 for Center + If $iColAlign Then + Local Const $_ARRAYCONSTANT_LVCF_FMT = 0x01 + Local Const $_ARRAYCONSTANT_LVM_SETCOLUMNW = (0x1000 + 96) + Local $tColumn = DllStructCreate("uint Mask;int Fmt;int CX;ptr Text;int TextMax;int SubItem;int Image;int Order;int cxMin;int cxDefault;int cxIdeal") + DllStructSetData($tColumn, "Mask", $_ARRAYCONSTANT_LVCF_FMT) + DllStructSetData($tColumn, "Fmt", $iColAlign / 2) ; Left = 0; Right = 1; Center = 2 + Local $pColumn = DllStructGetPtr($tColumn) + ; Loop through columns + For $i = 1 To $iSubItem_End - $iSubItem_Start + 1 + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETCOLUMNW, $i, $pColumn) + Next + EndIf + + ; End ListView update + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_WM_SETREDRAW, 1, 0) + + ; Allow for borders with and without vertical scrollbar + Local $iBorder = 45 + If UBound($avArrayText) > 20 Then + $iBorder += 20 + EndIf + ; Adjust dialog width + Local $iWidth = $iBorder, $iColWidth = 0, $aiColWidth[$iSubItem_End - $iSubItem_Start + 2], $iMin_ColWidth = 55 + ; Get required column widths to fit items + For $i = 0 To $iSubItem_End - $iSubItem_Start + 1 + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $_ARRAYCONSTANT_LVSCW_AUTOSIZE) + $iColWidth = GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0) + ; Set minimum if required + If $iColWidth < $iMin_ColWidth Then + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $iMin_ColWidth) + $iColWidth = $iMin_ColWidth + EndIf + ; Add to total width + $iWidth += $iColWidth + ; Store value + $aiColWidth[$i] = $iColWidth + Next + ; Reduce width if no "Row" colukm + If $iNoRow Then $iWidth -= 55 + ; Now check max size + If $iWidth > @DesktopWidth - 100 Then + ; Apply max col width limit to reduce width + $iWidth = $iBorder + For $i = 0 To $iSubItem_End - $iSubItem_Start + 1 + If $aiColWidth[$i] > $iMax_ColWidth Then + ; Reset width + GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $iMax_ColWidth) + $iWidth += $iMax_ColWidth + Else + ; Retain width + $iWidth += $aiColWidth[$i] + EndIf + Next + EndIf + ; Check max/min width + If $iWidth > @DesktopWidth - 100 Then + $iWidth = @DesktopWidth - 100 + ElseIf $iWidth < $iMinSize Then + $iWidth = $iMinSize + EndIf + + ; Get row height + Local $tRECT = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct") ; $tagRECT + DllCall("user32.dll", "struct*", "SendMessageW", "hwnd", GUICtrlGetHandle($idListView), "uint", $_ARRAYCONSTANT_LVM_GETITEMRECT, "wparam", 0, "struct*", $tRECT) + ; Set required GUI height + Local $aiWin_Pos = WinGetPos($hGUI) + Local $aiLV_Pos = ControlGetPos($hGUI, "", $idListView) + $iHeight = ((UBound($avArrayText) + 2) * (DllStructGetData($tRECT, "Bottom") - DllStructGetData($tRECT, "Top"))) + $aiWin_Pos[3] - $aiLV_Pos[3] + ; Check min/max height + If $iHeight > @DesktopHeight - 100 Then + $iHeight = @DesktopHeight - 100 + ElseIf $iHeight < $iMinSize Then + $iHeight = $iMinSize + EndIf + + If $iVerbose Then SplashOff() + + ; Display and resize dialog + GUISetState(@SW_HIDE, $hGUI) + WinMove($hGUI, "", (@DesktopWidth - $iWidth) / 2, (@DesktopHeight - $iHeight) / 2, $iWidth, $iHeight) + GUISetState(@SW_SHOW, $hGUI) + + ; Switch to GetMessage mode + Local $iOnEventMode = Opt("GUIOnEventMode", 0), $iMsg + + While 1 + + $iMsg = GUIGetMsg() ; Variable needed to check which "Copy" button was pressed + Switch $iMsg + Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE + ExitLoop + + Case $idCopy_ID, $idCopy_Data + ; Count selected rows + Local $iSel_Count = GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_GETSELECTEDCOUNT, 0, 0) + ; Display splash dialog if required + If $iVerbose And (Not $iSel_Count) And ($iItem_End - $iItem_Start) * ($iSubItem_End - $iSubItem_Start) > 10000 Then + SplashTextOn("ArrayDisplay", "Copying data" & @CRLF & @CRLF & "Please be patient", 300, 100) + EndIf + ; Generate clipboard text + Local $sClip = "", $sItem, $aSplit + ; Add items + For $i = 0 To $iItem_End - $iItem_Start + ; Skip if copying selected rows and item not selected + If $iSel_Count And Not (GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, $_ARRAYCONSTANT_LVIS_SELECTED)) Then + ContinueLoop + EndIf + $sItem = $avArrayText[$i] + If $iMsg = $idCopy_Data Then + ; Remove row ID if required + $sItem = StringRegExpReplace($sItem, "^\[\d+\].(.*)$", "$1") + EndIf + If $iCW_ColWidth Then + ; Expand columns + $aSplit = StringSplit($sItem, $sAD_Separator) + $sItem = "" + For $j = 1 To $aSplit[0] + $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) + Next + Else + ; Use defined separator + $sItem = StringReplace($sItem, $sAD_Separator, $vUser_Separator) + EndIf + $sClip &= $sItem & @CRLF + Next + ; Add header line if required + If $iMsg = $idCopy_ID Then + If $iCW_ColWidth Then + $aSplit = StringSplit($sHeader, $sAD_Separator) + $sItem = "" + For $j = 1 To $aSplit[0] + $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) + Next + Else + $sItem = StringReplace($sHeader, $sAD_Separator, $vUser_Separator) + EndIf + $sClip = $sItem & @CRLF & $sClip + EndIf + ;Send to clipboard + ClipPut($sClip) + ; Remove splash if used + SplashOff() + ; Refocus ListView + GUICtrlSetState($idListView, $_ARRAYCONSTANT_GUI_FOCUS) + + Case $idUser_Func + ; Get selected indices + Local $aiSelItems[$iRowLimit] = [0] + For $i = 0 To GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0) + If GUICtrlSendMsg($idListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, $_ARRAYCONSTANT_LVIS_SELECTED) Then + $aiSelItems[0] += 1 + $aiSelItems[$aiSelItems[0]] = $i + $iItem_Start + EndIf + Next + ReDim $aiSelItems[$aiSelItems[0] + 1] + ; Pass array and selection to user function + $hUser_Function($aArray, $aiSelItems) + GUICtrlSetState($idListView, $_ARRAYCONSTANT_GUI_FOCUS) + + Case $idExit_Script + ; Clear up + GUIDelete($hGUI) + Exit + EndSwitch + WEnd + + ; Clear up + GUIDelete($hGUI) + Opt("GUICoordMode", $iCoordMode) ; Reset original Coord mode + Opt("GUIOnEventMode", $iOnEventMode) ; Reset original GUI mode + Opt("GUIDataSeparatorChar", $sCurr_Separator) ; Reset original separator + + Return 1 + +EndFunc ;==>_ArrayDisplay + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 +; Modified.......: +; =============================================================================================================================== +Func _ArrayExtract(Const ByRef $aArray, $iStart_Row = -1, $iEnd_Row = -1, $iStart_Col = -1, $iEnd_Col = -1) + + If $iStart_Row = Default Then $iStart_Row = -1 + If $iEnd_Row = Default Then $iEnd_Row = -1 + If $iStart_Col = Default Then $iStart_Col = -1 + If $iEnd_Col = Default Then $iEnd_Col = -1 + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + If $iEnd_Row = -1 Then $iEnd_Row = $iDim_1 + If $iStart_Row = -1 Then $iStart_Row = 0 + If $iStart_Row < -1 Or $iEnd_Row < -1 Then Return SetError(3, 0, -1) + If $iStart_Row > $iDim_1 Or $iEnd_Row > $iDim_1 Then Return SetError(3, 0, -1) + If $iStart_Row > $iEnd_Row Then Return SetError(4, 0, -1) + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + Local $aRetArray[$iEnd_Row - $iStart_Row + 1] + For $i = 0 To $iEnd_Row - $iStart_Row + $aRetArray[$i] = $aArray[$i + $iStart_Row] + Next + Return $aRetArray + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iEnd_Col = -1 Then $iEnd_Col = $iDim_2 + If $iStart_Col = -1 Then $iStart_Col = 0 + If $iStart_Col < -1 Or $iEnd_Col < -1 Then Return SetError(5, 0, -1) + If $iStart_Col > $iDim_2 Or $iEnd_Col > $iDim_2 Then Return SetError(5, 0, -1) + If $iStart_Col > $iEnd_Col Then Return SetError(6, 0, -1) + If $iStart_Col = $iEnd_Col Then + Local $aRetArray[$iEnd_Row - $iStart_Row + 1] + Else + Local $aRetArray[$iEnd_Row - $iStart_Row + 1][$iEnd_Col - $iStart_Col + 1] + EndIf + For $i = 0 To $iEnd_Row - $iStart_Row + For $j = 0 To $iEnd_Col - $iStart_Col + If $iStart_Col = $iEnd_Col Then + $aRetArray[$i] = $aArray[$i + $iStart_Row][$j + $iStart_Col] + Else + $aRetArray[$i][$j] = $aArray[$i + $iStart_Row][$j + $iStart_Col] + EndIf + Next + Next + Return $aRetArray + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return 1 + +EndFunc ;==>_ArrayExtract + +; #FUNCTION# ==================================================================================================================== +; Author ........: GEOSoft, Ultima +; Modified.......: +; =============================================================================================================================== +Func _ArrayFindAll(Const ByRef $aArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iSubItem = 0, $bRow = False) + + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iCase = Default Then $iCase = 0 + If $iCompare = Default Then $iCompare = 0 + If $iSubItem = Default Then $iSubItem = 0 + If $bRow = Default Then $bRow = False + + $iStart = _ArraySearch($aArray, $vValue, $iStart, $iEnd, $iCase, $iCompare, 1, $iSubItem, $bRow) + If @error Then Return SetError(@error, 0, -1) + + Local $iIndex = 0, $avResult[UBound($aArray, ($bRow ? $UBOUND_COLUMNS : $UBOUND_ROWS))] ; Set dimension for Column/Row + Do + $avResult[$iIndex] = $iStart + $iIndex += 1 + $iStart = _ArraySearch($aArray, $vValue, $iStart + 1, $iEnd, $iCase, $iCompare, 1, $iSubItem, $bRow) + Until @error + + ReDim $avResult[$iIndex] + Return $avResult +EndFunc ;==>_ArrayFindAll + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jos +; Modified.......: Ultima - code cleanup; Melba23 - element position check, 2D support & multiple insertions +; =============================================================================================================================== +Func _ArrayInsert(ByRef $aArray, $vRange, $vValue = "", $iStart = 0, $sDelim_Item = "|", $sDelim_Row = @CRLF, $iForce = $ARRAYFILL_FORCE_DEFAULT) + + If $vValue = Default Then $vValue = "" + If $iStart = Default Then $iStart = 0 + If $sDelim_Item = Default Then $sDelim_Item = "|" + If $sDelim_Row = Default Then $sDelim_Row = @CRLF + If $iForce = Default Then $iForce = $ARRAYFILL_FORCE_DEFAULT + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + Local $hDataType = 0 + Switch $iForce + Case $ARRAYFILL_FORCE_INT + $hDataType = Int + Case $ARRAYFILL_FORCE_NUMBER + $hDataType = Number + Case $ARRAYFILL_FORCE_PTR + $hDataType = Ptr + Case $ARRAYFILL_FORCE_HWND + $hDataType = Hwnd + Case $ARRAYFILL_FORCE_STRING + $hDataType = String + EndSwitch + Local $aSplit_1, $aSplit_2 + If IsArray($vRange) Then + If UBound($vRange, $UBOUND_DIMENSIONS) <> 1 Or UBound($vRange, $UBOUND_ROWS) < 2 Then Return SetError(4, 0, -1) + Else + ; Expand range + Local $iNumber + $vRange = StringStripWS($vRange, 8) + $aSplit_1 = StringSplit($vRange, ";") + $vRange = "" + For $i = 1 To $aSplit_1[0] + ; Check for correct range syntax + If Not StringRegExp($aSplit_1[$i], "^\d+(-\d+)?$") Then Return SetError(3, 0, -1) + $aSplit_2 = StringSplit($aSplit_1[$i], "-") + Switch $aSplit_2[0] + Case 1 + $vRange &= $aSplit_2[1] & ";" + Case 2 + If Number($aSplit_2[2]) >= Number($aSplit_2[1]) Then + $iNumber = $aSplit_2[1] - 1 + Do + $iNumber += 1 + $vRange &= $iNumber & ";" + Until $iNumber = $aSplit_2[2] + EndIf + EndSwitch + Next + $vRange = StringSplit(StringTrimRight($vRange, 1), ";") + EndIf + If $vRange[1] < 0 Or $vRange[$vRange[0]] > $iDim_1 Then Return SetError(5, 0, -1) + For $i = 2 To $vRange[0] + If $vRange[$i] < $vRange[$i - 1] Then Return SetError(3, 0, -1) + Next + Local $iCopyTo_Index = $iDim_1 + $vRange[0] + Local $iInsertPoint_Index = $vRange[0] + ; Get lowest insert point + Local $iInsert_Index = $vRange[$iInsertPoint_Index] + ; Insert lines + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $iForce = $ARRAYFILL_FORCE_SINGLEITEM Then + ReDim $aArray[$iDim_1 + $vRange[0] + 1] + For $iReadFromIndex = $iDim_1 To 0 Step -1 + ; Copy existing elements + $aArray[$iCopyTo_Index] = $aArray[$iReadFromIndex] + ; Move up array + $iCopyTo_Index -= 1 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + While $iReadFromIndex = $iInsert_Index + ; Insert new item + $aArray[$iCopyTo_Index] = $vValue + ; Move up array + $iCopyTo_Index -= 1 + ; Reset insert index + $iInsertPoint_Index -= 1 + If $iInsertPoint_Index < 1 Then ExitLoop 2 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + WEnd + Next + Return $iDim_1 + $vRange[0] + 1 + EndIf + ReDim $aArray[$iDim_1 + $vRange[0] + 1] + If IsArray($vValue) Then + If UBound($vValue, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(5, 0, -1) + $hDataType = 0 + Else + Local $aTmp = StringSplit($vValue, $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT) + If UBound($aTmp, $UBOUND_ROWS) = 1 Then + $aTmp[0] = $vValue + $hDataType = 0 + EndIf + $vValue = $aTmp + EndIf + For $iReadFromIndex = $iDim_1 To 0 Step -1 + ; Copy existing elements + $aArray[$iCopyTo_Index] = $aArray[$iReadFromIndex] + ; Move up array + $iCopyTo_Index -= 1 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + While $iReadFromIndex = $iInsert_Index + ; Insert new item + If $iInsertPoint_Index <= UBound($vValue, $UBOUND_ROWS) Then + If IsFunc($hDataType) Then + $aArray[$iCopyTo_Index] = $hDataType($vValue[$iInsertPoint_Index - 1]) + Else + $aArray[$iCopyTo_Index] = $vValue[$iInsertPoint_Index - 1] + EndIf + Else + $aArray[$iCopyTo_Index] = "" + EndIf + ; Move up array + $iCopyTo_Index -= 1 + ; Reset insert index + $iInsertPoint_Index -= 1 + If $iInsertPoint_Index = 0 Then ExitLoop 2 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + WEnd + Next + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) + If $iStart < 0 Or $iStart > $iDim_2 - 1 Then Return SetError(6, 0, -1) + Local $iValDim_1, $iValDim_2 + If IsArray($vValue) Then + If UBound($vValue, $UBOUND_DIMENSIONS) <> 2 Then Return SetError(7, 0, -1) + $iValDim_1 = UBound($vValue, $UBOUND_ROWS) + $iValDim_2 = UBound($vValue, $UBOUND_COLUMNS) + $hDataType = 0 + Else + ; Convert string to 2D array + $aSplit_1 = StringSplit($vValue, $sDelim_Row, $STR_NOCOUNT + $STR_ENTIRESPLIT) + $iValDim_1 = UBound($aSplit_1, $UBOUND_ROWS) + StringReplace($aSplit_1[0], $sDelim_Item, "") + $iValDim_2 = @extended + 1 + Local $aTmp[$iValDim_1][$iValDim_2] + For $i = 0 To $iValDim_1 - 1 + $aSplit_2 = StringSplit($aSplit_1[$i], $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT) + For $j = 0 To $iValDim_2 - 1 + $aTmp[$i][$j] = $aSplit_2[$j] + Next + Next + $vValue = $aTmp + EndIf + ; Check if too many columns to fit + If UBound($vValue, $UBOUND_COLUMNS) + $iStart > UBound($aArray, $UBOUND_COLUMNS) Then Return SetError(8, 0, -1) + ReDim $aArray[$iDim_1 + $vRange[0] + 1][$iDim_2] + For $iReadFromIndex = $iDim_1 To 0 Step -1 + ; Copy existing elements + For $j = 0 To $iDim_2 - 1 + $aArray[$iCopyTo_Index][$j] = $aArray[$iReadFromIndex][$j] + Next + ; Move up array + $iCopyTo_Index -= 1 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + While $iReadFromIndex = $iInsert_Index + ; Insert new item + For $j = 0 To $iDim_2 - 1 + If $j < $iStart Then + $aArray[$iCopyTo_Index][$j] = "" + ElseIf $j - $iStart > $iValDim_2 - 1 Then + $aArray[$iCopyTo_Index][$j] = "" + Else + If $iInsertPoint_Index - 1 < $iValDim_1 Then + If IsFunc($hDataType) Then + $aArray[$iCopyTo_Index][$j] = $hDataType($vValue[$iInsertPoint_Index - 1][$j - $iStart]) + Else + $aArray[$iCopyTo_Index][$j] = $vValue[$iInsertPoint_Index - 1][$j - $iStart] + EndIf + Else + $aArray[$iCopyTo_Index][$j] = "" + EndIf + EndIf + Next + ; Move up array + $iCopyTo_Index -= 1 + ; Reset insert index + $iInsertPoint_Index -= 1 + If $iInsertPoint_Index = 0 Then ExitLoop 2 + ; Get next insert point + $iInsert_Index = $vRange[$iInsertPoint_Index] + WEnd + Next + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return UBound($aArray, $UBOUND_ROWS) +EndFunc ;==>_ArrayInsert + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - Added $iCompNumeric and $iStart parameters and logic, Ultima - added $iEnd parameter, code cleanup; Melba23 - Added 2D support +; =============================================================================================================================== +Func _ArrayMax(Const ByRef $aArray, $iCompNumeric = 0, $iStart = -1, $iEnd = -1, $iSubItem = 0) + + Local $iResult = _ArrayMaxIndex($aArray, $iCompNumeric, $iStart, $iEnd, $iSubItem) + If @error Then Return SetError(@error, 0, "") + If UBound($aArray, $UBOUND_DIMENSIONS) = 1 Then + Return $aArray[$iResult] + Else + Return $aArray[$iResult][$iSubItem] + EndIf +EndFunc ;==>_ArrayMax + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - Added $iCompNumeric and $iStart parameters and logic; Melba23 - Added 2D support; guinness - Reduced duplicate code. +; =============================================================================================================================== +Func _ArrayMaxIndex(Const ByRef $aArray, $iCompNumeric = 0, $iStart = -1, $iEnd = -1, $iSubItem = 0) + + If $iCompNumeric = Default Then $iCompNumeric = 0 + If $iStart = Default Then $iStart = -1 + If $iEnd = Default Then $iEnd = -1 + If $iSubItem = Default Then $iSubItem = 0 + Local $iRet = __Array_MinMaxIndex($aArray, $iCompNumeric, $iStart, $iEnd, $iSubItem, __Array_GreaterThan) ; Pass a delegate function to check if value1 > value2. + Return SetError(@error, 0, $iRet) +EndFunc ;==>_ArrayMaxIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - Added $iCompNumeric and $iStart parameters and logic, Ultima - added $iEnd parameter, code cleanup; Melba23 - Added 2D support +; =============================================================================================================================== +Func _ArrayMin(Const ByRef $aArray, $iCompNumeric = 0, $iStart = -1, $iEnd = -1, $iSubItem = 0) + + Local $iResult = _ArrayMinIndex($aArray, $iCompNumeric, $iStart, $iEnd, $iSubItem) + If @error Then Return SetError(@error, 0, "") + If UBound($aArray, $UBOUND_DIMENSIONS) = 1 Then + Return $aArray[$iResult] + Else + Return $aArray[$iResult][$iSubItem] + EndIf +EndFunc ;==>_ArrayMin + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - Added $iCompNumeric and $iStart parameters and logic; Melba23 - Added 2D support; guinness - Reduced duplicate code. +; =============================================================================================================================== +Func _ArrayMinIndex(Const ByRef $aArray, $iCompNumeric = 0, $iStart = -1, $iEnd = -1, $iSubItem = 0) + If $iCompNumeric = Default Then $iCompNumeric = 0 + If $iStart = Default Then $iStart = -1 + If $iEnd = Default Then $iEnd = -1 + If $iSubItem = Default Then $iSubItem = 0 + Local $iRet = __Array_MinMaxIndex($aArray, $iCompNumeric, $iStart, $iEnd, $iSubItem, __Array_LessThan) ; Pass a delegate function to check if value1 < value2. + Return SetError(@error, 0, $iRet) +EndFunc ;==>_ArrayMinIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Erik Pilsits +; Modified.......: Melba23 - added support for empty arrays +; =============================================================================================================================== +Func _ArrayPermute(ByRef $aArray, $sDelimiter = "") + + If $sDelimiter = Default Then $sDelimiter = "" + If Not IsArray($aArray) Then Return SetError(1, 0, 0) + If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(2, 0, 0) + Local $iSize = UBound($aArray), $iFactorial = 1, $aIdx[$iSize], $aResult[1], $iCount = 1 + + If UBound($aArray) Then + For $i = 0 To $iSize - 1 + $aIdx[$i] = $i + Next + For $i = $iSize To 1 Step -1 + $iFactorial *= $i + Next + ReDim $aResult[$iFactorial + 1] + $aResult[0] = $iFactorial + __Array_ExeterInternal($aArray, 0, $iSize, $sDelimiter, $aIdx, $aResult, $iCount) + Else + $aResult[0] = 0 + EndIf + Return $aResult +EndFunc ;==>_ArrayPermute + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Ultima - code cleanup; Melba23 - added support for empty arrays +; =============================================================================================================================== +Func _ArrayPop(ByRef $aArray) + If (Not IsArray($aArray)) Then Return SetError(1, 0, "") + If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(2, 0, "") + + Local $iUBound = UBound($aArray) - 1 + If $iUBound = -1 Then Return SetError(3, 0, "") + Local $sLastVal = $aArray[$iUBound] + + ; Remove last item + If $iUBound > -1 Then + ReDim $aArray[$iUBound] + EndIf + + ; Return last item + Return $sLastVal +EndFunc ;==>_ArrayPop + +; #FUNCTION# ==================================================================================================================== +; Author ........: Helias Gerassimou(hgeras), Ultima - code cleanup/rewrite (major optimization), fixed support for $vValue as an array +; Modified.......: +; =============================================================================================================================== +Func _ArrayPush(ByRef $aArray, $vValue, $iDirection = 0) + + If $iDirection = Default Then $iDirection = 0 + If (Not IsArray($aArray)) Then Return SetError(1, 0, 0) + If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(3, 0, 0) + Local $iUBound = UBound($aArray) - 1 + + If IsArray($vValue) Then ; $vValue is an array + Local $iUBoundS = UBound($vValue) + If ($iUBoundS - 1) > $iUBound Then Return SetError(2, 0, 0) + + ; $vValue is an array smaller than $aArray + If $iDirection Then ; slide right, add to front + For $i = $iUBound To $iUBoundS Step -1 + $aArray[$i] = $aArray[$i - $iUBoundS] + Next + For $i = 0 To $iUBoundS - 1 + $aArray[$i] = $vValue[$i] + Next + Else ; slide left, add to end + For $i = 0 To $iUBound - $iUBoundS + $aArray[$i] = $aArray[$i + $iUBoundS] + Next + For $i = 0 To $iUBoundS - 1 + $aArray[$i + $iUBound - $iUBoundS + 1] = $vValue[$i] + Next + EndIf + Else + ; Check for empty array + If $iUBound > -1 Then + If $iDirection Then ; slide right, add to front + For $i = $iUBound To 1 Step -1 + $aArray[$i] = $aArray[$i - 1] + Next + $aArray[0] = $vValue + Else ; slide left, add to end + For $i = 0 To $iUBound - 1 + $aArray[$i] = $aArray[$i + 1] + Next + $aArray[$iUBound] = $vValue + EndIf + EndIf + EndIf + + Return 1 +EndFunc ;==>_ArrayPush + +; #FUNCTION# ==================================================================================================================== +; Author ........: Brian Keene +; Modified.......: Jos - added $iStart parameter and logic; Tylo - added $iEnd parameter and rewrote it for speed +; =============================================================================================================================== +Func _ArrayReverse(ByRef $aArray, $iStart = 0, $iEnd = 0) + + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If Not IsArray($aArray) Then Return SetError(1, 0, 0) + If UBound($aArray, $UBOUND_DIMENSIONS) <> 1 Then Return SetError(3, 0, 0) + If Not UBound($aArray) Then Return SetError(4, 0, 0) + + Local $vTmp, $iUBound = UBound($aArray) - 1 + + ; Bounds checking + If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound + If $iStart < 0 Then $iStart = 0 + If $iStart > $iEnd Then Return SetError(2, 0, 0) + + ; Reverse + For $i = $iStart To Int(($iStart + $iEnd - 1) / 2) + $vTmp = $aArray[$i] + $aArray[$i] = $aArray[$iEnd] + $aArray[$iEnd] = $vTmp + $iEnd -= 1 + Next + + Return 1 +EndFunc ;==>_ArrayReverse + +; #FUNCTION# ==================================================================================================================== +; Author ........: Michael Michta +; Modified.......: gcriaco ; Ultima - 2D arrays supported, directional search, code cleanup, optimization; Melba23 - added support for empty arrays and row search; BrunoJ - Added compare option 3 to use a regex pattern +; =============================================================================================================================== +Func _ArraySearch(Const ByRef $aArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iForward = 1, $iSubItem = -1, $bRow = False) + + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iCase = Default Then $iCase = 0 + If $iCompare = Default Then $iCompare = 0 + If $iForward = Default Then $iForward = 1 + If $iSubItem = Default Then $iSubItem = -1 + If $bRow = Default Then $bRow = False + + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray) - 1 + If $iDim_1 = -1 Then Return SetError(3, 0, -1) + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + + ; Same var Type of comparison + Local $bCompType = False + If $iCompare = 2 Then + $iCompare = 0 + $bCompType = True + EndIf + ; Bounds checking + If $bRow Then + If UBound($aArray, $UBOUND_DIMENSIONS) = 1 Then Return SetError(5, 0, -1) + If $iEnd < 1 Or $iEnd > $iDim_2 Then $iEnd = $iDim_2 + If $iStart < 0 Then $iStart = 0 + If $iStart > $iEnd Then Return SetError(4, 0, -1) + Else + If $iEnd < 1 Or $iEnd > $iDim_1 Then $iEnd = $iDim_1 + If $iStart < 0 Then $iStart = 0 + If $iStart > $iEnd Then Return SetError(4, 0, -1) + EndIf + ; Direction (flip if $iForward = 0) + Local $iStep = 1 + If Not $iForward Then + Local $iTmp = $iStart + $iStart = $iEnd + $iEnd = $iTmp + $iStep = -1 + EndIf + + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 ; 1D array search + If Not $iCompare Then + If Not $iCase Then + For $i = $iStart To $iEnd Step $iStep + If $bCompType And VarGetType($aArray[$i]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$i] = $vValue Then Return $i + Next + Else + For $i = $iStart To $iEnd Step $iStep + If $bCompType And VarGetType($aArray[$i]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$i] == $vValue Then Return $i + Next + EndIf + Else + For $i = $iStart To $iEnd Step $iStep + If $iCompare = 3 Then + If StringRegExp($aArray[$i], $vValue) Then Return $i + Else + If StringInStr($aArray[$i], $vValue, $iCase) > 0 Then Return $i + EndIf + Next + EndIf + Case 2 ; 2D array search + Local $iDim_Sub + If $bRow Then + ; Search rows + $iDim_Sub = $iDim_1 + If $iSubItem > $iDim_Sub Then $iSubItem = $iDim_Sub + If $iSubItem < 0 Then + ; will search for all Col + $iSubItem = 0 + Else + $iDim_Sub = $iSubItem + EndIf + Else + ; Search columns + $iDim_Sub = $iDim_2 + If $iSubItem > $iDim_Sub Then $iSubItem = $iDim_Sub + If $iSubItem < 0 Then + ; will search for all Col + $iSubItem = 0 + Else + $iDim_Sub = $iSubItem + EndIf + EndIf + ; Now do the search + For $j = $iSubItem To $iDim_Sub + If Not $iCompare Then + If Not $iCase Then + For $i = $iStart To $iEnd Step $iStep + If $bRow Then + If $bCompType And VarGetType($aArray[$j][$j]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$j][$i] = $vValue Then Return $i + Else + If $bCompType And VarGetType($aArray[$i][$j]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$i][$j] = $vValue Then Return $i + EndIf + Next + Else + For $i = $iStart To $iEnd Step $iStep + If $bRow Then + If $bCompType And VarGetType($aArray[$j][$i]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$j][$i] == $vValue Then Return $i + Else + If $bCompType And VarGetType($aArray[$i][$j]) <> VarGetType($vValue) Then ContinueLoop + If $aArray[$i][$j] == $vValue Then Return $i + EndIf + Next + EndIf + Else + For $i = $iStart To $iEnd Step $iStep + If $iCompare = 3 Then + If $bRow Then + If StringRegExp($aArray[$j][$i], $vValue) Then Return $i + Else + If StringRegExp($aArray[$i][$j], $vValue) Then Return $i + EndIf + Else + If $bRow Then + If StringInStr($aArray[$j][$i], $vValue, $iCase) > 0 Then Return $i + Else + If StringInStr($aArray[$i][$j], $vValue, $iCase) > 0 Then Return $i + EndIf + EndIf + Next + EndIf + Next + Case Else + Return SetError(2, 0, -1) + EndSwitch + Return SetError(6, 0, -1) +EndFunc ;==>_ArraySearch + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 +; Modified.......: +; =============================================================================================================================== +Func _ArrayShuffle(ByRef $aArray, $iStart_Row = 0, $iEnd_Row = 0, $iCol = -1) + + ; Fisher–Yates algorithm + + If $iStart_Row = Default Then $iStart_Row = 0 + If $iEnd_Row = Default Then $iEnd_Row = 0 + If $iCol = Default Then $iCol = -1 + + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) + If $iEnd_Row = 0 Then $iEnd_Row = $iDim_1 - 1 + If $iStart_Row < 0 Or $iStart_Row > $iDim_1 - 1 Then Return SetError(3, 0, -1) + If $iEnd_Row < 1 Or $iEnd_Row > $iDim_1 - 1 Then Return SetError(3, 0, -1) + If $iStart_Row > $iEnd_Row Then Return SetError(4, 0, -1) + + Local $vTmp, $iRand + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + For $i = $iEnd_Row To $iStart_Row + 1 Step -1 + $iRand = Random($iStart_Row, $i, 1) + $vTmp = $aArray[$i] + $aArray[$i] = $aArray[$iRand] + $aArray[$iRand] = $vTmp + Next + Return 1 + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) + If $iCol < -1 Or $iCol > $iDim_2 - 1 Then Return SetError(5, 0, -1) + Local $iCol_Start, $iCol_End + If $iCol = -1 Then + $iCol_Start = 0 + $iCol_End = $iDim_2 - 1 + Else + $iCol_Start = $iCol + $iCol_End = $iCol + EndIf + For $i = $iEnd_Row To $iStart_Row + 1 Step -1 + $iRand = Random($iStart_Row, $i, 1) + For $j = $iCol_Start To $iCol_End + $vTmp = $aArray[$i][$j] + $aArray[$i][$j] = $aArray[$iRand][$j] + $aArray[$iRand][$j] = $vTmp + Next + Next + Return 1 + Case Else + Return SetError(2, 0, -1) + EndSwitch + +EndFunc ;==>_ArrayShuffle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jos +; Modified.......: LazyCoder - added $iSubItem option; Tylo - implemented stable QuickSort algo; Jos - changed logic to correctly Sort arrays with mixed Values and Strings; Melba23 - implemented stable pivot algo +; =============================================================================================================================== +Func _ArraySort(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0) + + If $iDescending = Default Then $iDescending = 0 + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iSubItem = Default Then $iSubItem = 0 + If $iPivot = Default Then $iPivot = 0 + If Not IsArray($aArray) Then Return SetError(1, 0, 0) + + Local $iUBound = UBound($aArray) - 1 + If $iUBound = -1 Then Return SetError(5, 0, 0) + + ; Bounds checking + If $iEnd = Default Then $iEnd = 0 + If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound + If $iStart < 0 Or $iStart = Default Then $iStart = 0 + If $iStart > $iEnd Then Return SetError(2, 0, 0) + + If $iDescending = Default Then $iDescending = 0 + If $iPivot = Default Then $iPivot = 0 + If $iSubItem = Default Then $iSubItem = 0 + + ; Sort + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $iPivot Then ; Switch algorithms as required + __ArrayDualPivotSort($aArray, $iStart, $iEnd) + Else + __ArrayQuickSort1D($aArray, $iStart, $iEnd) + EndIf + If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd) + Case 2 + If $iPivot Then Return SetError(6, 0, 0) ; Error if 2D array and $iPivot + Local $iSubMax = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iSubItem > $iSubMax Then Return SetError(3, 0, 0) + + If $iDescending Then + $iDescending = -1 + Else + $iDescending = 1 + EndIf + + __ArrayQuickSort2D($aArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax) + Case Else + Return SetError(4, 0, 0) + EndSwitch + + Return 1 +EndFunc ;==>_ArraySort + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __ArrayQuickSort1D +; Description ...: Helper function for sorting 1D arrays +; Syntax.........: __ArrayQuickSort1D ( ByRef $aArray, ByRef $iStart, ByRef $iEnd ) +; Parameters ....: $aArray - Array to sort +; $iStart - Index of array to start sorting at +; $iEnd - Index of array to stop sorting at +; Return values .: None +; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima +; Modified.......: +; Remarks .......: For Internal Use Only +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __ArrayQuickSort1D(ByRef $aArray, Const ByRef $iStart, Const ByRef $iEnd) + If $iEnd <= $iStart Then Return + + Local $vTmp + + ; InsertionSort (faster for smaller segments) + If ($iEnd - $iStart) < 15 Then + Local $vCur + For $i = $iStart + 1 To $iEnd + $vTmp = $aArray[$i] + + If IsNumber($vTmp) Then + For $j = $i - 1 To $iStart Step -1 + $vCur = $aArray[$j] + ; If $vTmp >= $vCur Then ExitLoop + If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop + $aArray[$j + 1] = $vCur + Next + Else + For $j = $i - 1 To $iStart Step -1 + If (StringCompare($vTmp, $aArray[$j]) >= 0) Then ExitLoop + $aArray[$j + 1] = $aArray[$j] + Next + EndIf + + $aArray[$j + 1] = $vTmp + Next + Return + EndIf + + ; QuickSort + Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)], $bNum = IsNumber($vPivot) + Do + If $bNum Then + ; While $aArray[$L] < $vPivot + While ($aArray[$L] < $vPivot And IsNumber($aArray[$L])) Or (Not IsNumber($aArray[$L]) And StringCompare($aArray[$L], $vPivot) < 0) + $L += 1 + WEnd + ; While $aArray[$R] > $vPivot + While ($aArray[$R] > $vPivot And IsNumber($aArray[$R])) Or (Not IsNumber($aArray[$R]) And StringCompare($aArray[$R], $vPivot) > 0) + $R -= 1 + WEnd + Else + While (StringCompare($aArray[$L], $vPivot) < 0) + $L += 1 + WEnd + While (StringCompare($aArray[$R], $vPivot) > 0) + $R -= 1 + WEnd + EndIf + + ; Swap + If $L <= $R Then + $vTmp = $aArray[$L] + $aArray[$L] = $aArray[$R] + $aArray[$R] = $vTmp + $L += 1 + $R -= 1 + EndIf + Until $L > $R + + __ArrayQuickSort1D($aArray, $iStart, $R) + __ArrayQuickSort1D($aArray, $L, $iEnd) +EndFunc ;==>__ArrayQuickSort1D + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __ArrayQuickSort2D +; Description ...: Helper function for sorting 2D arrays +; Syntax.........: __ArrayQuickSort2D ( ByRef $aArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax ) +; Parameters ....: $aArray - Array to sort +; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!) +; $iStart - Index of array to start sorting at +; $iEnd - Index of array to stop sorting at +; $iSubItem - Sub-index to sort on in 2D arrays +; $iSubMax - Maximum sub-index that array has +; Return values .: None +; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima +; Modified.......: +; Remarks .......: For Internal Use Only +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __ArrayQuickSort2D(ByRef $aArray, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax) + If $iEnd <= $iStart Then Return + + ; QuickSort + Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $bNum = IsNumber($vPivot) + Do + If $bNum Then + ; While $aArray[$L][$iSubItem] < $vPivot + While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot) < 0) + $L += 1 + WEnd + ; While $aArray[$R][$iSubItem] > $vPivot + While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot) > 0) + $R -= 1 + WEnd + Else + While ($iStep * StringCompare($aArray[$L][$iSubItem], $vPivot) < 0) + $L += 1 + WEnd + While ($iStep * StringCompare($aArray[$R][$iSubItem], $vPivot) > 0) + $R -= 1 + WEnd + EndIf + + ; Swap + If $L <= $R Then + For $i = 0 To $iSubMax + $vTmp = $aArray[$L][$i] + $aArray[$L][$i] = $aArray[$R][$i] + $aArray[$R][$i] = $vTmp + Next + $L += 1 + $R -= 1 + EndIf + Until $L > $R + + __ArrayQuickSort2D($aArray, $iStep, $iStart, $R, $iSubItem, $iSubMax) + __ArrayQuickSort2D($aArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax) +EndFunc ;==>__ArrayQuickSort2D + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __ArrayDualPivotSort +; Description ...: Helper function for sorting 1D arrays +; Syntax.........: __ArrayDualPivotSort ( ByRef $aArray, $iPivot_Left, $iPivot_Right [, $bLeftMost = True ] ) +; Parameters ....: $aArray - Array to sort +; $iPivot_Left - Index of the array to start sorting at +; $iPivot_Right - Index of the array to stop sorting at +; $bLeftMost - Indicates if this part is the leftmost in the range +; Return values .: None +; Author ........: Erik Pilsits +; Modified.......: Melba23 +; Remarks .......: For Internal Use Only +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __ArrayDualPivotSort(ByRef $aArray, $iPivot_Left, $iPivot_Right, $bLeftMost = True) + If $iPivot_Left > $iPivot_Right Then Return + Local $iLength = $iPivot_Right - $iPivot_Left + 1 + Local $i, $j, $k, $iAi, $iAk, $iA1, $iA2, $iLast + If $iLength < 45 Then ; Use insertion sort for small arrays - value chosen empirically + If $bLeftMost Then + $i = $iPivot_Left + While $i < $iPivot_Right + $j = $i + $iAi = $aArray[$i + 1] + While $iAi < $aArray[$j] + $aArray[$j + 1] = $aArray[$j] + $j -= 1 + If $j + 1 = $iPivot_Left Then ExitLoop + WEnd + $aArray[$j + 1] = $iAi + $i += 1 + WEnd + Else + While 1 + If $iPivot_Left >= $iPivot_Right Then Return 1 + $iPivot_Left += 1 + If $aArray[$iPivot_Left] < $aArray[$iPivot_Left - 1] Then ExitLoop + WEnd + While 1 + $k = $iPivot_Left + $iPivot_Left += 1 + If $iPivot_Left > $iPivot_Right Then ExitLoop + $iA1 = $aArray[$k] + $iA2 = $aArray[$iPivot_Left] + If $iA1 < $iA2 Then + $iA2 = $iA1 + $iA1 = $aArray[$iPivot_Left] + EndIf + $k -= 1 + While $iA1 < $aArray[$k] + $aArray[$k + 2] = $aArray[$k] + $k -= 1 + WEnd + $aArray[$k + 2] = $iA1 + While $iA2 < $aArray[$k] + $aArray[$k + 1] = $aArray[$k] + $k -= 1 + WEnd + $aArray[$k + 1] = $iA2 + $iPivot_Left += 1 + WEnd + $iLast = $aArray[$iPivot_Right] + $iPivot_Right -= 1 + While $iLast < $aArray[$iPivot_Right] + $aArray[$iPivot_Right + 1] = $aArray[$iPivot_Right] + $iPivot_Right -= 1 + WEnd + $aArray[$iPivot_Right + 1] = $iLast + EndIf + Return 1 + EndIf + Local $iSeventh = BitShift($iLength, 3) + BitShift($iLength, 6) + 1 + Local $iE1, $iE2, $iE3, $iE4, $iE5, $t + $iE3 = Ceiling(($iPivot_Left + $iPivot_Right) / 2) + $iE2 = $iE3 - $iSeventh + $iE1 = $iE2 - $iSeventh + $iE4 = $iE3 + $iSeventh + $iE5 = $iE4 + $iSeventh + If $aArray[$iE2] < $aArray[$iE1] Then + $t = $aArray[$iE2] + $aArray[$iE2] = $aArray[$iE1] + $aArray[$iE1] = $t + EndIf + If $aArray[$iE3] < $aArray[$iE2] Then + $t = $aArray[$iE3] + $aArray[$iE3] = $aArray[$iE2] + $aArray[$iE2] = $t + If $t < $aArray[$iE1] Then + $aArray[$iE2] = $aArray[$iE1] + $aArray[$iE1] = $t + EndIf + EndIf + If $aArray[$iE4] < $aArray[$iE3] Then + $t = $aArray[$iE4] + $aArray[$iE4] = $aArray[$iE3] + $aArray[$iE3] = $t + If $t < $aArray[$iE2] Then + $aArray[$iE3] = $aArray[$iE2] + $aArray[$iE2] = $t + If $t < $aArray[$iE1] Then + $aArray[$iE2] = $aArray[$iE1] + $aArray[$iE1] = $t + EndIf + EndIf + EndIf + If $aArray[$iE5] < $aArray[$iE4] Then + $t = $aArray[$iE5] + $aArray[$iE5] = $aArray[$iE4] + $aArray[$iE4] = $t + If $t < $aArray[$iE3] Then + $aArray[$iE4] = $aArray[$iE3] + $aArray[$iE3] = $t + If $t < $aArray[$iE2] Then + $aArray[$iE3] = $aArray[$iE2] + $aArray[$iE2] = $t + If $t < $aArray[$iE1] Then + $aArray[$iE2] = $aArray[$iE1] + $aArray[$iE1] = $t + EndIf + EndIf + EndIf + EndIf + Local $iLess = $iPivot_Left + Local $iGreater = $iPivot_Right + If (($aArray[$iE1] <> $aArray[$iE2]) And ($aArray[$iE2] <> $aArray[$iE3]) And ($aArray[$iE3] <> $aArray[$iE4]) And ($aArray[$iE4] <> $aArray[$iE5])) Then + Local $iPivot_1 = $aArray[$iE2] + Local $iPivot_2 = $aArray[$iE4] + $aArray[$iE2] = $aArray[$iPivot_Left] + $aArray[$iE4] = $aArray[$iPivot_Right] + Do + $iLess += 1 + Until $aArray[$iLess] >= $iPivot_1 + Do + $iGreater -= 1 + Until $aArray[$iGreater] <= $iPivot_2 + $k = $iLess + While $k <= $iGreater + $iAk = $aArray[$k] + If $iAk < $iPivot_1 Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $iAk + $iLess += 1 + ElseIf $iAk > $iPivot_2 Then + While $aArray[$iGreater] > $iPivot_2 + $iGreater -= 1 + If $iGreater + 1 = $k Then ExitLoop 2 + WEnd + If $aArray[$iGreater] < $iPivot_1 Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $aArray[$iGreater] + $iLess += 1 + Else + $aArray[$k] = $aArray[$iGreater] + EndIf + $aArray[$iGreater] = $iAk + $iGreater -= 1 + EndIf + $k += 1 + WEnd + $aArray[$iPivot_Left] = $aArray[$iLess - 1] + $aArray[$iLess - 1] = $iPivot_1 + $aArray[$iPivot_Right] = $aArray[$iGreater + 1] + $aArray[$iGreater + 1] = $iPivot_2 + __ArrayDualPivotSort($aArray, $iPivot_Left, $iLess - 2, True) + __ArrayDualPivotSort($aArray, $iGreater + 2, $iPivot_Right, False) + If ($iLess < $iE1) And ($iE5 < $iGreater) Then + While $aArray[$iLess] = $iPivot_1 + $iLess += 1 + WEnd + While $aArray[$iGreater] = $iPivot_2 + $iGreater -= 1 + WEnd + $k = $iLess + While $k <= $iGreater + $iAk = $aArray[$k] + If $iAk = $iPivot_1 Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $iAk + $iLess += 1 + ElseIf $iAk = $iPivot_2 Then + While $aArray[$iGreater] = $iPivot_2 + $iGreater -= 1 + If $iGreater + 1 = $k Then ExitLoop 2 + WEnd + If $aArray[$iGreater] = $iPivot_1 Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $iPivot_1 + $iLess += 1 + Else + $aArray[$k] = $aArray[$iGreater] + EndIf + $aArray[$iGreater] = $iAk + $iGreater -= 1 + EndIf + $k += 1 + WEnd + EndIf + __ArrayDualPivotSort($aArray, $iLess, $iGreater, False) + Else + Local $iPivot = $aArray[$iE3] + $k = $iLess + While $k <= $iGreater + If $aArray[$k] = $iPivot Then + $k += 1 + ContinueLoop + EndIf + $iAk = $aArray[$k] + If $iAk < $iPivot Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $iAk + $iLess += 1 + Else + While $aArray[$iGreater] > $iPivot + $iGreater -= 1 + WEnd + If $aArray[$iGreater] < $iPivot Then + $aArray[$k] = $aArray[$iLess] + $aArray[$iLess] = $aArray[$iGreater] + $iLess += 1 + Else + $aArray[$k] = $iPivot + EndIf + $aArray[$iGreater] = $iAk + $iGreater -= 1 + EndIf + $k += 1 + WEnd + __ArrayDualPivotSort($aArray, $iPivot_Left, $iLess - 1, True) + __ArrayDualPivotSort($aArray, $iGreater + 1, $iPivot_Right, False) + EndIf +EndFunc ;==>__ArrayDualPivotSort + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 +; Modified.......: +; =============================================================================================================================== +Func _ArraySwap(ByRef $aArray, $iIndex_1, $iIndex_2, $bCol = False, $iStart = -1, $iEnd = -1) + + If $bCol = Default Then $bCol = False + If $iStart = Default Then $iStart = -1 + If $iEnd = Default Then $iEnd = -1 + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iDim_2 = -1 Then ; 1D array so force defaults + $bCol = False + $iStart = -1 + $iEnd = -1 + EndIf + ; Bounds check + If $iStart > $iEnd Then Return SetError(5, 0, -1) + If $bCol Then + If $iIndex_1 < 0 Or $iIndex_2 > $iDim_2 Then Return SetError(3, 0, -1) + If $iStart = -1 Then $iStart = 0 + If $iEnd = -1 Then $iEnd = $iDim_1 + Else + If $iIndex_1 < 0 Or $iIndex_2 > $iDim_1 Then Return SetError(3, 0, -1) + If $iStart = -1 Then $iStart = 0 + If $iEnd = -1 Then $iEnd = $iDim_2 + EndIf + Local $vTmp + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + $vTmp = $aArray[$iIndex_1] + $aArray[$iIndex_1] = $aArray[$iIndex_2] + $aArray[$iIndex_2] = $vTmp + Case 2 + If $iStart < -1 Or $iEnd < -1 Then Return SetError(4, 0, -1) + If $bCol Then + If $iStart > $iDim_1 Or $iEnd > $iDim_1 Then Return SetError(4, 0, -1) + For $j = $iStart To $iEnd + $vTmp = $aArray[$j][$iIndex_1] + $aArray[$j][$iIndex_1] = $aArray[$j][$iIndex_2] + $aArray[$j][$iIndex_2] = $vTmp + Next + Else + If $iStart > $iDim_2 Or $iEnd > $iDim_2 Then Return SetError(4, 0, -1) + For $j = $iStart To $iEnd + $vTmp = $aArray[$iIndex_1][$j] + $aArray[$iIndex_1][$j] = $aArray[$iIndex_2][$j] + $aArray[$iIndex_2][$j] = $vTmp + Next + EndIf + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return 1 + +EndFunc ;==>_ArraySwap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Cephas +; Modified.......: Jos - added $iStart parameter and logic, Ultima - added $iEnd parameter, make use of _ArrayToString() instead of duplicating efforts; Melba23 - added 2D support +; =============================================================================================================================== +Func _ArrayToClip(Const ByRef $aArray, $sDelim_Col = "|", $iStart_Row = -1, $iEnd_Row = -1, $sDelim_Row = @CRLF, $iStart_Col = -1, $iEnd_Col = -1) + Local $sResult = _ArrayToString($aArray, $sDelim_Col, $iStart_Row, $iEnd_Row, $sDelim_Row, $iStart_Col, $iEnd_Col) + If @error Then Return SetError(@error, 0, 0) + If ClipPut($sResult) Then Return 1 + Return SetError(-1, 0, 0) +EndFunc ;==>_ArrayToClip + +; #FUNCTION# ==================================================================================================================== +; Author ........: Brian Keene , Valik - rewritten +; Modified.......: Ultima - code cleanup; Melba23 - added support for empty and 2D arrays +; =============================================================================================================================== +Func _ArrayToString(Const ByRef $aArray, $sDelim_Col = "|", $iStart_Row = -1, $iEnd_Row = -1, $sDelim_Row = @CRLF, $iStart_Col = -1, $iEnd_Col = -1) + + If $sDelim_Col = Default Then $sDelim_Col = "|" + If $sDelim_Row = Default Then $sDelim_Row = @CRLF + If $iStart_Row = Default Then $iStart_Row = -1 + If $iEnd_Row = Default Then $iEnd_Row = -1 + If $iStart_Col = Default Then $iStart_Col = -1 + If $iEnd_Col = Default Then $iEnd_Col = -1 + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + If $iStart_Row = -1 Then $iStart_Row = 0 + If $iEnd_Row = -1 Then $iEnd_Row = $iDim_1 + If $iStart_Row < -1 Or $iEnd_Row < -1 Then Return SetError(3, 0, -1) + If $iStart_Row > $iDim_1 Or $iEnd_Row > $iDim_1 Then Return SetError(3, 0, "") + If $iStart_Row > $iEnd_Row Then Return SetError(4, 0, -1) + Local $sRet = "" + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + For $i = $iStart_Row To $iEnd_Row + $sRet &= $aArray[$i] & $sDelim_Col + Next + Return StringTrimRight($sRet, StringLen($sDelim_Col)) + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iStart_Col = -1 Then $iStart_Col = 0 + If $iEnd_Col = -1 Then $iEnd_Col = $iDim_2 + If $iStart_Col < -1 Or $iEnd_Col < -1 Then Return SetError(5, 0, -1) + If $iStart_Col > $iDim_2 Or $iEnd_Col > $iDim_2 Then Return SetError(5, 0, -1) + If $iStart_Col > $iEnd_Col Then Return SetError(6, 0, -1) + For $i = $iStart_Row To $iEnd_Row + For $j = $iStart_Col To $iEnd_Col + $sRet &= $aArray[$i][$j] & $sDelim_Col + Next + $sRet = StringTrimRight($sRet, StringLen($sDelim_Col)) & $sDelim_Row + Next + Return StringTrimRight($sRet, StringLen($sDelim_Row)) + Case Else + Return SetError(2, 0, -1) + EndSwitch + Return 1 + +EndFunc ;==>_ArrayToString + +; #FUNCTION# ==================================================================================================================== +; Author ........: jchd +; Modified.......: jpm, czardas +; =============================================================================================================================== +Func _ArrayTranspose(ByRef $aArray) + Switch UBound($aArray, 0) + Case 0 + Return SetError(2, 0, 0) + Case 1 + Local $aTemp[1][UBound($aArray)] + For $i = 0 To UBound($aArray) - 1 + $aTemp[0][$i] = $aArray[$i] + Next + $aArray = $aTemp + Case 2 + Local $iDim_1 = UBound($aArray, 1), $iDim_2 = UBound($aArray, 2) + If $iDim_1 <> $iDim_2 Then + Local $aTemp[$iDim_2][$iDim_1] + For $i = 0 To $iDim_1 - 1 + For $j = 0 To $iDim_2 - 1 + $aTemp[$j][$i] = $aArray[$i][$j] + Next + Next + $aArray = $aTemp + Else ; optimimal method for a square grid + Local $vElement + For $i = 0 To $iDim_1 - 1 + For $j = $i + 1 To $iDim_2 - 1 + $vElement = $aArray[$i][$j] + $aArray[$i][$j] = $aArray[$j][$i] + $aArray[$j][$i] = $vElement + Next + Next + EndIf + Case Else + Return SetError(1, 0, 0) + EndSwitch + Return 1 +EndFunc ;==>_ArrayTranspose + +; #FUNCTION# ==================================================================================================================== +; Author ........: Adam Moore (redndahead) +; Modified.......: Ultima - code cleanup, optimization; Melba23 - added 2D support +; =============================================================================================================================== +Func _ArrayTrim(ByRef $aArray, $iTrimNum, $iDirection = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0) + + If $iDirection = Default Then $iDirection = 0 + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iSubItem = Default Then $iSubItem = 0 + If Not IsArray($aArray) Then Return SetError(1, 0, 0) + + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + If $iEnd = 0 Then $iEnd = $iDim_1 + If $iStart > $iEnd Then Return SetError(3, 0, -1) + If $iStart < 0 Or $iEnd < 0 Then Return SetError(3, 0, -1) + If $iStart > $iDim_1 Or $iEnd > $iDim_1 Then Return SetError(3, 0, -1) + If $iStart > $iEnd Then Return SetError(4, 0, -1) + + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $iDirection Then + For $i = $iStart To $iEnd + $aArray[$i] = StringTrimRight($aArray[$i], $iTrimNum) + Next + Else + For $i = $iStart To $iEnd + $aArray[$i] = StringTrimLeft($aArray[$i], $iTrimNum) + Next + EndIf + Case 2 + Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) - 1 + If $iSubItem < 0 Or $iSubItem > $iDim_2 Then Return SetError(5, 0, -1) + If $iDirection Then + For $i = $iStart To $iEnd + $aArray[$i][$iSubItem] = StringTrimRight($aArray[$i][$iSubItem], $iTrimNum) + Next + Else + For $i = $iStart To $iEnd + $aArray[$i][$iSubItem] = StringTrimLeft($aArray[$i][$iSubItem], $iTrimNum) + Next + EndIf + Case Else + Return SetError(2, 0, 0) + EndSwitch + + Return 1 +EndFunc ;==>_ArrayTrim + +; #FUNCTION# ==================================================================================================================== +; Author ........: SmOke_N +; Modified.......: litlmike, Erik Pilsits, BrewManNH, Melba23 +; =============================================================================================================================== +Func _ArrayUnique(Const ByRef $aArray, $iColumn = 0, $iBase = 0, $iCase = 0, $iCount = $ARRAYUNIQUE_COUNT, $iIntType = $ARRAYUNIQUE_AUTO) + + If $iColumn = Default Then $iColumn = 0 + If $iBase = Default Then $iBase = 0 + If $iCase = Default Then $iCase = 0 + If $iCount = Default Then $iCount = $ARRAYUNIQUE_COUNT + ; Check array + If UBound($aArray, $UBOUND_ROWS) = 0 Then Return SetError(1, 0, 0) + Local $iDims = UBound($aArray, $UBOUND_DIMENSIONS), $iNumColumns = UBound($aArray, $UBOUND_COLUMNS) + If $iDims > 2 Then Return SetError(2, 0, 0) + ; Check parameters + If $iBase < 0 Or $iBase > 1 Or (Not IsInt($iBase)) Then Return SetError(3, 0, 0) + If $iCase < 0 Or $iCase > 1 Or (Not IsInt($iCase)) Then Return SetError(3, 0, 0) + If $iCount < 0 Or $iCount > 1 Or (Not IsInt($iCount)) Then Return SetError(4, 0, 0) + If $iIntType < 0 Or $iIntType > 4 Or (Not IsInt($iIntType)) Then Return SetError(5, 0, 0) + If $iColumn < 0 Or ($iNumColumns = 0 And $iColumn > 0) Or ($iNumColumns > 0 And $iColumn >= $iNumColumns) Then Return SetError(6, 0, 0) + ; Autocheck of first element + If $iIntType = $ARRAYUNIQUE_AUTO Then + Local $vFirstElem = ( ($iDims = 1) ? ($aArray[$iBase]) : ($aArray[$iColumn][$iBase]) ) + If IsInt($vFirstElem) Then + Switch VarGetType($vFirstElem) + Case "Int32" + $iIntType = $ARRAYUNIQUE_FORCE32 + Case "Int64" + $iIntType = $ARRAYUNIQUE_FORCE64 + EndSwitch + Else + $iIntType = $ARRAYUNIQUE_FORCE32 + EndIf + EndIf + ; Create error handler + ObjEvent("AutoIt.Error", "__ArrayUnique_AutoErrFunc") + ; Create dictionary + Local $oDictionary = ObjCreate("Scripting.Dictionary") + ; Set case sensitivity + $oDictionary.CompareMode = Number(Not $iCase) + ; Add elements to dictionary + Local $vElem, $sType, $vKey, $bCOMError = False + For $i = $iBase To UBound($aArray) - 1 + If $iDims = 1 Then + ; 1D array + $vElem = $aArray[$i] + Else + ; 2D array + $vElem = $aArray[$i][$iColumn] + EndIf + ; Determine method to use + Switch $iIntType + Case $ARRAYUNIQUE_FORCE32 + ; Use element as key + $oDictionary.Item($vElem) ; Check if key exists - automatically created if not + If @error Then + $bCOMError = True ; Failed with an Int64, Ptr or Binary datatype + ExitLoop + EndIf + Case $ARRAYUNIQUE_FORCE64 + $sType = VarGetType($vElem) + If $sType = "Int32" Then + $bCOMError = True ; Failed with an Int32 datatype + ExitLoop + EndIf ; Create key + $vKey = "#" & $sType & "#" & String($vElem) + If Not $oDictionary.Item($vKey) Then ; Check if key exists + $oDictionary($vKey) = $vElem ; Store actual value in dictionary + EndIf + Case $ARRAYUNIQUE_MATCH + $sType = VarGetType($vElem) + If StringLeft($sType, 3) = "Int" Then + $vKey = "#Int#" & String($vElem) + Else + $vKey = "#" & $sType & "#" & String($vElem) + EndIf + If Not $oDictionary.Item($vKey) Then ; Check if key exists + $oDictionary($vKey) = $vElem ; Store actual value in dictionary + EndIf + Case $ARRAYUNIQUE_DISTINCT + $vKey = "#" & VarGetType($vElem) & "#" & String($vElem) + If Not $oDictionary.Item($vKey) Then ; Check if key exists + $oDictionary($vKey) = $vElem ; Store actual value in dictionary + EndIf + EndSwitch + Next + ; Create return array + Local $aValues, $j = 0 + If $bCOMError Then ; Mismatch Int32/64 + Return SetError(7, 0, 0) + ElseIf $iIntType <> $ARRAYUNIQUE_FORCE32 Then + ; Extract values associated with the unique keys + Local $aValues[$oDictionary.Count] + For $vKey In $oDictionary.Keys() + $aValues[$j] = $oDictionary($vKey) + ; Check for Ptr datatype + If StringLeft($vKey, 5) = "#Ptr#" Then + $aValues[$j] = Ptr($aValues[$j]) + EndIf + $j += 1 + Next + Else + ; Only need to list the unique keys + $aValues = $oDictionary.Keys() + EndIf + ; Add cout if required + If $iCount Then + _ArrayInsert($aValues, 0, $oDictionary.Count) + EndIf + ; Return array + Return $aValues + +EndFunc ;==>_ArrayUnique + +; #FUNCTION# ==================================================================================================================== +; Author ........: jchd, jpm +; Modified.......: +; =============================================================================================================================== +Func _Array1DToHistogram($aArray, $iSizing = 100) + If UBound($aArray, 0) > 1 Then Return SetError(1, 0, "") + $iSizing = $iSizing * 8 + Local $t, $n, $iMin = 0, $iMax = 0, $iOffset = 0 + For $i = 0 To UBound($aArray) - 1 + $t = $aArray[$i] + $t = IsNumber($t) ? Round($t) : 0 + If $t < $iMin Then $iMin = $t + If $t > $iMax Then $iMax = $t + Next + Local $iRange = Int(Round(($iMax - $iMin) / 8)) * 8 + Local $iSpaceRatio = 4 + For $i = 0 To UBound($aArray) - 1 + $t = $aArray[$i] + If $t Then + $n = Abs(Round(($iSizing * $t) / $iRange) / 8) + + $aArray[$i] = "" + If $t > 0 Then + If $iMin Then + $iOffset = Int(Abs(Round(($iSizing * $iMin) / $iRange) / 8) / 8 * $iSpaceRatio) + $aArray[$i] = __Array_StringRepeat(ChrW(0x20), $iOffset) + EndIf + Else + If $iMin <> $t Then + $iOffset = Int(Abs(Round(($iSizing * ($t - $iMin)) / $iRange) / 8) / 8 * $iSpaceRatio) + $aArray[$i] = __Array_StringRepeat(ChrW(0x20), $iOffset) + EndIf + EndIf + $aArray[$i] &= __Array_StringRepeat(ChrW(0x2588), Int($n / 8)) + + $n = Mod($n, 8) + If $n > 0 Then $aArray[$i] &= ChrW(0x2588 + 8 - $n) + $aArray[$i] &= ' ' & $t + Else + $aArray[$i] = "" + EndIf + Next + + Return $aArray +EndFunc ;==>_Array1DToHistogram + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __Array_StringRepeat +; Description ...: Repeats a string a specified number of times +; Syntax.........: __Array_StringRepeat ( $sString, $iRepeatCount ) +; Parameters ....: $sString - String to repeat +; $iRepeatCount - Number of times to repeat the string +; Return values .: a string with specified number of repeats. +; Author ........: Jeremy Landes +; Modified.......: jpm +; Remarks .......: This function is used internally. similar to _StringRepeat() but if $iRepeatCount = 0 returns "" +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __Array_StringRepeat($sString, $iRepeatCount) + ; Casting Int() takes care of String/Int, Numbers. + $iRepeatCount = Int($iRepeatCount) + ; Zero is a valid repeat integer. + If StringLen($sString) < 1 Or $iRepeatCount <= 0 Then Return SetError(1, 0, "") + Local $sResult = "" + While $iRepeatCount > 1 + If BitAND($iRepeatCount, 1) Then $sResult &= $sString + $sString &= $sString + $iRepeatCount = BitShift($iRepeatCount, 1) + WEnd + Return $sString & $sResult +EndFunc ;==>__Array_StringRepeat + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __Array_ExeterInternal +; Description ...: Permute Function based on an algorithm from Exeter University. +; Syntax.........: __Array_ExeterInternal ( ByRef $aArray, $iStart, $iSize, $sDelimiter, ByRef $aIdx, ByRef $aResult ) +; Parameters ....: $aArray - The Array to get Permutations +; $iStart - Starting Point for Loop +; $iSize - End Point for Loop +; $sDelimiter - String result separator +; $aIdx - Array Used in Rotations +; $aResult - Resulting Array +; Return values .: Success - Computer name +; Author ........: Erik Pilsits +; Modified.......: 07/08/2008 +; Remarks .......: This function is used internally. Permute Function based on an algorithm from Exeter University. +; + +; http://www.bearcave.com/random_hacks/permute.html +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __Array_ExeterInternal(ByRef $aArray, $iStart, $iSize, $sDelimiter, ByRef $aIdx, ByRef $aResult, ByRef $iCount) + If $iStart == $iSize - 1 Then + For $i = 0 To $iSize - 1 + $aResult[$iCount] &= $aArray[$aIdx[$i]] & $sDelimiter + Next + If $sDelimiter <> "" Then $aResult[$iCount] = StringTrimRight($aResult[$iCount], StringLen($sDelimiter)) + $iCount += 1 + Else + Local $iTemp + For $i = $iStart To $iSize - 1 + $iTemp = $aIdx[$i] + + $aIdx[$i] = $aIdx[$iStart] + $aIdx[$iStart] = $iTemp + __Array_ExeterInternal($aArray, $iStart + 1, $iSize, $sDelimiter, $aIdx, $aResult, $iCount) + $aIdx[$iStart] = $aIdx[$i] + $aIdx[$i] = $iTemp + Next + EndIf +EndFunc ;==>__Array_ExeterInternal + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __Array_Combinations +; Description ...: Creates Combination +; Syntax.........: __Array_Combinations ( $iN, $iR ) +; Parameters ....: $iN - Value passed on from UBound($aArray) +; $iR - Size of the combinations set +; Return values .: Integer value of the number of combinations +; Author ........: Erik Pilsits +; Modified.......: 07/08/2008 +; Remarks .......: This function is used internally. PBased on an algorithm by Kenneth H. Rosen. +; + +; http://www.bearcave.com/random_hacks/permute.html +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __Array_Combinations($iN, $iR) + Local $i_Total = 1 + + For $i = $iR To 1 Step -1 + $i_Total *= ($iN / $i) + $iN -= 1 + Next + Return Round($i_Total) +EndFunc ;==>__Array_Combinations + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __Array_GetNext +; Description ...: Creates Combination +; Syntax.........: __Array_GetNext ( $iN, $iR, ByRef $iLeft, $iTotal, ByRef $aIdx ) +; Parameters ....: $iN - Value passed on from UBound($aArray) +; $iR - Size of the combinations set +; $iLeft - Remaining number of combinations +; $iTotal - Total number of combinations +; $aIdx - Array containing combinations +; Return values .: Function only changes values ByRef +; Author ........: Erik Pilsits +; Modified.......: 07/08/2008 +; Remarks .......: This function is used internally. PBased on an algorithm by Kenneth H. Rosen. +; + +; http://www.bearcave.com/random_hacks/permute.html +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __Array_GetNext($iN, $iR, ByRef $iLeft, $iTotal, ByRef $aIdx) + If $iLeft == $iTotal Then + $iLeft -= 1 + Return + EndIf + + Local $i = $iR - 1 + While $aIdx[$i] == $iN - $iR + $i + $i -= 1 + WEnd + + $aIdx[$i] += 1 + For $j = $i + 1 To $iR - 1 + $aIdx[$j] = $aIdx[$i] + $j - $i + Next + + $iLeft -= 1 +EndFunc ;==>__Array_GetNext + +Func __Array_MinMaxIndex(Const ByRef $aArray, $iCompNumeric, $iStart, $iEnd, $iSubItem, $fuComparison) ; Always swapped the comparison params around e.g. it was for min 100 > 1000 whereas 1000 < 100 makes more sense in a min function. + If $iCompNumeric = Default Then $iCompNumeric = 0 + If $iCompNumeric <> 1 Then $iCompNumeric = 0 + If $iStart = Default Then $iStart = 0 + If $iEnd = Default Then $iEnd = 0 + If $iSubItem = Default Then $iSubItem = 0 + If Not IsArray($aArray) Then Return SetError(1, 0, -1) + Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) - 1 + If $iDim_1 < 0 Then Return SetError(1, 0, -1) + If $iEnd = -1 Then $iEnd = $iDim_1 + If $iStart = -1 Then $iStart = 0 + If $iStart < -1 Or $iEnd < -1 Then Return SetError(3, 0, -1) + If $iStart > $iDim_1 Or $iEnd > $iDim_1 Then Return SetError(3, 0, -1) + If $iStart > $iEnd Then Return SetError(4, 0, -1) + If $iDim_1 < 0 Then Return SetError(5, 0, -1) + Local $iMaxMinIndex = $iStart + Switch UBound($aArray, $UBOUND_DIMENSIONS) + Case 1 + If $iCompNumeric Then + For $i = $iStart To $iEnd + If $fuComparison(Number($aArray[$i]), Number($aArray[$iMaxMinIndex])) Then $iMaxMinIndex = $i + Next + Else + For $i = $iStart To $iEnd + If $fuComparison($aArray[$i], $aArray[$iMaxMinIndex]) Then $iMaxMinIndex = $i + Next + EndIf + Case 2 + If $iSubItem < 0 Or $iSubItem > UBound($aArray, $UBOUND_COLUMNS) - 1 Then Return SetError(6, 0, -1) + If $iCompNumeric Then + For $i = $iStart To $iEnd + If $fuComparison(Number($aArray[$i][$iSubItem]), Number($aArray[$iMaxMinIndex][$iSubItem])) Then $iMaxMinIndex = $i + Next + Else + For $i = $iStart To $iEnd + If $fuComparison($aArray[$i][$iSubItem], $aArray[$iMaxMinIndex][$iSubItem]) Then $iMaxMinIndex = $i + Next + EndIf + Case Else + Return SetError(2, 0, -1) + EndSwitch + + Return $iMaxMinIndex +EndFunc ;==>__Array_MinMaxIndex + +Func __Array_GreaterThan($vValue1, $vValue2) + Return $vValue1 > $vValue2 +EndFunc ;==>__Array_GreaterThan + +Func __Array_LessThan($vValue1, $vValue2) + Return $vValue1 < $vValue2 +EndFunc ;==>__Array_LessThan + +Func __ArrayUnique_AutoErrFunc() + ; Do nothing special, just check @error after suspect functions. +EndFunc ;==>__ArrayUnique_AutoErrFunc diff --git a/src/include/AutoItConstants.au3 b/src/include/AutoItConstants.au3 new file mode 100644 index 0000000..9bf20c6 --- /dev/null +++ b/src/include/AutoItConstants.au3 @@ -0,0 +1,338 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Constants to be included in an AutoIt v3 script. +; Author(s) .....: JLandes, Nutster, CyberSlug, Holger, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +; Sets the way coords are used in the mouse and pixel functions +Global Const $OPT_COORDSRELATIVE = 0 ; Relative coords to the active window +Global Const $OPT_COORDSABSOLUTE = 1 ; Absolute screen coordinates (default) +Global Const $OPT_COORDSCLIENT = 2 ; Relative coords to client area + +; Sets how errors are handled if a Run/RunWait function fails +Global Const $OPT_ERRORSILENT = 0 ; Silent error (@error set to 1) +Global Const $OPT_ERRORFATAL = 1 ; Fatal error (default) + +; Alters the use of Caps Lock +Global Const $OPT_CAPSNOSTORE = 0 ; Don't store/restore Caps Lock state +Global Const $OPT_CAPSSTORE = 1 ; Store/restore Caps Lock state (default) + +; Alters the method that is used to match window titles +Global Const $OPT_MATCHSTART = 1 ; Match the title from the start (default) +Global Const $OPT_MATCHANY = 2 ; Match any substring in the title +Global Const $OPT_MATCHEXACT = 3 ; Match the title exactly +Global Const $OPT_MATCHADVANCED = 4 ; Use advanced window matching (deprecated) + +; Common Control Styles +Global Const $CCS_TOP = 0x01 +Global Const $CCS_NOMOVEY = 0x02 +Global Const $CCS_BOTTOM = 0x03 +Global Const $CCS_NORESIZE = 0x04 +Global Const $CCS_NOPARENTALIGN = 0x08 +Global Const $CCS_NOHILITE = 0x10 +Global Const $CCS_ADJUSTABLE = 0x20 +Global Const $CCS_NODIVIDER = 0x40 +Global Const $CCS_VERT = 0x0080 +Global Const $CCS_LEFT = 0x0081 +Global Const $CCS_NOMOVEX = 0x0082 +Global Const $CCS_RIGHT = 0x0083 + +; DriveGetType() Constants +Global Const $DT_DRIVETYPE = 1 ; Drive type e.g. CD-ROM, Fixed. +Global Const $DT_SSDSTATUS = 2 ; Status of whether the drive is SSD. +Global Const $DT_BUSTYPE = 3 ; Bus type e.g. SATA, SD. + +; FtpSetProxy and HttpSetProxy Constants +Global Const $PROXY_IE = 0 +Global Const $PROXY_NONE = 1 +Global Const $PROXY_SPECIFIED = 2 + +; Reserved IDs for System Objects +; in MenuConstants.au3 +; in ScrollBarsConstants.au3 +Global Const $OBJID_WINDOW = 0x00000000 +Global Const $OBJID_TITLEBAR = 0xFFFFFFFE +Global Const $OBJID_SIZEGRIP = 0xFFFFFFF9 +Global Const $OBJID_CARET = 0xFFFFFFF8 +Global Const $OBJID_CURSOR = 0xFFFFFFF7 +Global Const $OBJID_ALERT = 0xFFFFFFF6 +Global Const $OBJID_SOUND = 0xFFFFFFF5 + +; Progress and Splash Constants +; Indicates properties of the displayed progress or splash dialog +Global Const $DLG_CENTERONTOP = 0 ; Center justified/always on top/with title +Global Const $DLG_NOTITLE = 1 ; Titleless window +Global Const $DLG_NOTONTOP = 2 ; Without "always on top" attribute +Global Const $DLG_TEXTLEFT = 4 ; Left justified text +Global Const $DLG_TEXTRIGHT = 8 ; Right justified text +Global Const $DLG_MOVEABLE = 16 ; Window can be moved +Global Const $DLG_TEXTVCENTER = 32 ; Splash text centered vertically + +; Mouse Constants +; Indicates current mouse cursor +Global Const $IDC_UNKNOWN = 0 ; Unknown cursor +Global Const $IDC_APPSTARTING = 1 ; Standard arrow and small hourglass +Global Const $IDC_ARROW = 2 ; Standard arrow +Global Const $IDC_CROSS = 3 ; Crosshair +Global Const $IDC_HAND = 32649 ; Hand cursor +Global Const $IDC_HELP = 4 ; Arrow and question mark +Global Const $IDC_IBEAM = 5 ; I-beam +Global Const $IDC_ICON = 6 ; Obsolete +Global Const $IDC_NO = 7 ; Slashed circle +Global Const $IDC_SIZE = 8 ; Obsolete +Global Const $IDC_SIZEALL = 9 ; Four-pointed arrow pointing N, S, E, and W +Global Const $IDC_SIZENESW = 10 ; Double-pointed arrow pointing NE and SW +Global Const $IDC_SIZENS = 11 ; Double-pointed arrow pointing N and S +Global Const $IDC_SIZENWSE = 12 ; Double-pointed arrow pointing NW and SE +Global Const $IDC_SIZEWE = 13 ; Double-pointed arrow pointing W and E +Global Const $IDC_UPARROW = 14 ; Vertical arrow +Global Const $IDC_WAIT = 15 ; Hourglass + +Global Const $IDI_APPLICATION = 32512 ; Application icon +Global Const $IDI_ASTERISK = 32516 ; Asterisk icon +Global Const $IDI_EXCLAMATION = 32515 ; Exclamation point icon +Global Const $IDI_HAND = 32513 ; Stop sign icon +Global Const $IDI_QUESTION = 32514 ; Question-mark icon +Global Const $IDI_WINLOGO = 32517 ; Windows logo icon. Windows XP: Application icon +Global Const $IDI_SHIELD = 32518 +Global Const $IDI_ERROR = $IDI_HAND +Global Const $IDI_INFORMATION = $IDI_ASTERISK +Global Const $IDI_WARNING = $IDI_EXCLAMATION + +; Process Constants +; Indicates the type of shutdown +Global Const $SD_LOGOFF = 0 ; Logoff +Global Const $SD_SHUTDOWN = 1 ; Shutdown +Global Const $SD_REBOOT = 2 ; Reboot +Global Const $SD_FORCE = 4 ; Force +Global Const $SD_POWERDOWN = 8 ; Power down +Global Const $SD_FORCEHUNG = 16 ; Force shutdown if hung +Global Const $SD_STANDBY = 32 ; Standby +Global Const $SD_HIBERNATE = 64 ; Hibernate + +; Run Constants +Global Const $STDIN_CHILD = 1 +Global Const $STDOUT_CHILD = 2 +Global Const $STDERR_CHILD = 4 +Global Const $STDERR_MERGED = 8 +Global Const $STDIO_INHERIT_PARENT = 0x10 +Global Const $RUN_CREATE_NEW_CONSOLE = 0x00010000 + +; UBound Constants +Global Const $UBOUND_DIMENSIONS = 0 +Global Const $UBOUND_ROWS = 1 +Global Const $UBOUND_COLUMNS = 2 + +; Mouse Event Constants +Global Const $MOUSEEVENTF_ABSOLUTE = 0x8000 ; Specifies that the dx and dy parameters contain normalized absolute coordinates +Global Const $MOUSEEVENTF_MOVE = 0x0001 ; Specifies that movement occurred +Global Const $MOUSEEVENTF_LEFTDOWN = 0x0002 ; Specifies that the left button changed to down +Global Const $MOUSEEVENTF_LEFTUP = 0x0004 ; Specifies that the left button changed to up +Global Const $MOUSEEVENTF_RIGHTDOWN = 0x0008 ; Specifies that the right button changed to down +Global Const $MOUSEEVENTF_RIGHTUP = 0x0010 ; Specifies that the right button changed to up +Global Const $MOUSEEVENTF_MIDDLEDOWN = 0x0020 ; Specifies that the middle button changed to down +Global Const $MOUSEEVENTF_MIDDLEUP = 0x0040 ; Specifies that the middle button changed to up +Global Const $MOUSEEVENTF_WHEEL = 0x0800 ; Specifies that the wheel has been moved, if the mouse has a wheel +Global Const $MOUSEEVENTF_XDOWN = 0x0080 ; Specifies that an X button was pressed +Global Const $MOUSEEVENTF_XUP = 0x0100 ; Specifies that an X button was released + +; Reg Value type Constants +Global Const $REG_NONE = 0 +Global Const $REG_SZ = 1 +Global Const $REG_EXPAND_SZ = 2 +Global Const $REG_BINARY = 3 +Global Const $REG_DWORD = 4 +Global Const $REG_DWORD_LITTLE_ENDIAN = 4 +Global Const $REG_DWORD_BIG_ENDIAN = 5 +Global Const $REG_LINK = 6 +Global Const $REG_MULTI_SZ = 7 +Global Const $REG_RESOURCE_LIST = 8 +Global Const $REG_FULL_RESOURCE_DESCRIPTOR = 9 +Global Const $REG_RESOURCE_REQUIREMENTS_LIST = 10 +Global Const $REG_QWORD = 11 +Global Const $REG_QWORD_LITTLE_ENDIAN = 11 + +; Z order +Global Const $HWND_BOTTOM = 1 ; Places the window at the bottom of the Z order +Global Const $HWND_NOTOPMOST = -2 ; Places the window above all non-topmost windows +Global Const $HWND_TOP = 0 ; Places the window at the top of the Z order +Global Const $HWND_TOPMOST = -1 ; Places the window above all non-topmost windows + +; SetWindowPos Constants +Global Const $SWP_NOSIZE = 0x0001 +Global Const $SWP_NOMOVE = 0x0002 +Global Const $SWP_NOZORDER = 0x0004 +Global Const $SWP_NOREDRAW = 0x0008 +Global Const $SWP_NOACTIVATE = 0x0010 +Global Const $SWP_FRAMECHANGED = 0x0020 +Global Const $SWP_DRAWFRAME = 0x0020 +Global Const $SWP_SHOWWINDOW = 0x0040 +Global Const $SWP_HIDEWINDOW = 0x0080 +Global Const $SWP_NOCOPYBITS = 0x0100 +Global Const $SWP_NOOWNERZORDER = 0x0200 +Global Const $SWP_NOREPOSITION = 0x0200 +Global Const $SWP_NOSENDCHANGING = 0x0400 +Global Const $SWP_DEFERERASE = 0x2000 +Global Const $SWP_ASYNCWINDOWPOS = 0x4000 + +; Keywords (returned from the IsKeyword() function) +Global Const $KEYWORD_DEFAULT = 1 +Global Const $KEYWORD_NULL = 2 + +; IsDeclared Constants +Global Const $DECLARED_LOCAL = -1 +Global Const $DECLARED_UNKNOWN = 0 +Global Const $DECLARED_GLOBAL = 1 + +; Assign Constants +Global Const $ASSIGN_CREATE = 0 +Global Const $ASSIGN_FORCELOCAL = 1 +Global Const $ASSIGN_FORCEGLOBAL = 2 +Global Const $ASSIGN_EXISTFAIL = 4 + +; BlockInput Constants +Global Const $BI_ENABLE = 0 +Global Const $BI_DISABLE = 1 + +; Break Constants +Global Const $BREAK_ENABLE = 1 +Global Const $BREAK_DISABLE = 0 + +; CDTray Constants +Global Const $CDTRAY_OPEN = "open" +Global Const $CDTRAY_CLOSED = "closed" + +; ControlSend and Send Constants +Global Const $SEND_DEFAULT = 0 +Global Const $SEND_RAW = 1 + +; DirGetSize Constants +Global Const $DIR_DEFAULT = 0 +Global Const $DIR_EXTENDED= 1 +Global Const $DIR_NORECURSE = 2 + +; DirRemove Constants +;~ Global Const $DIR_DEFAULT = 0 +Global Const $DIR_REMOVE= 1 + +; DriveGetDrive Constants +Global Const $DT_ALL = "ALL" +Global Const $DT_CDROM = "CDROM" +Global Const $DT_REMOVABLE = "REMOVABLE" +Global Const $DT_FIXED = "FIXED" +Global Const $DT_NETWORK = "NETWORK" +Global Const $DT_RAMDISK = "RAMDISK" +Global Const $DT_UNKNOWN = "UNKNOWN" + +; DriveGetFileSystem Constants +Global Const $DT_UNDEFINED = 1 +Global Const $DT_FAT = "FAT" +Global Const $DT_FAT32 = "FAT32" +Global Const $DT_EXFAT = "exFAT" +Global Const $DT_NTFS = "NTFS" +Global Const $DT_NWFS = "NWFS" +Global Const $DT_CDFS = "CDFS" +Global Const $DT_UDF = "UDF" + +; DriveMapAdd Constants +Global Const $DMA_DEFAULT = 0 +Global Const $DMA_PERSISTENT = 1 +Global Const $DMA_AUTHENTICATION = 8 + +; DriveStatus Constants +Global Const $DS_UNKNOWN = "UNKNOWN" +Global Const $DS_READY = "READY" +Global Const $DS_NOTREADY = "NOTREADY" +Global Const $DS_INVALID = "INVALID" + +; Mouse related Constants +Global Const $MOUSE_CLICK_LEFT = "left" +Global Const $MOUSE_CLICK_RIGHT = "right" +Global Const $MOUSE_CLICK_MIDDLE = "middle" +Global Const $MOUSE_CLICK_MAIN = "main" +Global Const $MOUSE_CLICK_MENU = "menu" +Global Const $MOUSE_CLICK_PRIMARY = "primary" +Global Const $MOUSE_CLICK_SECONDARY = "secondary" +Global Const $MOUSE_WHEEL_UP = "up" +Global Const $MOUSE_WHEEL_DOWN = "down" + +; Dec, Int, Number Constants +Global Const $NUMBER_AUTO = 0 +Global Const $NUMBER_32BIT = 1 +Global Const $NUMBER_64BIT = 2 +Global Const $NUMBER_DOUBLE = 3 + +; ObjName Constants +Global Const $OBJ_NAME = 1 +Global Const $OBJ_STRING = 2 +Global Const $OBJ_PROGID = 3 +Global Const $OBJ_FILE = 4 +Global Const $OBJ_MODULE = 5 +Global Const $OBJ_CLSID = 6 +Global Const $OBJ_IID = 7 + +; OnAutoItExitRegister Constants +Global Const $EXITCLOSE_NORMAL = 0 ; Natural closing. +Global Const $EXITCLOSE_BYEXIT = 1 ; close by Exit function. +Global Const $EXITCLOSE_BYCLICK = 2 ; close by clicking on exit of the systray. +Global Const $EXITCLOSE_BYLOGOFF = 3 ; close by user logoff. +Global Const $EXITCLOSE_BYSUTDOWN = 4 ; close by Windows shutdown. + +; ProcessGetStats Constants +Global Const $PROCESS_STATS_MEMORY = 0 +Global Const $PROCESS_STATS_IO = 1 + +; ProcessSetPriority Constants +Global Const $PROCESS_LOW = 0 +Global Const $PROCESS_BELOWNORMAL = 1 +Global Const $PROCESS_NORMAL = 2 +Global Const $PROCESS_ABOVENORMAL = 3 +Global Const $PROCESS_HIGH = 4 +Global Const $PROCESS_REALTIME = 5 + +; RunAs and RunAsWait Constants +Global Const $RUN_LOGON_NOPROFILE = 0 +Global Const $RUN_LOGON_PROFILE = 1 +Global Const $RUN_LOGON_NETWORK = 2 +Global Const $RUN_LOGON_INHERIT = 4 + +; SoundPlay Constants +Global Const $SOUND_NOWAIT = 0 ; continue script while sound is playing (default) +Global Const $SOUND_WAIT = 1 ; wait until sound has finished + +; ShellExecute and ShellExecuteWait Constants +Global Const $SHEX_OPEN = "open" +Global Const $SHEX_EDIT = "edit" +Global Const $SHEX_PRINT = "print" +Global Const $SHEX_PROPERTIES = "properties" + +; TCPRecv Constants +Global Const $TCP_DATA_DEFAULT = 0 +Global Const $TCP_DATA_BINARY = 1 + +; UDPOpen, UDPRecv Constants +Global Const $UDP_OPEN_DEFAULT = 0 +Global Const $UDP_OPEN_BROADCAST = 1 +Global Const $UDP_DATA_DEFAULT = 0 +Global Const $UDP_DATA_BINARY = 1 +Global Const $UDP_DATA_ARRAY = 2 + +; ToolTip, GUICtrlSetTip Constants +Global Const $TIP_NOICON = 0 ; No icon +Global Const $TIP_INFOICON = 1 ; Info icon +Global Const $TIP_WARNINGICON = 2 ; Warning icon +Global Const $TIP_ERRORICON = 3 ; Error Icon + +Global Const $TIP_BALLOON = 1 +Global Const $TIP_CENTER = 2 +Global Const $TIP_FORCEVISIBLE = 4 + +; WindowsSetOnTop Constants +Global Const $WINDOWS_NOONTOP = 0 +Global Const $WINDOWS_ONTOP = 1 +; =============================================================================================================================== diff --git a/src/include/CommMG64.au3 b/src/include/CommMG64.au3 new file mode 100644 index 0000000..732efec --- /dev/null +++ b/src/include/CommMG64.au3 @@ -0,0 +1,1155 @@ +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Outfile_x64=CommMG64.exe +#AutoIt3Wrapper_Compile_Both=y +#AutoIt3Wrapper_UseX64=y +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** +#include-once +;Opt("mustdeclarevars", 1) ;testing only +#cs + UDF for commg.dll +#ce + +Global $mgdebug = false +#cs + Version 2.1.1 Added missing declarations which caused problems in scripts using Opt("MustDeclareVars",1) - thanks to Hannes + Version 2.1 Thanks to jps1x2 for the read/send bte array incentive and testing. + Version 2.0.2 beta changed readbytearray so returns no of bytes read + Version 2.0.1 beta + added _CommSendByteArray and _CommReadByteArray + Version 2.0 - added _CommSwitch. Can now use up to 4 ports. + Version 2.2 - add rts, dtr to setport + added option for flow control = NONE to _CommSetPort + version 2.3 use commg.dll v2.3 which allows any baud rate up to 256000. + Version 2.4 added setTimeouts, SetXonXoffProperties + Version 2.5 add _CommsetTimeouts, _CommSetXonXoffProperties + Version 2.6 added _CommSetRTS, _CommSetDTR + change switch so up to 50 com ports can be open at a time + Version 2.7 added _CommSetDllPath + Version 2.8 17th April 2010 + add GetLineStates for CTS, DSR, Ring Indicator and DCD + Corrected return of functions _CommSetRTS and _CommSetDTR to be -1 on error + Version 2.81 add sleep(20) in CommGetLine to reduce CPU usage. Thanks to jimg. + Version 2.82 Correct error in _ComSetPort which could prevent _CommSetDllPath working. + Version 2.83 add function _CommSetBufferSizes + added ComGetPortNames around these versions but not sure when. + Version 2.84 modify ReadByte to allow for error, probable cause is a timeout triggered by values set in _CommSetTimeouts + Removed CloseDll in _CommClosePort so one port can be closed and others still used. + Version 2.85 Fix error in _CommClosePort + version 2.86 change return from GetByte so that if result of call to dll is a string longer than 2 chara assume it is an error message. + Version 2.87 corrected _CommReadByte which would not return characters with ACSII codes > 99. Now returns 0 to 255 inclusive. + Added sleep(20)Cto end of While loop in _CommGetLine which greatly reduced CPU usage. + Thanks to adrianhudson for bring these problems to my attention. + Version 2.88 Made the sleep added the _CommGetLine only happen if no character received so that reading + is not slower. + Version 2.89 Corect typo in V2.88 + Version 2.90 Change _CommClosePort. Requires the use of Commg.dll version 2.79 or later. Thanks to tfabris for telling me about the error. +#ce +Const $sUDFVersion = 'CommMG64.au3 V2.91' +#cs + AutoIt Version: 3.2.3++ + Language: English + + Description: Functions for serial comms using commg2_4.dll or later + Works with COM ports, USB to Serial converters, Serial to RS424 etc + + Functions available: + _CommGetVersion + _CommSetDllPath + _CommListPorts + _ComGetPortNames + _CommSetPort + _CommPortConnection + _CommClearOutputBuffer + _CommClearInputBuffer + _CommGetInputcount + _CommGetOutputcount + _CommSendString + _CommGetString + _CommGetLine + _CommReadByte + _CommReadChar + _CommSendByte + _CommSendBreak; not tested!!!!!!!!!! + _CommCloseport + _CommSwitch + _CommSendByteArray + _CommReadByteArray + _CommSetTimeouts + _CommSetXonXoffProperties + _CommSetRTS + _CommSetDTR + _CommGetLineStates + _CommSetBufferSizes + + Author: Martin Gibson +#ce +#include-once + +Global $fPortOpen = False +Global $hDll +Global $DLLNAME = 'commg64.dll' + + +;=============================================================================== +; +; Function Name: _CommSetDllPath($sFullPath) +; Description: Sets full path to th edll so that it can be in any location. +; +; Parameters: $sFullPath - Full path to the commg.dll e.g. _CommSetDllPath("C:\COMMS\commg.dll") +; Returns; on success 1 +; on error -1 if full path does not exist +;=============================================================================== +Func _CommSetDllPath($sFullPath) + If Not FileExists($sFullPath) Then Return -1 + + $DLLNAME = $sFullPath + Return 1 + +EndFunc ;==>_CommSetDllPath + + +;=============================================================================== +; +; Function Name: _CommListPorts($iReturnType=1) +; Description: Gets the list of available ports seperated by '|' or as an array +; +; Parameters: $iReturnType - integer:if $iReturnType = 1 then return a string with the list of COM ports seperated by '|' +; if $iReturnType <> 1 then return an array of strings, with element [0] holding the number of COM ports +; Returns; on success - a string eg 'COM1|COM8', or array eg ['2','COM1','COM2'] +; on failure - an empty string and @error set to 1 if dll could not list any ports +; @error set to 2 id dll not open and couldn't be opened + +;=============================================================================== +Func _CommListPorts($iReturnType = 1) + Local $vDllAns, $lpres + If Not $fPortOpen Then + ConsoleWrite($DLLNAME & @LF) + $hDll = DllOpen($DLLNAME) + If $hDll = -1 Then + SetError(2) + ;$sErr = 'Failed to open commg2_2.dll' + Return 0;failed + EndIf + $fPortOpen = True + EndIf + If $fPortOpen Then + $vDllAns = DllCall($hDll, 'str', 'ListPorts') + If @error = 1 Then + SetError(1) + Return '' + Else + + ;mgdebugCW($vDllAns[0] & @CRLF) + If $iReturnType = 1 Then + Return $vDllAns[0] + Else + Return StringSplit($vDllAns[0], '|') + EndIf + + + EndIf + Else + SetError(1) + Return '' + EndIf + + +EndFunc ;==>_CommListPorts + + +;=============================================================================== +; +; Function Name: _Commgetversion($iType = 1) +; Description: Gets the version of the dll if $iType = 1 +; Or the version of this UDF if $iType = 2 +; Parameters: $iType - integer: = 1 to reurn the commg2_2.dll version +; = 2 to return the UDF version +; Returns; on success - a string eg 'V1.3' +; on failure - an empty string and @error set to 1 + +;=============================================================================== + + +Func _CommGetVersion($iType = 1) + Local $vDllAns + If $iType = 2 Then Return $sUDFVersion + + If $fPortOpen Then + $vDllAns = DllCall($hDll, 'str', 'Version') + + If @error = 1 Then + SetError(1) + mgdebugCW('error in get version' & @CRLF) + Return '' + Else + ;mgdebugCW('length of version is ' & stringlen($vDllAns[0]) & @CRLF) + Return $vDllAns[0] + + EndIf + Else + $vDllAns = DllCall($DLLNAME, 'str', 'Version') + If @error = 1 Then + SetError(1) + mgdebugCW('error in get version' & @CRLF) + Return '' + Else + ;mgdebugCW('length of version is ' & stringlen($vDllAns[0]) & @CRLF) + Return $vDllAns[0] + EndIf + EndIf + + +EndFunc ;==>_CommGetVersion + +;=============================================================================== +; +; Function Name: _CommSwitch($channel) +;switches functions to operate on channel 1, 2, 3 to 50 +;returns on succes the channel switched to ie 1 or 2 +; on failure -1 +;Remarks on start up of script channel 1 is selected, so if you only need one COM port +; you don't need to use _CommSwitch +; each channel needs to be set up with _CommSetPort +; The same COM port cannot be used on more than one channel. +;When switch is used the first time on a channel number that port will be inactive +; and the port name will be '' (an empty string) until it is set with _CommSetport. +;The exception is that on creation channel 1 is always created and used as the +;port so switch is not needed unless more than one port is used. +; The channel number is not related to the COM port number, so channel 1 can +; be set to use COM2 and channel 4 can be set to use COM1 or any available port. +;Any channel number in the range 1 - 50 can be used, so it is possible to use +; the same channel number as the port number, ie switch(21) switches to COM21 +;====================================================================================== +Func _CommSwitch($channel) + Local $vDllAns + #cs remove section after fixing? comclose in dll + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + #ce + If $channel > 50 Then Return -1 + $vDllAns = DllCall($hDll, 'int', 'switch', 'int', $channel) + + If @error <> 0 Then + SetError(1) + Return -1 + Else + mgdebugCW("COM port selected now is " & _CommPortConnection() & @CRLF) + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSwitch + + + +;=========================================================================================================== +; +; Function Name: _CommSetport($iPort,ByRef $sErr,$iBaud=9600,$iBits=8,$ipar=0,$iStop=1,$iFlow=0,$RTSMode = 0,$DTRMode = 0) +; Description: Initialises the port and sets the parameters +; Parameters: $iPort - integer = the port or COM number to set. Allowed values are 1 or higher. +; NB WIndows refers To COM10 Or higher`as \\.\com10 but only use the number 10, 11 etc +; $sErr - string: the string to hold an error message if func fails. +; $iBaud - integer: the baud rate required. With commg.dll v2.3 and later any value allowed up to 256000. +; With v2.4 any value?? +; If using commg.dll before V2.3 then only allowed values are one of +; 50, 75, 110, 150, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600, 10400, +; 14400, 15625, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 256000 +; $iBits - integer: number of bits in code to be transmitted +; $iParity - integer: 0=None,1=Odd,2=Even,3=Mark,4=Space +; $iStop - integer: number of stop bits, 1=1 stop bit 2 = 2 stop bits, 15 = 1.5 stop bits +; $iFlow - integer: 0 sets hardware flow control, +; 1 sets XON XOFF control, +; 2 sets NONE i.e. no flow control. + +; $RTSMode 0= turns on the RTS line when the device is opened and leaves it on +; 1= RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. +; 2 = the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low. +; 3 = turns off the RTS line when the port is opened and leaves it off +; $DTRMode 0 = turns on the DTR line when the port is opened and leaves it on +; 1 = enables DTR handshaking +; 2 = disables the DTR line when the device is opened and leaves it disabled. +; Returns; on success - returns 1 and sets $sErr to '' +; on failure - returns 0 and with the error message in $sErr, and sets @error as follows +; @error meaning error with +; 1 dll call failed +; 2 dll was not open and could not be opened +; -1 $iBaud +; -2 $iStop +; -4 $iBits +; -8 $iPort = 0 not allowed +; -16 $iPort not found +; -32 $iPort access denied (in use?) +; -64 unknown error +;Remarks You cannot set the same COM port on more than one channel +;=========================================================================================================== + +Func _CommSetPort($iPort, ByRef $sErr, $iBaud = 9600, $iBits = 8, $iPar = 0, $iStop = 1, $iFlow = 0, $RTSMode = 0, $DTRMode = 0) + Local $vDllAns + $sErr = '' + + mgdebugCW("$fPortOpen = " & $fPortOpen & @CRLF) + If Not $fPortOpen Then + $hDll = DllOpen($DLLNAME) + If $hDll = -1 Then + SetError(2) + $sErr = 'Failed to open commg.dll' + Return 0;failed + EndIf + $fPortOpen = True + EndIf + mgdebugCW('port = ' & $iPort & ', baud = ' & $iBaud & ', bits = ' & $iBits & ', par = ' & $iPar & ', stop = ' & $iStop & ', flow = ' & $iFlow & @CRLF) + + $vDllAns = DllCall($hDll, 'int', 'SetPort', 'int', $iPort, 'int', $iBaud, 'int', $iBits, 'int', $iPar, 'int', $iStop, 'int', $iFlow, 'int', $RTSMode, 'int', $DTRMode) + If @error <> 0 Then + $sErr = 'dll SetPort call failed' + SetError(1) + Return 0 + EndIf + + If $vDllAns[0] < 0 Then + SetError($vDllAns[0]) + Switch $vDllAns[0] + Case -1 + $sErr = 'undefined baud rate' + Case -2 + $sErr = 'undefined stop bit number' + Case -4 + $sErr = 'undefined data size' + Case -8 + $sErr = 'port 0 not allowed' + Case -16 + $sErr = 'port does not exist' + Case -32 + $sErr = 'access denied, maybe port already in use' + Case -64 + $sErr = 'unknown error accessing port' + EndSwitch + Return 0 + Else + Return 1 + EndIf + +EndFunc ;==>_CommSetPort + + +;=================================================================================== +; +; Function Name: _CommPortConnection() +; Description: Gets the port connected to the selected channel - see _CommSwitch +; Parameters: None +; Returns; on success - a string eg 'COM5' +; on failure - an empty string and @error set to the rerror set by DllCall +; Remarks - Can be used to verify the port is connected + +;==================================================================================== + +Func _CommPortConnection() + Local $vDllAns + + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + + $vDllAns = DllCall($hDll, 'str', 'Connection');reply is port eg COM8 + + If @error <> 0 Then + SetError(@error) + Return '' + Else + Return $vDllAns[0] + EndIf + + +EndFunc ;==>_CommPortConnection + + + +;===================================================================================== +; +; Function Name: _CommSendString($sMGString,$iWaitComplete=0) +; Description: Sends a string to the connected port on the currently selected channel +; Parameters: $sMGString: the string to send sent without any extra CR or LF added. +; $iWaitComplete- integer:0 = do not wait till string sent +; 1 = wait till sent +; Returns: always 1 +; on success- @error set to 0 +; on failure - @error set to the error returned from DllCall +;====================================================================================== + +Func _CommSendString($sMGString, $iWaitComplete = 0) + ;sends $sMGString on the currently open port + ;returns 1 if ok, returns 0 if port not open/active + Local $vDllAns + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + If $sMGString = '' Then Return + mgdebugCW("pre sendstring " & @CRLF) + $vDllAns = DllCall($hDll, 'int', 'SendString', 'str', $sMGString, 'int', $iWaitComplete) + If @error <> 0 Then + mgdebugCW("past sendstring(1)" & @CRLF) + SetError(@error) + Return '' + Else + mgdebugCW("past sendstring(2)" & @CRLF) + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSendString + + + +;================================================================================ +; +; Function Name: _CommGetstring() +; Description: Get whatever characters are available received by the port for the selected channel +; Parameters: none +; Returns: on success the string and @error is 0 +; if input buffer empty then empty string returned +; on failure an empty string and @error set to the error set by DllCall +; Notes: Use _CommGetLine to get a whole line treminated by @CR or a defined character. +;================================================================================= + +Func _Commgetstring() + ;get a string NB could be part of a line depending on what is in buffer + Local $vDllAns + + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + ;$sStr1 = '' + ;$vDllAns = DllCall($hDll,'str','GetByte') + $vDllAns = DllCall($hDll, 'str', 'GetString') + + If @error <> 0 Then + SetError(1) + mgdebugCW('error in _commgetstring' & @CRLF) + Return '' + EndIf + Return $vDllAns[0] +EndFunc ;==>_Commgetstring + + +;==================================================================================== +; +; Function Name: _CommGetLine($EndChar = @CR,$maxlen = 0, $maxtime = 0) +; Description: Get a string ending in $EndChar +; Parameters: $EndChar the character to indicate the end of the string to return. +; The $EndChar character is included in the return string. +; $MaxLen - integer: the maximum length of a string before +; returning even if $linEnd not received +; If $maxlen is 0 then there is no max number of characters +; $maxtime - integer:the maximum time in mS to wait for the $EndChar before +; returning even if $linEnd not received. +; If $maxtime is 0 then there is no max time to wait +; +; Returns: on success the string and @error is 0 +; If $maxlen characters received without the $lineEnd character, then these +; characters are returned and @error is set To -1. +; If $maxtime passes without receiving the $lineEnd character, then the characters +; received so far are returned and @error is set To -2. +; on failure returns any characters received and sets @error to 1 +;====================================================================================== +Func _CommGetLine($sEndChar = @CR, $maxlen = 0, $maxtime = 0) + Local $vDllAns, $sLineRet, $sStr1, $waited, $sNextChar, $iSaveErr + + If Not $fPortOpen Then + SetError(1) + mgdebugCW("Port not open" & @CRLF) + Return 0 + EndIf + + $sStr1 = '' + $waited = TimerInit() + + While 1;stringinstr($sStr1,$EndChar) = 0 + If TimerDiff($waited) > $maxtime And $maxtime > 0 Then + SetError(-2) + mgdebugCW("Time Too long" & @CRLF) + Return $sStr1 + EndIf + + + If StringLen($sStr1) >= $maxlen And $maxlen > 0 Then + SetError(-1) + mgdebugCW("String to long" & @CRLF) + Return $sStr1 + EndIf + ;$ic = _CommGetInputCount() + + + $sNextChar = _CommReadChar() + $iSaveErr = @error + If $iSaveErr <> 0 Then + mgdebugCW("$iSaveErr = " & $iSaveErr & @CRLF) + EndIf + + If $iSaveErr = 0 And $sNextChar <> '' Then + + $sStr1 = $sStr1 & $sNextChar + mgdebugCW($sStr1 & @CRLF) + If $sNextChar = $sEndChar Then ExitLoop + + EndIf + + If $iSaveErr <> 0 And $iSaveErr <> 3 Then + SetError(1) + mgdebugCW("Errors" & @CRLF) + Return $sStr1 + EndIf + + if $snextchar = '' then sleep(20) + WEnd + + + + Return $sStr1 +EndFunc ;==>_CommGetLine + + + + + +;============================================================================ +; +; Function Name: _CommGetInputCount() +; Description: Get the number of characters available to be read from the port. +; Parameters: none +; Returns: on success a string conversion of the number of characters.(eg '0', '26') +; on failure returns an empty string and sets @error to 1 +;=============================================================================== + +Func _CommGetInputCount() + Local $vDllAns + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + +mgdebugCW("to dll getipcount"); + $vDllAns = DllCall($hDll, 'str', 'GetInputCount') + + If @error <> 0 Then + SetError(1) + Return 0 + Else + Return $vDllAns[0] + + EndIf + + +EndFunc ;==>_CommGetInputCount + + + +;============================================================================ +; +; Function Name: _CommGetOutputCount() +; Description: Get the number of characters waiting to be sent from the port. +; Parameters: none +; Returns: on success a string conversion of the number of characters.(eg '0', '26') +; on failure returns an empty string and sets @error to 1 +;=============================================================================== +Func _CommGetOutputCount() + Local $vDllAns + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + + $vDllAns = DllCall($hDll, 'str', 'GetOutputCount') + + If @error <> 0 Then + SetError(1) + Return '' + Else + Return $vDllAns[0] + EndIf + + +EndFunc ;==>_CommGetOutputCount + + +;================================================================================================ +; +; Function Name: _CommReadByte($wait = 0) + +; Description: Reads the byte as a string +; Parameters: $wait:integer if 0 then if no data to read then return -1 and set @error to 1 +; if <> 0 then does not return until a byte has been read +; Returns: on success a string conversion of the value of the byte read.(eg '0', '20') +; on failure +; if port not open or wait = 0 and no data to read sets @error to 1 and returns an empty string +; if DllCall failed returns empty string and sets @error to 2 +; if $wait is 0 and no data to read returns an empty string and sets @error to 1 if +; if $wait is not 0 returns a string containing imnformation on the $error if known +; and sets @error to 3. +; +; +;;NB could hang if nothing rec'd when wait is <> 0 +;================================================================================================== + +Func _CommReadByte($wait = 0) + Local $iCount, $vDllAns + If Not $fPortOpen Then + SetError(1) + Return '' + EndIf + +mgdebugCW("599 before get input count"); + If Not $wait Then + $iCount = _CommGetInputCount() + If @error = 1 Or $iCount = 0 Then + SetError(1) + Return '' + EndIf + EndIf +mgdebugCW("to dll getbyte"); + $vDllAns = DllCall($hDll, 'str', 'GetByte');GetByte returns the ascii code in string format for the next char + + If @error <> 0 Then + mgdebugCW("readbyte error = " & @error & @CRLF) + SetError(2) + Return '' + EndIf + + If StringLen($vDllAns[0]) > 3 or $vDllAns[0] > 255 Then ;Execute($vDllAns[0]) > 999 Then ; + ; mgdebugCW + mgdebugCW("getbyte call returned >" & $vDllAns[0] & @CRLF) + Return SetError(3, 0, $vDllAns[0]) + EndIf +;consolewrite("getbyte call returned >" & $vDllAns[0] & @CRLF) + Return $vDllAns[0] + +EndFunc ;==>_CommReadByte + +;============================================================================ +; +; Function Name: _CommReadChar($wait = 0) + +; Description: Reads the next Character as a string +; Parameters: $wait:integer if 0 then if no data to read then return -1 and set @error to 1 +; if <> 0 then does not return until a byte has been read +; Returns: on success a string of 1 character +; on failure returns empty string and sets @error to 1 +; +; +;;NB could hang if nothing rec'd when wait is <> 0 +;=============================================================================== + +Func _CommReadChar($wait = 0) + Local $sChar, $iErr + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf +mgdebugCW("will read byte"); + $sChar = _CommReadByte($wait) + + $iErr = @error + ; + + If $iErr > 2 Then + mgdebugCW("$iErr = " & $iErr & @CR) + SetError(1) + Return '' + EndIf + mgdebugCW(Chr(Execute($sChar)) & @CRLF) + If $iErr == 0 Then Return Chr(Execute($sChar)) +EndFunc ;==>_CommReadChar + + +;============================================================================ +; Function Name: SendByte($byte,$iWaitComplete=0) + +; Description: Sends the byte value of $byte. $byte must be in range 0 to 255 +; Parameters: $byte the byte to send. +; $iWaitComplete - integer: if 0 then functions returns without +; waiting for byte to be sent +; If <> 0 then waits till byte sent. +; Returns: on success returns 1 +; on failure returns -1 and sets @error to 1 +; +;;NB could hang if byte cannot be sent and $iWaitComplete <> 0 +;=============================================================================== +Func _CommSendByte($byte, $iWaitComplete = 0) + Local $vDllAns + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + $vDllAns = DllCall($hDll, 'int', 'SendByte', 'int', $byte, 'int', $iWaitComplete) + If @error <> 0 Then + SetError(1) + Return -1 + Else + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSendByte + + +;=============================================================================== +; Function Name: _CommSendByteArray($pAddr,$iNum,$iWait) + +; Description: Sends the bytes from address $pAddress +; Parameters: $iNum the number of bytes to send. +; $iWaitComplete - integer: if 0 then functions returns without +; waiting for bytes to be sent +; if <> 0 then waits until all bytes are sent. +; Returns: on success returns 1 +; on failure returns -1 and sets @error to 1 +; +;;NB could hang if byte cannot be sent and $iWaitComplete <> 0 +; could lose data if you send more bytes than the size of the outbuffer. +; the output buffer size is 2048 +;=============================================================================== +Func _CommSendByteArray($pAddr, $iNum, $iWait) + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + Local $vDllAns = DllCall($hDll, 'int', 'SendByteArray', 'ptr', $pAddr, 'int', $iNum, 'int', $iWait) + If @error <> 0 Or $vDllAns[0] = -1 Then + SetError(1) + Return -1 + Else + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSendByteArray + + + +;==================================================================================== +; Function Name: _CommReadByteArray($pAddr,$iNum,$iWait) +; +; Description: Reads bytes and writes them to memory starting at address $pAddress +; Parameters: $iNum the number of bytes to read. +; $iWaitComplete - integer: if 0 then the functions returns +; with the available bytes up to $iNum. +; if 1 then waits until the $iNum bytes received. +; Returns: on success returns the Number of bytes read. +; on failure returns -1 and sets @error to 1 +; +;;NB could hang if bytes are not received and $iWaitComplete <> 0 +; the input buffer size is 4096 +;==================================================================================== +Func _CommReadByteArray($pAddr, $iNum, $iWait) + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + Local $vDllAns = DllCall($hDll, 'int', 'ReadByteArray', 'ptr', $pAddr, 'int', $iNum, 'int', $iWait) + If @error <> 0 Or $vDllAns[0] = -1 Then + SetError(1) + Return -1 + Else + Return $vDllAns[0] + EndIf + + + +EndFunc ;==>_CommReadByteArray + + + + +;=============================================================================== +; Function Name: ClearOutputBuffer() + +; Description: Clears any characters in the out put queue5 +; Parameters: none +; Returns: on success returns 1 +; on failure returns -1 and sets @error to 1 +; +;=============================================================================== +Func _CommClearOutputBuffer() + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + Local $vDllAns = DllCall($hDll, 'int', 'ClearOutputBuffer') + +EndFunc ;==>_CommClearOutputBuffer + +Func _CommClearInputBuffer() + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + Local $vDllAns = DllCall($hDll, 'int', 'ClearInputBuffer') + If @error <> 0 Then + Return -1 + Else + Return 1 + EndIf + +EndFunc ;==>_CommClearInputBuffer + + + + +;=============================================================================== +; Function Name: ClosePort()@@@@@@@@@to be improved or replaced. Should have parameter for channel to close and new fn for closedown +; Parameters +; TODO ?? $fAll if set to true or non zero then + +; Description: closes currently selected port +; Remarks: +; +; Parameters: none + +; Returns: no return value +;=============================================================================== +Func _CommClosePort($fAll = False) + Local $closeAll + ;mgdebugCW("Closing port" & @CRLF) + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + If $fAll Then + $closeAll = 1 + Else + $closeAll = 0 + EndIf + + + _CommClearOutputBuffer() + _CommClearInputBuffer() + + DllCall($hDll, 'int', 'CloseDown', 'int', $closeAll);close all ports + + If @error <> 0 Then ConsoleWrite("Error closing dll" & @CRLF) + $fPortOpen = False + if $fAll then DllClose($hDll) + +EndFunc ;==>_CommClosePort + + + +;================================================================================================ +; Function Name: SendBreak($iDowTime,$iUpTime) +; NB Simulates the break signal used by some equipment to indicate the start of a sequence +; Not tested so might Not work. Any feedback welcome - PM martin on Autoit forum + +; Description: sets the TX line low for $iDowTime, then sets it high for $iUpTime + +; Parameters: $iDowTime - integer: the number of ms to hold the TX line down +; $iUpTime - integer: the number of ms to hold the line up for before returning +; if $iDowTime or $iUpTime is zero then does nothing and returns +; Returns: on success returns 1 +; on failure returns 0 and sets @error to +; = 1 if one of params is zero +; = 2 1 unable to use the DLL file, +; = 3 unknown "return type" from dll +; = 4 "function" not found in the DLL file. + +; Notes : Not tested! +;================================================================================================ +Func _CommSendBreak($iDowTime, $iUpTime);requirescommg2_2.dllv2.0 or later + Local $vDllAns + If $iDowTime = 0 Or $iUpTime = 0 Then + SetError(1) + Return 0 + EndIf + + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + $vDllAns = DllCall($hDll, 'int', 'SendBreak', 'int', $iDowTime, 'int', $iUpTime) + If @error <> 0 Then + SetError(@error + 1) + Return 0 + Else + ;mgdebugCW('done setbreak' & @CRLF) + Return 1;success + EndIf + +EndFunc ;==>_CommSendBreak + + +;=========== _CommSetBufferSizes ======================================================================================================== +; Description: Sets the buffer sizes for the current channel +;Parameters - $InputLen - the maximum number of bytes which can be received and waiting to be read +; - $OutPutLen - the number of bytes which can be qued waiting to be transmitted; +;Return 1 on success +; 0 on failure +;============================================================================================================================================================= +Func _CommSetBufferSizes($InPutLen, $OututLen = 2048) + Local $vDllAns = DllCall($hDll, 'int', 'SetBufSizes', 'int', $InPutLen, 'int', $OututLen) + If @error <> 0 Then + SetError(@error + 1) + Return 0 + Else + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSetBufferSizes + +;=========== _CommSetTimeouts ======================================================================================================== +; Description: Sets the timeouts for the current channel +;Parameters - ReadInt - maximum time allowed to elapse between the arrival of two characters +; - ReadMult - multiplier used to calculate the total timeout period for read operations. +; For each read operation, this value is multiplied by the requested number of bytes to be read. +; - ReadConst - constant used to calculate the total timeout period for read operations. +; For each read operation, this value is added to the product of the ReadMultiplier member and the requested number of bytes. +; - WriteMult - multiplier used to calculate the total timeout period for write operations. +; For each write operation, this value is multiplied by the number of bytes to be written. +; - WriteConst - constant used to calculate the total time-out period for write operations. +; For each write operation, this value is added to the product of the WriteMultiplier member and the number of bytes to be written. +; if a parameter is set to 0 it means that timeout will not be used. All values are at zero when a port is opened. +; Return 1 on success +; 0 on failure +;============================================================================================================================================================= +Func _CommSetTimeouts($ReadInt = 0, $ReadMult = 0, $ReadConst = 0, $WriteMult = 0, $WriteConst = 0) + Local $vDllAns + + If Not $fPortOpen Then + SetError(1) + Return 0 + EndIf + + $vDllAns = DllCall($hDll, 'int', 'SetTimeouts', 'int', $ReadInt, 'int', $ReadMult, 'int', $ReadConst, 'int', $WriteMult, 'int', $WriteConst) + If @error <> 0 Then + SetError(@error + 1) + Return 0 + Else + Return $vDllAns[0] + EndIf +EndFunc ;==>_CommSetTimeouts + + +;====================== SetXonXoffProperties ======================================================================= +; Description: Set the values used for the XON and XOFF characters, and when these charactyers are to be transmitted +; Parameters - $XonChar - the ASCII code for the character to be sent to indicate the port is ready to receive +; - $XoffChar - the ASCII code for the character to be sent to stop receiving +; - $XonStart - when the number of characters in the input buffer falls below this value the XonChar will be sent +; - $XoffStop - when the number of bytes free in the input buffer falls below this value the XoffChar will be sent +;When a port is opened the values are as the defaults for the function. +;Return - on success 1 +; - on error 0 if error making dllcall and @error set to 1 +; -1 illegal XonChar value +; -2 illegal XoffChar value +; +Func _CommSetXonXoffProperties($XonChar = 0x11, $XoffChar = 0x13, $XonStart = 0, $XoffStop = 0) + Local $vDllAns + + + + If $XonChar > 255 Or $XonChar < 0 Then Return -1 + If $XoffChar > 255 Or $XoffChar < 0 Then Return -2 + + + $vDllAns = DllCall($hDll, 'int', 'SetXonXoffProperties', 'byte', $XonChar, 'byte', $XoffChar, 'int', $XonStart, 'int', $XoffStop) + If @error <> 0 Then + SetError(@error + 1) + Return 0 + Else + Return $vDllAns[0] + EndIf + +EndFunc ;==>_CommSetXonXoffProperties + +Func mgdebugCW($sDB) + If Not $mgdebug Then Return + ConsoleWrite($sDB) + +EndFunc ;==>mgdebugCW + + + +;=================================================================================== +; +; Function Name: _CommSetRTS() +; Description: Sets or restets the RTS signal for to the selected channel - see _CommSwitch +; Parameters: $iSet = 1 to set 0 to reset +; Returns; 1 on success +; on failure -1 and @error set to 1 +; Notes Only works if flow control is set to NONE or XON/XOFF. Ie not for hardware handshaking. +;==================================================================================== + +Func _CommSetRTS($iSet) + Local $vDllAns + + If Not $fPortOpen Then + SetError(1) + Return -1 + EndIf + + + $vDllAns = DllCall($hDll, 'int', 'SetRTS', 'int', $iSet) + + If @error <> 0 Then + SetError(1) + Return -1 + Else + Return 1 + EndIf + + +EndFunc ;==>_CommSetRTS + + +;=================================================================================== +; +; Function Name: _CommSetDTR() +; Description: Sets or restets the DTR signal for to the selected channel - see _CommSwitch +; Parameters: $iSet = 1 to set 0 to reset +; Returns; 1 on success +; on failure -1 and @error set to 1 +; Notes Only works if flow control is set to NONE or XON/XOFF. Ie not for hardware handshaking. +;==================================================================================== + +Func _CommSetDTR($iSet) + Local $vDllAns + + If Not $fPortOpen Then + SetError(1) + Return -1 + EndIf + + + $vDllAns = DllCall($hDll, 'int', 'SetDTR', 'int', $iSet) + + If @error <> 0 Then + SetError(1) + Return -1 + Else + Return 1 + EndIf + + +EndFunc ;==>_CommSetDTR + +;=================================================================================== +; +; Function Name: _CommGetLIneStates() +; Description: Gets the states of 4 signals +; Parameters: none +; Returns; on success +; returns an array with 4 elements giving the state of the lines CTS, DSR, Ring Indicator and DCD +; in that order. Value True = ON, value False = OFF +; on failure +; returns -1 and @error set to 1 +;==================================================================================== +Func _CommGetLineStates() + Local $vDllAns + Local $iL, $aStates[4] + + If Not $fPortOpen Then + SetError(1) + Return -1 + EndIf + + + $vDllAns = DllCall($hDll, 'int', 'GetLineStates') + + If @error <> 0 Then + SetError(1) + Return -1 + EndIf + mgdebugCW($vDllAns[0] & @CRLF) + For $iL = 0 To 3 + $aStates[$iL] = BitAND($vDllAns[0], 2 ^ $iL) <> 0 + Next + Return $aStates + +EndFunc ;==>_CommGetLineStates + + +; ===================================================================================================================== +; Name........................: _ComGetPortNames +; Description ................: Lists all com ports or a single com port and the names to a 2D array +; Syntax......................: _GetComPorts($sComPort = 0) +; Parameters .................: $sComPort - Either 0 or "" for all ports or a number for a particular port, eg 12 or a string "COM12" +; Return on success ..........: an array (size depends on $sComPort) +; Return on Failure ..........: an empty string "" and sets @error to +; -1 incorrect parameter +; 1 no COM Ports found +; 2 specified COM port not found. +; Author .....................: funkey, 2010, Nov 29th +; Modified....................: by martin and renamed from _GetComPorts to _ComGetPortNames, 14th December 2010 +; Remarks ....................: +; Related ....................: +; Link to original function...: http://www.autoitscript.com/forum/topic/122663-getcomports/page__view__findpost__p__851620 +; Example ....................: Yes see below +; +; ======================================================================================================================== + + +Func _ComGetPortNames($sComPort = "") + + Local $objWMIService, $colItems, $stempName, $aTemp, $sRet, $iCount + + If IsInt($sComPort) Then + If $sComPort = 0 Then + $sComPort = "" + Else + $sComPort = "COM" & $sComPort + EndIf + EndIf + + + If $sComPort <> "" And Not StringIsInt(StringReplace($sComPort, "COM", "")) Then Return SetError(-1, 0, "") + + $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") + $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%" & StringReplace($sComPort, "COM", "") & ")'", "WQL", 48) + + For $objItem In $colItems + $sRet &= $objItem.Name & @CR + Next + + If $sRet = "" Then Return SetError(1, 0, "") + + If $sComPort <> "" And Not StringInStr($sRet, "(" & $sComPort & ")") Then Return SetError(2, 0, "") + + + $aTemp = StringSplit($sRet, @CR, 2) + Dim $aRet[UBound($aTemp) - 1][2] + + $iCount = 0 + For $i = 0 To UBound($aTemp) - 2 + $stempName = StringTrimLeft($aTemp[$i], StringInStr($aTemp[$i], "(", 0, -1) - 1);StringTrimRight(, 1) + + If $sComPort = "" Or $stempName = "(" & $sComPort & ")" Then + $aRet[$i][0] = StringTrimRight(StringTrimLeft($stempName, StringInStr($stempName, "(", 0, -1)), 1) + $aRet[$i][1] = StringLeft($aTemp[$i], StringInStr($aTemp[$i], "(", 0, -1) - 2) + $iCount += 1 + EndIf + Next + + ReDim $aRet[$iCount][2] + Return $aRet +EndFunc ;==>_ComGetPortNames +;======================================================================================================================= + + +#cs =============_ComGetPortNames example start=============================== + #include + + Local $aComPort = _ComGetPortNames() + _ArrayDisplay($aComPort) + Local $sComPort = _ComGetPortNames("COM1") + If @error Then + MsgBox(16, "Error " & @error, "No matching COM port found.") + Else + ConsoleWrite($sComPort & @CRLF) + EndIf +#ce =============_GetComPorts example end=============================== +Opt("MustDeclareVars", 0) \ No newline at end of file diff --git a/src/include/EditConstants.au3 b/src/include/EditConstants.au3 new file mode 100644 index 0000000..e470b93 --- /dev/null +++ b/src/include/EditConstants.au3 @@ -0,0 +1,120 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: Edit_Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: GUI control Edit/Input styles and much more constants. +; Author(s) .....: Valik, Gary Frost, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +; Styles +Global Const $ES_LEFT = 0 +Global Const $ES_CENTER = 1 +Global Const $ES_RIGHT = 2 +Global Const $ES_MULTILINE = 4 +Global Const $ES_UPPERCASE = 8 +Global Const $ES_LOWERCASE = 16 +Global Const $ES_PASSWORD = 32 +Global Const $ES_AUTOVSCROLL = 64 +Global Const $ES_AUTOHSCROLL = 128 +Global Const $ES_NOHIDESEL = 256 +Global Const $ES_OEMCONVERT = 1024 +Global Const $ES_READONLY = 2048 +Global Const $ES_WANTRETURN = 4096 +Global Const $ES_NUMBER = 8192 +; Global Const $ES_DISABLENOSCROLL = 8192 +; Global Const $ES_SUNKEN = 16384 +; Global Const $ES_VERTICAL = 4194304 +; Global Const $ES_SELECTIONBAR = 16777216 + +; Error checking +Global Const $EC_ERR = -1 + +; Messages to send to edit control +Global Const $ECM_FIRST = 0X1500 +Global Const $EM_CANUNDO = 0xC6 +Global Const $EM_CHARFROMPOS = 0xD7 +Global Const $EM_EMPTYUNDOBUFFER = 0xCD +Global Const $EM_FMTLINES = 0xC8 +Global Const $EM_GETCUEBANNER = ($ECM_FIRST + 2) +Global Const $EM_GETFIRSTVISIBLELINE = 0xCE +Global Const $EM_GETHANDLE = 0xBD +Global Const $EM_GETIMESTATUS = 0xD9 +Global Const $EM_GETLIMITTEXT = 0xD5 +Global Const $EM_GETLINE = 0xC4 +Global Const $EM_GETLINECOUNT = 0xBA +Global Const $EM_GETMARGINS = 0xD4 +Global Const $EM_GETMODIFY = 0xB8 +Global Const $EM_GETPASSWORDCHAR = 0xD2 +Global Const $EM_GETRECT = 0xB2 +Global Const $EM_GETSEL = 0xB0 +Global Const $EM_GETTHUMB = 0xBE +Global Const $EM_GETWORDBREAKPROC = 0xD1 +Global Const $EM_HIDEBALLOONTIP = ($ECM_FIRST + 4) +Global Const $EM_LIMITTEXT = 0xC5 +Global Const $EM_LINEFROMCHAR = 0xC9 +Global Const $EM_LINEINDEX = 0xBB +Global Const $EM_LINELENGTH = 0xC1 +Global Const $EM_LINESCROLL = 0xB6 +Global Const $EM_POSFROMCHAR = 0xD6 +Global Const $EM_REPLACESEL = 0xC2 +Global Const $EM_SCROLL = 0xB5 +Global Const $EM_SCROLLCARET = 0x00B7 +Global Const $EM_SETCUEBANNER = ($ECM_FIRST + 1) +Global Const $EM_SETHANDLE = 0xBC +Global Const $EM_SETIMESTATUS = 0xD8 +Global Const $EM_SETLIMITTEXT = $EM_LIMITTEXT +Global Const $EM_SETMARGINS = 0xD3 +Global Const $EM_SETMODIFY = 0xB9 +Global Const $EM_SETPASSWORDCHAR = 0xCC +Global Const $EM_SETREADONLY = 0xCF +Global Const $EM_SETRECT = 0xB3 +Global Const $EM_SETRECTNP = 0xB4 +Global Const $EM_SETSEL = 0xB1 +Global Const $EM_SETTABSTOPS = 0xCB +Global Const $EM_SETWORDBREAKPROC = 0xD0 +Global Const $EM_SHOWBALLOONTIP = ($ECM_FIRST + 3) +Global Const $EM_UNDO = 0xC7 + +; Params +Global Const $EC_LEFTMARGIN = 0x1 +Global Const $EC_RIGHTMARGIN = 0x2 +Global Const $EC_USEFONTINFO = 0xFFFF + +Global Const $EMSIS_COMPOSITIONSTRING = 0x1 + +; Status +Global Const $EIMES_GETCOMPSTRATONCE = 0x1 ; If this flag is set, the edit control hooks the WM_IME_COMPOSITION message with fFlags set to GCS_RESULTSTR and returns the result string immediately +Global Const $EIMES_CANCELCOMPSTRINFOCUS = 0x2 ; If this flag is set, the edit control cancels the composition string when it receives the WM_SETFOCUS message. +Global Const $EIMES_COMPLETECOMPSTRKILLFOCUS = 0x4 ; If this flag is set, the edit control completes the composition string upon receiving the WM_KILLFOCUS message. + +; Notifications +Global Const $EN_ALIGN_LTR_EC = 0x700 +Global Const $EN_ALIGN_RTL_EC = 0x701 +Global Const $EN_CHANGE = 0x300 +Global Const $EN_ERRSPACE = 0x500 +Global Const $EN_HSCROLL = 0X601 +Global Const $EN_KILLFOCUS = 0x200 +Global Const $EN_MAXTEXT = 0x501 +Global Const $EN_SETFOCUS = 0x100 +Global Const $EN_UPDATE = 0x400 +Global Const $EN_VSCROLL = 0x602 + +; Edit Balloon Tool Tip Icons +; move in ToolTipConstants.au3 + +; Global Const $TTI_NONE = 0 +; Global Const $TTI_INFO = 1 +; Global Const $TTI_WARNING = 2 +; Global Const $TTI_ERROR = 3 +; Vista Edit Balloon Tool Tip Icons +; Global Const $TTI_INFO_LARGE = 4 +; Global Const $TTI_WARNING_LARGE = 5 +; Global Const $TTI_ERROR_LARGE = 6 + +; Control default styles +Global Const $GUI_SS_DEFAULT_EDIT = 0x003010c0 ; BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL) +Global Const $GUI_SS_DEFAULT_INPUT = 0x00000080 ; BitOR($ES_LEFT, $ES_AUTOHSCROLL) +; =============================================================================================================================== diff --git a/src/include/File.au3 b/src/include/File.au3 new file mode 100644 index 0000000..f886cc2 --- /dev/null +++ b/src/include/File.au3 @@ -0,0 +1,1077 @@ +#include-once + +#include "Array.au3" +#include "FileConstants.au3" +#include "StringConstants.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: File +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with files and directories. +; Author(s) .....: Brian Keene, Michael Michta, erifash, Jon, JdeB, Jeremy Landes, MrCreatoR, cdkid, Valik, Erik Pilsits, Kurt, Dale, guinness, DXRW4E, Melba23 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _FileCountLines +; _FileCreate +; _FileListToArray +; _FileListToArrayRec +; _FilePrint +; _FileReadToArray +; _FileWriteFromArray +; _FileWriteLog +; _FileWriteToLine +; _PathFull +; _PathGetRelative +; _PathMake +; _PathSplit +; _ReplaceStringInFile +; _TempFile +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY#============================================================================================================ +; __FLTAR_ListToMask +; __FLTAR_AddToList +; __FLTAR_AddFileLists +; =============================================================================================================================== + +; #FUNCTION# ==================================================================================================================== +; Author ........: Tylo +; Modified.......: Xenobiologist, Gary, guinness, DXRW4E +; =============================================================================================================================== +Func _FileCountLines($sFilePath) + Local $hFileOpen = FileOpen($sFilePath, $FO_READ) + If $hFileOpen = -1 Then Return SetError(1, 0, 0) + + Local $sFileRead = StringStripWS(FileRead($hFileOpen), $STR_STRIPTRAILING) + FileClose($hFileOpen) + Return UBound(StringRegExp($sFileRead, "\R", $STR_REGEXPARRAYGLOBALMATCH)) + 1 - Int($sFileRead = "") +EndFunc ;==>_FileCountLines + +; #FUNCTION# ==================================================================================================================== +; Author ........: Brian Keene +; Modified.......: +; =============================================================================================================================== +Func _FileCreate($sFilePath) + Local $hFileOpen = FileOpen($sFilePath, BitOR($FO_OVERWRITE, $FO_CREATEPATH)) + If $hFileOpen = -1 Then Return SetError(1, 0, 0) + + Local $iFileWrite = FileWrite($hFileOpen, "") + FileClose($hFileOpen) + If Not $iFileWrite Then Return SetError(2, 0, 0) + Return 1 +EndFunc ;==>_FileCreate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Michael Michta +; Modified.......: guinness - Added optional parameter to return the full path. +; =============================================================================================================================== +Func _FileListToArray($sFilePath, $sFilter = "*", $iFlag = $FLTA_FILESFOLDERS, $bReturnPath = False) + Local $sDelimiter = "|", $sFileList = "", $sFileName = "", $sFullPath = "" + + ; Check parameters for the Default keyword or they meet a certain criteria + $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+$", "") & "\" ; Ensure a single trailing backslash + If $iFlag = Default Then $iFlag = $FLTA_FILESFOLDERS + If $bReturnPath Then $sFullPath = $sFilePath + If $sFilter = Default Then $sFilter = "*" + + ; Check if the directory exists + If Not FileExists($sFilePath) Then Return SetError(1, 0, 0) + If StringRegExp($sFilter, "[\\/:><\|]|(?s)^\s*$") Then Return SetError(2, 0, 0) + If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 0, 0) + Local $hSearch = FileFindFirstFile($sFilePath & $sFilter) + If @error Then Return SetError(4, 0, 0) + While 1 + $sFileName = FileFindNextFile($hSearch) + If @error Then ExitLoop + If ($iFlag + @extended = 2) Then ContinueLoop + $sFileList &= $sDelimiter & $sFullPath & $sFileName + WEnd + FileClose($hSearch) + If $sFileList = "" Then Return SetError(4, 0, 0) + Return StringSplit(StringTrimLeft($sFileList, 1), $sDelimiter) +EndFunc ;==>_FileListToArray + +; #FUNCTION# ==================================================================================================================== +; Author ........: Melba23 - with credits for code snippets to Ultima, Partypooper, Spiff59, guinness, wraithdu +; Modified ......: +; =============================================================================================================================== +Func _FileListToArrayRec($sFilePath, $sMask = "*", $iReturn = $FLTAR_FILESFOLDERS, $iRecur = $FLTAR_NORECUR, $iSort = $FLTAR_NOSORT, $iReturnPath = $FLTAR_RELPATH) + If Not FileExists($sFilePath) Then Return SetError(1, 1, "") + + ; Check for Default keyword + If $sMask = Default Then $sMask = "*" + If $iReturn = Default Then $iReturn = $FLTAR_FILESFOLDERS + If $iRecur = Default Then $iRecur = $FLTAR_NORECUR + If $iSort = Default Then $iSort = $FLTAR_NOSORT + If $iReturnPath = Default Then $iReturnPath = $FLTAR_RELPATH + + ; Check for valid recur value + If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 6, "") + + Local $bLongPath = False + ; Check for valid path + If StringLeft($sFilePath, 4) == "\\?\" Then + $bLongPath = True + EndIf + + Local $sFolderSlash = "" + ; Check if folders should have trailing \ and ensure that initial path does have one + If StringRight($sFilePath, 1) = "\" Then + $sFolderSlash = "\" + Else + $sFilePath = $sFilePath & "\" + EndIf + + Local $asFolderSearchList[100] = [1] + ; Add path to folder search list + $asFolderSearchList[1] = $sFilePath + + Local $iHide_HS = 0, _ + $sHide_HS = "" + ; Check for H or S omitted + If BitAND($iReturn, 4) Then + $iHide_HS += 2 + $sHide_HS &= "H" + $iReturn -= 4 + EndIf + If BitAND($iReturn, 8) Then + $iHide_HS += 4 + $sHide_HS &= "S" + $iReturn -= 8 + EndIf + + Local $iHide_Link = 0 + ; Check for link/junction omitted + If BitAND($iReturn, 16) Then + $iHide_Link = 0x400 + $iReturn -= 16 + EndIf + + Local $iMaxLevel = 0 + ; If required, determine \ count for max recursive level setting + If $iRecur < 0 Then + StringReplace($sFilePath, "\", "", 0, $STR_NOCASESENSEBASIC) + $iMaxLevel = @extended - $iRecur + EndIf + + Local $sExclude_List = "", $sExclude_List_Folder = "", $sInclude_List = "*" + ; Check mask parameter + Local $aMaskSplit = StringSplit($sMask, "|") + ; Check for multiple sections and set values + Switch $aMaskSplit[0] + Case 3 + $sExclude_List_Folder = $aMaskSplit[3] + ContinueCase + Case 2 + $sExclude_List = $aMaskSplit[2] + ContinueCase + Case 1 + $sInclude_List = $aMaskSplit[1] + EndSwitch + + Local $sInclude_File_Mask = ".+" + ; Create Include mask for files + If $sInclude_List <> "*" Then + If Not __FLTAR_ListToMask($sInclude_File_Mask, $sInclude_List) Then Return SetError(1, 2, "") + EndIf + + Local $sInclude_Folder_Mask = ".+" + ; Set Include mask for folders + Switch $iReturn + Case 0 + ; Folders affected by mask if not recursive + Switch $iRecur + Case 0 + ; Folders match mask for compatibility + $sInclude_Folder_Mask = $sInclude_File_Mask + EndSwitch + Case 2 + ; Folders affected by mask + $sInclude_Folder_Mask = $sInclude_File_Mask + EndSwitch + + Local $sExclude_File_Mask = ":" + ; Create Exclude List mask for files + If $sExclude_List <> "" Then + If Not __FLTAR_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 3, "") + EndIf + + Local $sExclude_Folder_Mask = ":" + ; Create Exclude mask for folders + If $iRecur Then + If $sExclude_List_Folder Then + If Not __FLTAR_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 4, "") + EndIf + ; If folders only + If $iReturn = 2 Then + ; Folders affected by normal mask + $sExclude_Folder_Mask = $sExclude_File_Mask + EndIf + Else + ; Folders affected by normal mask + $sExclude_Folder_Mask = $sExclude_File_Mask + EndIf + + ; Verify other parameters + If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 5, "") + If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 7, "") + If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 8, "") + + ; Prepare for DllCall if required + If $iHide_Link Then + Local $tFile_Data = DllStructCreate("struct;align 4;dword FileAttributes;uint64 CreationTime;uint64 LastAccessTime;uint64 LastWriteTime;" & _ + "dword FileSizeHigh;dword FileSizeLow;dword Reserved0;dword Reserved1;wchar FileName[260];wchar AlternateFileName[14];endstruct") + Local $hDLL = DllOpen('kernel32.dll'), $aDLL_Ret + EndIf + + Local $asReturnList[100] = [0] + Local $asFileMatchList = $asReturnList, $asRootFileMatchList = $asReturnList, $asFolderMatchList = $asReturnList + Local $bFolder = False, _ + $hSearch = 0, _ + $sCurrentPath = "", $sName = "", $sRetPath = "" + Local $iAttribs = 0, _ + $sAttribs = '' + Local $asFolderFileSectionList[100][2] = [[0, 0]] + ; Search within listed folders + While $asFolderSearchList[0] > 0 + + ; Set path to search + $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]] + ; Reduce folder search list count + $asFolderSearchList[0] -= 1 + ; Determine return path to add to file/folder name + Switch $iReturnPath + ; Case 0 ; Name only + ; Leave as "" + Case 1 ;Relative to initial path + $sRetPath = StringReplace($sCurrentPath, $sFilePath, "") + Case 2 ; Full path + If $bLongPath Then + $sRetPath = StringTrimLeft($sCurrentPath, 4) + Else + $sRetPath = $sCurrentPath + EndIf + EndSwitch + + ; Get search handle - use code matched to required listing + If $iHide_Link Then + ; Use DLL code + $aDLL_Ret = DllCall($hDLL, 'handle', 'FindFirstFileW', 'wstr', $sCurrentPath & "*", 'struct*', $tFile_Data) + If @error Or Not $aDLL_Ret[0] Then + ContinueLoop + EndIf + $hSearch = $aDLL_Ret[0] + Else + ; Use native code + $hSearch = FileFindFirstFile($sCurrentPath & "*") + ; If folder empty move to next in list + If $hSearch = -1 Then + ContinueLoop + EndIf + EndIf + + ; If sorting files and folders with paths then store folder name and position of associated files in list + If $iReturn = 0 And $iSort And $iReturnPath Then + __FLTAR_AddToList($asFolderFileSectionList, $sRetPath, $asFileMatchList[0] + 1) + EndIf + $sAttribs = '' + + ; Search folder - use code matched to required listing + While 1 + ; Use DLL code + If $iHide_Link Then + ; Use DLL code + $aDLL_Ret = DllCall($hDLL, 'int', 'FindNextFileW', 'handle', $hSearch, 'struct*', $tFile_Data) + ; Check for end of folder + If @error Or Not $aDLL_Ret[0] Then + ExitLoop + EndIf + ; Extract data + $sName = DllStructGetData($tFile_Data, "FileName") + ; Check for .. return - only returned by the DllCall + If $sName = ".." Then + ContinueLoop + EndIf + $iAttribs = DllStructGetData($tFile_Data, "FileAttributes") + ; Check for hidden/system attributes and skip if found + If $iHide_HS And BitAND($iAttribs, $iHide_HS) Then + ContinueLoop + EndIf + ; Check for link attribute and skip if found + If BitAND($iAttribs, $iHide_Link) Then + ContinueLoop + EndIf + ; Set subfolder flag + $bFolder = False + If BitAND($iAttribs, 16) Then + $bFolder = True + EndIf + Else + ; Reset folder flag + $bFolder = False + ; Use native code + $sName = FileFindNextFile($hSearch, 1) + ; Check for end of folder + If @error Then + ExitLoop + EndIf + $sAttribs = @extended + ; Check for folder + If StringInStr($sAttribs, "D") Then + $bFolder = True + EndIf + ; Check for Hidden/System + If StringRegExp($sAttribs, "[" & $sHide_HS & "]") Then + ContinueLoop + EndIf + EndIf + + ; If folder then check whether to add to search list + If $bFolder Then + Select + Case $iRecur < 0 ; Check recur depth + StringReplace($sCurrentPath, "\", "", 0, $STR_NOCASESENSEBASIC) + If @extended < $iMaxLevel Then + ContinueCase ; Check if matched to masks + EndIf + Case $iRecur = 1 ; Full recur + If Not StringRegExp($sName, $sExclude_Folder_Mask) Then ; Add folder unless excluded + __FLTAR_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\") + EndIf + ; Case $iRecur = 0 ; Never add + ; Do nothing + EndSelect + EndIf + + If $iSort Then ; Save in relevant folders for later sorting + If $bFolder Then + If StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then + __FLTAR_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash) + EndIf + Else + If StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then + ; Select required list for files + If $sCurrentPath = $sFilePath Then + __FLTAR_AddToList($asRootFileMatchList, $sRetPath & $sName) + Else + __FLTAR_AddToList($asFileMatchList, $sRetPath & $sName) + EndIf + EndIf + EndIf + Else ; Save directly in return list + If $bFolder Then + If $iReturn <> 1 And StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then + __FLTAR_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash) + EndIf + Else + If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then + __FLTAR_AddToList($asReturnList, $sRetPath & $sName) + EndIf + EndIf + EndIf + + WEnd + + ; Close current search + If $iHide_Link Then + DllCall($hDLL, 'int', 'FindClose', 'ptr', $hSearch) + Else + FileClose($hSearch) + EndIf + + WEnd + + ; Close the DLL if needed + If $iHide_Link Then + DllClose($hDLL) + EndIf + + ; Sort results if required + If $iSort Then + Switch $iReturn + Case 2 ; Folders only + ; Check if any folders found + If $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "") + ; Correctly size folder match list + ReDim $asFolderMatchList[$asFolderMatchList[0] + 1] + ; Copy size folder match array + $asReturnList = $asFolderMatchList + ; Simple sort list + __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0]) + Case 1 ; Files only + ; Check if any files found + If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 Then Return SetError(1, 9, "") + If $iReturnPath = 0 Then ; names only so simple sort suffices + ; Combine file match lists + __FLTAR_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList) + ; Simple sort combined file list + __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0]) + Else + ; Combine sorted file match lists + __FLTAR_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1) + EndIf + Case 0 ; Both files and folders + ; Check if any root files or folders found + If $asRootFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "") + If $iReturnPath = 0 Then ; names only so simple sort suffices + ; Combine file match lists + __FLTAR_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList) + ; Set correct count for folder add + $asReturnList[0] += $asFolderMatchList[0] + ; Resize and add file match array + ReDim $asFolderMatchList[$asFolderMatchList[0] + 1] + _ArrayConcatenate($asReturnList, $asFolderMatchList, 1) + ; Simple sort final list + __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0]) + Else + ; Size return list + Local $asReturnList[$asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0] + 1] + $asReturnList[0] = $asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0] + ; Sort root file list + __ArrayDualPivotSort($asRootFileMatchList, 1, $asRootFileMatchList[0]) + ; Add the sorted root files at the top + For $i = 1 To $asRootFileMatchList[0] + $asReturnList[$i] = $asRootFileMatchList[$i] + Next + ; Set next insertion index + Local $iNextInsertionIndex = $asRootFileMatchList[0] + 1 + ; Sort folder list + __ArrayDualPivotSort($asFolderMatchList, 1, $asFolderMatchList[0]) + Local $sFolderToFind = "" + ; Work through folder list + For $i = 1 To $asFolderMatchList[0] + ; Add folder to return list + $asReturnList[$iNextInsertionIndex] = $asFolderMatchList[$i] + $iNextInsertionIndex += 1 + ; Format folder name for search + If $sFolderSlash Then + $sFolderToFind = $asFolderMatchList[$i] + Else + $sFolderToFind = $asFolderMatchList[$i] & "\" + EndIf + Local $iFileSectionEndIndex = 0, $iFileSectionStartIndex = 0 + ; Find folder in FolderFileSectionList + For $j = 1 To $asFolderFileSectionList[0][0] + ; If found then deal with files + If $sFolderToFind = $asFolderFileSectionList[$j][0] Then + ; Set file list indexes + $iFileSectionStartIndex = $asFolderFileSectionList[$j][1] + If $j = $asFolderFileSectionList[0][0] Then + $iFileSectionEndIndex = $asFileMatchList[0] + Else + $iFileSectionEndIndex = $asFolderFileSectionList[$j + 1][1] - 1 + EndIf + ; Sort files if required + If $iSort = 1 Then + __ArrayDualPivotSort($asFileMatchList, $iFileSectionStartIndex, $iFileSectionEndIndex) + EndIf + ; Add files to return list + For $k = $iFileSectionStartIndex To $iFileSectionEndIndex + $asReturnList[$iNextInsertionIndex] = $asFileMatchList[$k] + $iNextInsertionIndex += 1 + Next + ExitLoop + EndIf + Next + Next + EndIf + EndSwitch + Else ; No sort + ; Check if any file/folders have been added + If $asReturnList[0] = 0 Then Return SetError(1, 9, "") + ; Remove any unused return list elements from last ReDim + ReDim $asReturnList[$asReturnList[0] + 1] + + EndIf + + Return $asReturnList +EndFunc ;==>_FileListToArrayRec + +; #INTERNAL_USE_ONLY#============================================================================================================ +; Name...........: __FLTAR_AddFileLists +; Description ...: Add internal lists after resizing and optional sorting +; Syntax ........: __FLTAR_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2[, $iSort = 0]) +; Parameters ....: $asReturnList - Base list +; $asRootFileMatchList - First list to add +; $asFileMatchList - Second list to add +; $iSort - (Optional) Whether to sort lists before adding +; |$iSort = 0 (Default) No sort +; |$iSort = 1 Sort in descending alphabetical order +; Return values .: None - array modified ByRef +; Author ........: Melba23 +; Remarks .......: This function is used internally by _FileListToArrayRec +; =============================================================================================================================== +Func __FLTAR_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2, $iSort = 0) + ; Correctly size root file match array + ReDim $asSource_1[$asSource_1[0] + 1] + ; Simple sort root file match array if required + If $iSort = 1 Then __ArrayDualPivotSort($asSource_1, 1, $asSource_1[0]) + ; Copy root file match array + $asTarget = $asSource_1 + ; Add file match count + $asTarget[0] += $asSource_2[0] + ; Correctly size file match array + ReDim $asSource_2[$asSource_2[0] + 1] + ; Simple sort file match array if required + If $iSort = 1 Then __ArrayDualPivotSort($asSource_2, 1, $asSource_2[0]) + ; Add file match array + _ArrayConcatenate($asTarget, $asSource_2, 1) +EndFunc ;==>__FLTAR_AddFileLists + +; #INTERNAL_USE_ONLY#============================================================================================================ +; Name...........: __FLTAR_AddToList +; Description ...: Add element to [?] or [?][2] list which is resized if necessary +; Syntax ........: __FLTAR_AddToList(ByRef $asList, $vValue_0, [$vValue_1]) +; Parameters ....: $aList - List to be added to +; $vValue_0 - Value to add to array - if $vValue_1 exists value added to [?][0] element in [?][2] array +; $vValue_1 - Value to add to [?][1] element in [?][2] array (optional) +; Return values .: None - array modified ByRef +; Author ........: Melba23 +; Remarks .......: This function is used internally by _FileListToArrayRec +; =============================================================================================================================== +Func __FLTAR_AddToList(ByRef $aList, $vValue_0, $vValue_1 = -1) + If $vValue_1 = -1 Then ; [?] array + ; Increase list count + $aList[0] += 1 + ; Double list size if too small (fewer ReDim needed) + If UBound($aList) <= $aList[0] Then ReDim $aList[UBound($aList) * 2] + ; Add value + $aList[$aList[0]] = $vValue_0 + Else ; [?][2] array + $aList[0][0] += 1 + If UBound($aList) <= $aList[0][0] Then ReDim $aList[UBound($aList) * 2][2] + $aList[$aList[0][0]][0] = $vValue_0 + $aList[$aList[0][0]][1] = $vValue_1 + EndIf +EndFunc ;==>__FLTAR_AddToList + +; #INTERNAL_USE_ONLY#============================================================================================================ +; Name...........: __FLTAR_ListToMask +; Description ...: Convert include/exclude lists to SRE format +; Syntax ........: __FLTAR_ListToMask(ByRef $sMask, $sList) +; Parameters ....: $asMask - Include/Exclude mask to create +; $asList - Include/Exclude list to convert +; Return values .: Success: 1 +; Failure: 0 +; Author ........: SRE patterns developed from those posted by various forum members and Spiff59 in particular +; Remarks .......: This function is used internally by _FileListToArrayRec +; =============================================================================================================================== +Func __FLTAR_ListToMask(ByRef $sMask, $sList) + ; Check for invalid characters within list + If StringRegExp($sList, "\\|/|:|\<|\>|\|") Then Return 0 + ; Strip WS and insert | for ; + $sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), $STR_STRIPLEADING + $STR_STRIPTRAILING), ";", "|") + ; Convert to SRE pattern + $sList = StringReplace(StringReplace(StringRegExpReplace($sList, "[][$^.{}()+\-]", "\\$0"), "?", "."), "*", ".*?") + ; Add prefix and suffix + $sMask = "(?i)^(" & $sList & ")\z" + Return 1 +EndFunc ;==>__FLTAR_ListToMask + +; #FUNCTION# ==================================================================================================================== +; Author ........: erifash +; Modified.......: guinness - Use the native ShellExecute function. +; =============================================================================================================================== +Func _FilePrint($sFilePath, $iShow = @SW_HIDE) + If $iShow = Default Then $iShow = @SW_HIDE + Return ShellExecute($sFilePath, "", @WorkingDir, "print", $iShow) +EndFunc ;==>_FilePrint + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jonathan Bennett , Valik - Support Windows Unix and Mac line separator +; Modified ......: Jpm - fixed empty line at the end, Gary Fixed file contains only 1 line, guinness - Optional flag to return the array count. +; : Melba23 - Read to 1D/2D arrays, guinness & jchd - Removed looping through 1D array with $FRTA_COUNT flag. +; =============================================================================================================================== +Func _FileReadToArray($sFilePath, ByRef $vReturn, $iFlags = $FRTA_COUNT, $sDelimiter = "") + ; Clear the previous contents + $vReturn = 0 + + If $iFlags = Default Then $iFlags = $FRTA_COUNT + If $sDelimiter = Default Then $sDelimiter = "" + + ; Set "array of arrays" flag + Local $bExpand = True + If BitAND($iFlags, $FRTA_INTARRAYS) Then + $bExpand = False + $iFlags -= $FRTA_INTARRAYS + EndIf + ; Set delimiter flag + Local $iEntire = $STR_CHRSPLIT + If BitAND($iFlags, $FRTA_ENTIRESPLIT) Then + $iEntire = $STR_ENTIRESPLIT + $iFlags -= $FRTA_ENTIRESPLIT + EndIf + ; Set row count and split count flags + Local $iNoCount = 0 + If $iFlags <> $FRTA_COUNT Then + $iFlags = $FRTA_NOCOUNT + $iNoCount = $STR_NOCOUNT + EndIf + + ; Check delimiter + If $sDelimiter Then + ; Read file into an array + Local $aLines = FileReadToArray($sFilePath) + If @error Then Return SetError(@error, 0, 0) + + ; Get first dimension and add count if required + Local $iDim_1 = UBound($aLines) + $iFlags + ; Check type of return array + If $bExpand Then ; All lines have same number of fields + ; Count fields in first line + Local $iDim_2 = UBound(StringSplit($aLines[0], $sDelimiter, $iEntire + $STR_NOCOUNT)) + ; Size array + Local $aTemp_Array[$iDim_1][$iDim_2] + ; Declare the variables + Local $iFields, _ + $aSplit + ; Loop through the lines + For $i = 0 To $iDim_1 - $iFlags - 1 + ; Split each line as required + $aSplit = StringSplit($aLines[$i], $sDelimiter, $iEntire + $STR_NOCOUNT) + ; Count the items + $iFields = UBound($aSplit) + If $iFields <> $iDim_2 Then + ; Return error + Return SetError(3, 0, 0) + EndIf + ; Fill this line of the array + For $j = 0 To $iFields - 1 + $aTemp_Array[$i + $iFlags][$j] = $aSplit[$j] + Next + Next + ; Check at least 2 columns + If $iDim_2 < 2 Then Return SetError(4, 0, 0) + ; Set dimension count + If $iFlags Then + $aTemp_Array[0][0] = $iDim_1 - $iFlags + $aTemp_Array[0][1] = $iDim_2 + EndIf + Else ; Create "array of arrays" + ; Size array + Local $aTemp_Array[$iDim_1] + ; Loop through the lines + For $i = 0 To $iDim_1 - $iFlags - 1 + ; Split each line as required + $aTemp_Array[$i + $iFlags] = StringSplit($aLines[$i], $sDelimiter, $iEntire + $iNoCount) + Next + ; Set dimension count + If $iFlags Then + $aTemp_Array[0] = $iDim_1 - $iFlags + EndIf + EndIf + ; Return the array + $vReturn = $aTemp_Array + Else ; 1D + If $iFlags Then + Local $hFileOpen = FileOpen($sFilePath, $FO_READ) + If $hFileOpen = -1 Then Return SetError(1, 0, 0) + Local $sFileRead = FileRead($hFileOpen) + FileClose($hFileOpen) + + If StringLen($sFileRead) Then + $vReturn = StringRegExp(@LF & $sFileRead, "(?|(\N+)\z|(\N*)(?:\R))", 3) + $vReturn[0] = UBound($vReturn) - 1 + Else + Return SetError(2, 0, 0) + EndIf + Else + $vReturn = FileReadToArray($sFilePath) + If @error Then + $vReturn = 0 + Return SetError(@error, 0, 0) + EndIf + EndIf + + EndIf + Return 1 +EndFunc ;==>_FileReadToArray + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jos van der Zande +; Modified.......: Updated for file handles by PsaltyDS, @error = 4 msg and 2-dimension capability added by Spiff59 and fixed by guinness. +; =============================================================================================================================== +Func _FileWriteFromArray($sFilePath, Const ByRef $aArray, $iBase = Default, $iUBound = Default, $sDelimiter = "|") + Local $iReturn = 0 + ; Check if we have a valid array as an input. + If Not IsArray($aArray) Then Return SetError(2, 0, $iReturn) + + ; Check the number of dimensions is no greater than a 2d array. + Local $iDims = UBound($aArray, $UBOUND_DIMENSIONS) + If $iDims > 2 Then Return SetError(4, 0, 0) + + ; Determine last entry of the array. + Local $iLast = UBound($aArray) - 1 + If $iUBound = Default Or $iUBound > $iLast Then $iUBound = $iLast + If $iBase < 0 Or $iBase = Default Then $iBase = 0 + If $iBase > $iUBound Then Return SetError(5, 0, $iReturn) + If $sDelimiter = Default Then $sDelimiter = "|" + + ; Open output file for overwrite by default, or use input file handle if passed. + Local $hFileOpen = $sFilePath + If IsString($sFilePath) Then + $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE) + If $hFileOpen = -1 Then Return SetError(1, 0, $iReturn) + EndIf + + ; Write array data to file. + Local $iError = 0 + $iReturn = 1 ; Set the return value to true. + Switch $iDims + Case 1 + For $i = $iBase To $iUBound + If Not FileWrite($hFileOpen, $aArray[$i] & @CRLF) Then + $iError = 3 + $iReturn = 0 + ExitLoop + EndIf + Next + Case 2 + Local $sTemp = "" + For $i = $iBase To $iUBound + $sTemp = $aArray[$i][0] + For $j = 1 To UBound($aArray, $UBOUND_COLUMNS) - 1 + $sTemp &= $sDelimiter & $aArray[$i][$j] + Next + If Not FileWrite($hFileOpen, $sTemp & @CRLF) Then + $iError = 3 + $iReturn = 0 + ExitLoop + EndIf + Next + EndSwitch + + ; Close file only if specified by a string path. + If IsString($sFilePath) Then FileClose($hFileOpen) + + ; Return the results. + Return SetError($iError, 0, $iReturn) +EndFunc ;==>_FileWriteFromArray + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jeremy Landes +; Modified.......: MrCreatoR - added $iFlag parameter +; =============================================================================================================================== +Func _FileWriteLog($sLogPath, $sLogMsg, $iFlag = -1) + Local $iOpenMode = $FO_APPEND + + Local $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY + Local $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC + Local $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg + + If $iFlag = Default Then $iFlag = -1 + If $iFlag <> -1 Then + $iOpenMode = $FO_OVERWRITE + $sMsg &= @CRLF & FileRead($sLogPath) + EndIf + + ; Open output file for appending to the end/overwriting, or use input file handle if passed + Local $hFileOpen = $sLogPath + If IsString($sLogPath) Then + $hFileOpen = FileOpen($sLogPath, $iOpenMode) + EndIf + If $hFileOpen = -1 Then Return SetError(1, 0, 0) + + Local $iReturn = FileWriteLine($hFileOpen, $sMsg) + + ; Close file only if specified by a string path + If IsString($sLogPath) Then $iReturn = FileClose($hFileOpen) + If $iReturn <= 0 Then Return SetError(2, $iReturn, 0) + Return $iReturn +EndFunc ;==>_FileWriteLog + +; #FUNCTION# ==================================================================================================================== +; Author ........: cdkid +; Modified.......: partypooper, MrCreatoR +; =============================================================================================================================== +Func _FileWriteToLine($sFilePath, $iLine, $sText, $bOverWrite = False) + If $iLine <= 0 Then Return SetError(4, 0, 0) + If Not IsString($sText) Then + $sText = String($sText) + If $sText = "" Then Return SetError(6, 0, 0) + EndIf + If $bOverWrite = Default Then $bOverWrite = False + If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions. + If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) + + Local $aArray = FileReadToArray($sFilePath) + Local $iUBound = UBound($aArray) - 1 + If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0) + + Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE) + If $hFileOpen = -1 Then Return SetError(3, 0, 0) + + Local $sData = "" + $iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1. + For $i = 0 To $iUBound + If $i = $iLine Then + If $bOverWrite Then + If $sText Then $sData &= $sText & @CRLF + Else + $sData &= $sText & @CRLF & $aArray[$i] & @CRLF + EndIf + ElseIf $i < $iUBound Then + $sData &= $aArray[$i] & @CRLF + ElseIf $i = $iUBound Then + $sData &= $aArray[$i] + EndIf + Next + + FileWrite($hFileOpen, $sData) + FileClose($hFileOpen) + Return 1 +EndFunc ;==>_FileWriteToLine + +; #FUNCTION# ==================================================================================================================== +; Author ........: Valik (Original function and modification to rewrite), tittoproject (Rewrite) +; Modified.......: +; =============================================================================================================================== +Func _PathFull($sRelativePath, $sBasePath = @WorkingDir) + If Not $sRelativePath Or $sRelativePath = "." Then Return $sBasePath + + ; Normalize slash direction. + Local $sFullPath = StringReplace($sRelativePath, "/", "\") ; Holds the full path (later, minus the root) + Local Const $sFullPathConst = $sFullPath ; Holds a constant version of the full path. + Local $sPath ; Holds the root drive/server + Local $bRootOnly = StringLeft($sFullPath, 1) = "\" And StringMid($sFullPath, 2, 1) <> "\" + + If $sBasePath = Default Then $sBasePath = @WorkingDir + + ; Check for UNC paths or local drives. We run this twice at most. The + ; first time, we check if the relative path is absolute. If it's not, then + ; we use the base path which should be absolute. + For $i = 1 To 2 + $sPath = StringLeft($sFullPath, 2) + If $sPath = "\\" Then + $sFullPath = StringTrimLeft($sFullPath, 2) + Local $nServerLen = StringInStr($sFullPath, "\") - 1 + $sPath = "\\" & StringLeft($sFullPath, $nServerLen) + $sFullPath = StringTrimLeft($sFullPath, $nServerLen) + ExitLoop + ElseIf StringRight($sPath, 1) = ":" Then + $sFullPath = StringTrimLeft($sFullPath, 2) + ExitLoop + Else + $sFullPath = $sBasePath & "\" & $sFullPath + EndIf + Next + + ; If this happens, we've found a funky path and don't know what to do + ; except for get out as fast as possible. We've also screwed up our + ; variables so we definitely need to quit. + ; If $i = 3 Then Return "" + + ; A path with a drive but no slash (e.g. C:Path\To\File) has the following + ; behavior. If the relative drive is the same as the $BasePath drive then + ; insert the base path. If the drives differ then just insert a leading + ; slash to make the path valid. + If StringLeft($sFullPath, 1) <> "\" Then + If StringLeft($sFullPathConst, 2) = StringLeft($sBasePath, 2) Then + $sFullPath = $sBasePath & "\" & $sFullPath + Else + $sFullPath = "\" & $sFullPath + EndIf + EndIf + + ; Build an array of the path parts we want to use. + Local $aTemp = StringSplit($sFullPath, "\") + Local $aPathParts[$aTemp[0]], $j = 0 + For $i = 2 To $aTemp[0] + If $aTemp[$i] = ".." Then + If $j Then $j -= 1 + ElseIf Not ($aTemp[$i] = "" And $i <> $aTemp[0]) And $aTemp[$i] <> "." Then + $aPathParts[$j] = $aTemp[$i] + $j += 1 + EndIf + Next + + ; Here we re-build the path from the parts above. We skip the + ; loop if we are only returning the root. + $sFullPath = $sPath + If Not $bRootOnly Then + For $i = 0 To $j - 1 + $sFullPath &= "\" & $aPathParts[$i] + Next + Else + $sFullPath &= $sFullPathConst + ; If we detect more relative parts, remove them by calling ourself recursively. + If StringInStr($sFullPath, "..") Then $sFullPath = _PathFull($sFullPath) + EndIf + + ; Clean up the path. + Do + $sFullPath = StringReplace($sFullPath, ".\", "\") + Until @extended = 0 + Return $sFullPath +EndFunc ;==>_PathFull + +; #FUNCTION# ==================================================================================================================== +; Author ........: Erik Pilsits +; Modified.......: +; =============================================================================================================================== +Func _PathGetRelative($sFrom, $sTo) + If StringRight($sFrom, 1) <> "\" Then $sFrom &= "\" ; add missing trailing \ to $sFrom path + If StringRight($sTo, 1) <> "\" Then $sTo &= "\" ; add trailing \ to $sTo + If $sFrom = $sTo Then Return SetError(1, 0, StringTrimRight($sTo, 1)) ; $sFrom equals $sTo + Local $asFrom = StringSplit($sFrom, "\") + Local $asTo = StringSplit($sTo, "\") + If $asFrom[1] <> $asTo[1] Then Return SetError(2, 0, StringTrimRight($sTo, 1)) ; drives are different, rel path not possible + ; create rel path + Local $i = 2 + Local $iDiff = 1 + While 1 + If $asFrom[$i] <> $asTo[$i] Then + $iDiff = $i + ExitLoop + EndIf + $i += 1 + WEnd + $i = 1 + Local $sRelPath = "" + For $j = 1 To $asTo[0] + If $i >= $iDiff Then + $sRelPath &= "\" & $asTo[$i] + EndIf + $i += 1 + Next + $sRelPath = StringTrimLeft($sRelPath, 1) + $i = 1 + For $j = 1 To $asFrom[0] + If $i > $iDiff Then + $sRelPath = "..\" & $sRelPath + EndIf + $i += 1 + Next + If StringRight($sRelPath, 1) == "\" Then $sRelPath = StringTrimRight($sRelPath, 1) ; remove trailing \ + Return $sRelPath +EndFunc ;==>_PathGetRelative + +; #FUNCTION# ==================================================================================================================== +; Author ........: Valik +; Modified.......: guinness +; =============================================================================================================================== +Func _PathMake($sDrive, $sDir, $sFileName, $sExtension) + ; Format $sDrive, if it's not a UNC server name, then just get the drive letter and add a colon + If StringLen($sDrive) Then + If Not (StringLeft($sDrive, 2) = "\\") Then $sDrive = StringLeft($sDrive, 1) & ":" + EndIf + + ; Format the directory by adding any necessary slashes + If StringLen($sDir) Then + If Not (StringRight($sDir, 1) = "\") And Not (StringRight($sDir, 1) = "/") Then $sDir = $sDir & "\" + Else + $sDir = "\" + EndIf + + If StringLen($sDir) Then + ; Append a backslash to the start of the directory if required + If Not (StringLeft($sDir, 1) = "\") And Not (StringLeft($sDir, 1) = "/") Then $sDir = "\" & $sDir + EndIf + + ; Nothing to be done for the filename + + ; Add the period to the extension if necessary + If StringLen($sExtension) Then + If Not (StringLeft($sExtension, 1) = ".") Then $sExtension = "." & $sExtension + EndIf + + Return $sDrive & $sDir & $sFileName & $sExtension +EndFunc ;==>_PathMake + +; #FUNCTION# ==================================================================================================================== +; Author ........: Valik +; Modified.......: DXRW4E - Re-wrote to use a regular expression; guinness - Update syntax and structure. +; =============================================================================================================================== +Func _PathSplit($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension) + Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH) + If @error Then ; This error should never happen. + ReDim $aArray[5] + $aArray[0] = $sFilePath + EndIf + $sDrive = $aArray[1] + If StringLeft($aArray[2], 1) == "/" Then + $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/") + Else + $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\") + EndIf + $aArray[2] = $sDir + $sFileName = $aArray[3] + $sExtension = $aArray[4] + Return $aArray +EndFunc ;==>_PathSplit + +; #FUNCTION# ==================================================================================================================== +; Author ........: Kurt (aka /dev/null) and JdeB +; Modified ......: guinness - Re-wrote the function entirely for improvements in readability. +; =============================================================================================================================== +Func _ReplaceStringInFile($sFilePath, $sSearchString, $sReplaceString, $iCaseSensitive = 0, $iOccurance = 1) + If StringInStr(FileGetAttrib($sFilePath), "R") Then Return SetError(1, 0, -1) + + ; Open the file for reading. + Local $hFileOpen = FileOpen($sFilePath, $FO_READ) + If $hFileOpen = -1 Then Return SetError(2, 0, -1) + + ; Read the contents of the file and stores in a variable + Local $sFileRead = FileRead($hFileOpen) + FileClose($hFileOpen) ; Close the open file after reading + + ; Set the default parameters + If $iCaseSensitive = Default Then $iCaseSensitive = 0 + If $iOccurance = Default Then $iOccurance = 1 + + ; Replace strings + $sFileRead = StringReplace($sFileRead, $sSearchString, $sReplaceString, 1 - $iOccurance, $iCaseSensitive) + Local $iReturn = @extended + + ; If there are replacements then overwrite the file + If $iReturn Then + ; Retrieve the file encoding + Local $iFileEncoding = FileGetEncoding($sFilePath) + + ; Open the file for writing and set the overwrite flag + $hFileOpen = FileOpen($sFilePath, $iFileEncoding + $FO_OVERWRITE) + If $hFileOpen = -1 Then Return SetError(3, 0, -1) + + ; Write to the open file + FileWrite($hFileOpen, $sFileRead) + FileClose($hFileOpen) ; Close the open file after writing + EndIf + Return $iReturn +EndFunc ;==>_ReplaceStringInFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Dale (Klaatu) Thompson +; Modified.......: Hans Harder - Added Optional parameters, guinness - Fixed using non-supported characters in the file prefix. +; =============================================================================================================================== +Func _TempFile($sDirectoryName = @TempDir, $sFilePrefix = "~", $sFileExtension = ".tmp", $iRandomLength = 7) + ; Check parameters for the Default keyword or they meet a certain criteria + If $iRandomLength = Default Or $iRandomLength <= 0 Then $iRandomLength = 7 + If $sDirectoryName = Default Or (Not FileExists($sDirectoryName)) Then $sDirectoryName = @TempDir + If $sFileExtension = Default Then $sFileExtension = ".tmp" + If $sFilePrefix = Default Then $sFilePrefix = "~" + + ; Check if the directory exists or use the current script directory + If Not FileExists($sDirectoryName) Then $sDirectoryName = @ScriptDir + + ; Remove the appending backslash + $sDirectoryName = StringRegExpReplace($sDirectoryName, "[\\/]+$", "") + ; Remove the initial dot (.) from the file extension + $sFileExtension = StringRegExpReplace($sFileExtension, "^\.+", "") + ; Remove any non-supported characters in the file prefix + $sFilePrefix = StringRegExpReplace($sFilePrefix, '[\\/:*?"<>|]', "") + + ; Create the temporary file path without writing to the selected directory + Local $sTempName = "" + Do + ; Create a random filename + $sTempName = "" + While StringLen($sTempName) < $iRandomLength + $sTempName &= Chr(Random(97, 122, 1)) + WEnd + ; Temporary filepath + $sTempName = $sDirectoryName & "\" & $sFilePrefix & $sTempName & "." & $sFileExtension + Until Not FileExists($sTempName) ; Exit the loop if no file with the same name is present + Return $sTempName +EndFunc ;==>_TempFile diff --git a/src/include/GUIConstantsEx.au3 b/src/include/GUIConstantsEx.au3 new file mode 100644 index 0000000..9d062f3 --- /dev/null +++ b/src/include/GUIConstantsEx.au3 @@ -0,0 +1,111 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: GUIConstantsEx +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Constants to be used in GUI applications. +; Author(s) .....: Jpm, Valik +; Dll ...........: +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +; Events and messages +Global Const $GUI_EVENT_SINGLE = 0 ; (default) Returns a single event. +Global Const $GUI_EVENT_ARRAY = 1 ; returns an array containing the event and extended information. + +Global Const $GUI_EVENT_NONE = 0 +Global Const $GUI_EVENT_CLOSE = -3 +Global Const $GUI_EVENT_MINIMIZE = -4 +Global Const $GUI_EVENT_RESTORE = -5 +Global Const $GUI_EVENT_MAXIMIZE = -6 +Global Const $GUI_EVENT_PRIMARYDOWN = -7 +Global Const $GUI_EVENT_PRIMARYUP = -8 +Global Const $GUI_EVENT_SECONDARYDOWN = -9 +Global Const $GUI_EVENT_SECONDARYUP = -10 +Global Const $GUI_EVENT_MOUSEMOVE = -11 +Global Const $GUI_EVENT_RESIZED = -12 +Global Const $GUI_EVENT_DROPPED = -13 + +Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG' + +; State +Global Const $GUI_AVISTOP = 0 +Global Const $GUI_AVISTART = 1 +Global Const $GUI_AVICLOSE = 2 + +Global Const $GUI_CHECKED = 1 +Global Const $GUI_INDETERMINATE = 2 +Global Const $GUI_UNCHECKED = 4 + +Global Const $GUI_DROPACCEPTED = 8 +Global Const $GUI_NODROPACCEPTED = 4096 +Global Const $GUI_ACCEPTFILES = $GUI_DROPACCEPTED ; to be suppressed + +Global Const $GUI_SHOW = 16 +Global Const $GUI_HIDE = 32 +Global Const $GUI_ENABLE = 64 +Global Const $GUI_DISABLE = 128 + +Global Const $GUI_FOCUS = 256 +Global Const $GUI_NOFOCUS = 8192 +Global Const $GUI_DEFBUTTON = 512 + +Global Const $GUI_EXPAND = 1024 +Global Const $GUI_ONTOP = 2048 + +; Font +Global Const $GUI_FONTNORMAL = 0 +Global Const $GUI_FONTITALIC = 2 +Global Const $GUI_FONTUNDER = 4 +Global Const $GUI_FONTSTRIKE = 8 + +; Resizing +Global Const $GUI_DOCKAUTO = 0x0001 +Global Const $GUI_DOCKLEFT = 0x0002 +Global Const $GUI_DOCKRIGHT = 0x0004 +Global Const $GUI_DOCKHCENTER = 0x0008 +Global Const $GUI_DOCKTOP = 0x0020 +Global Const $GUI_DOCKBOTTOM = 0x0040 +Global Const $GUI_DOCKVCENTER = 0x0080 +Global Const $GUI_DOCKWIDTH = 0x0100 +Global Const $GUI_DOCKHEIGHT = 0x0200 + +Global Const $GUI_DOCKSIZE = 0x0300 ; width+height +Global Const $GUI_DOCKMENUBAR = 0x0220 ; top+height +Global Const $GUI_DOCKSTATEBAR = 0x0240 ; bottom+height +Global Const $GUI_DOCKALL = 0x0322 ; left+top+width+height +Global Const $GUI_DOCKBORDERS = 0x0066 ; left+top+right+bottom + +; Graphic +Global Const $GUI_GR_CLOSE = 1 +Global Const $GUI_GR_LINE = 2 +Global Const $GUI_GR_BEZIER = 4 +Global Const $GUI_GR_MOVE = 6 +Global Const $GUI_GR_COLOR = 8 +Global Const $GUI_GR_RECT = 10 +Global Const $GUI_GR_ELLIPSE = 12 +Global Const $GUI_GR_PIE = 14 +Global Const $GUI_GR_DOT = 16 +Global Const $GUI_GR_PIXEL = 18 +Global Const $GUI_GR_HINT = 20 +Global Const $GUI_GR_REFRESH = 22 +Global Const $GUI_GR_PENSIZE = 24 +Global Const $GUI_GR_NOBKCOLOR = -2 + +; Background color special flags +Global Const $GUI_BKCOLOR_DEFAULT = -1 +Global Const $GUI_BKCOLOR_TRANSPARENT = -2 +Global Const $GUI_BKCOLOR_LV_ALTERNATE = 0xFE000000 + +; GUICtrlRead Constants +Global Const $GUI_READ_DEFAULT = 0 ; (Default) Returns a value with state or data of a control. +Global Const $GUI_READ_EXTENDED = 1 ; Returns extended information of a control (see Remarks). + +; GUISetCursor Constants +Global Const $GUI_CURSOR_NOOVERRIDE = 0 ; (default) Don't override a control's default mouse cursor. +Global Const $GUI_CURSOR_OVERRIDE = 1 ; override control's default mouse cursor. + +; Other +Global Const $GUI_WS_EX_PARENTDRAG = 0x00100000 +; =============================================================================================================================== diff --git a/src/include/GuiEdit.au3 b/src/include/GuiEdit.au3 new file mode 100644 index 0000000..a22ff35 --- /dev/null +++ b/src/include/GuiEdit.au3 @@ -0,0 +1,1057 @@ +#include-once + +#include "EditConstants.au3" +#include "GuiStatusBar.au3" +#include "Memory.au3" +#include "SendMessage.au3" +#include "UDFGlobalID.au3" +#include "WinAPI.au3" +#include "ToolTipConstants.au3" ; for _GUICtrlEdit_ShowBalloonTip() + +; #INDEX# ======================================================================================================================= +; Title .........: Edit +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with Edit control management. +; An edit control is a rectangular control window typically used in a dialog box to permit the user to enter +; and edit text by typing on the keyboard. +; =============================================================================================================================== + +; #VARIABLES# =================================================================================================================== +Global $__g_hEditLastWnd + +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $__EDITCONSTANT_ClassName = "Edit" +Global Const $__EDITCONSTANT_GUI_CHECKED = 1 +Global Const $__EDITCONSTANT_GUI_HIDE = 32 +Global Const $__EDITCONSTANT_GUI_EVENT_CLOSE = -3 +Global Const $__EDITCONSTANT_GUI_ENABLE = 64 +Global Const $__EDITCONSTANT_GUI_DISABLE = 128 +Global Const $__EDITCONSTANT_SS_CENTER = 1 +Global Const $__EDITCONSTANT_WM_SETREDRAW = 0x000B +Global Const $__EDITCONSTANT_WS_CAPTION = 0x00C00000 +Global Const $__EDITCONSTANT_WS_POPUP = 0x80000000 +Global Const $__EDITCONSTANT_WS_SYSMENU = 0x00080000 +Global Const $__EDITCONSTANT_WS_MINIMIZEBOX = 0x00020000 +Global Const $__EDITCONSTANT_DEFAULT_GUI_FONT = 17 +Global Const $__EDITCONSTANT_WM_SETFONT = 0x0030 +Global Const $__EDITCONSTANT_WM_GETTEXTLENGTH = 0x000E +Global Const $__EDITCONSTANT_WM_GETTEXT = 0x000D +Global Const $__EDITCONSTANT_WM_SETTEXT = 0x000C +Global Const $__EDITCONSTANT_SB_LINEUP = 0 +Global Const $__EDITCONSTANT_SB_LINEDOWN = 1 +Global Const $__EDITCONSTANT_SB_PAGEDOWN = 3 +Global Const $__EDITCONSTANT_SB_PAGEUP = 2 +Global Const $__EDITCONSTANT_SB_SCROLLCARET = 4 +; =============================================================================================================================== + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Not working/documented/implemented at this time +; +; _GUICtrlEdit_GetHandle +; _GUICtrlEdit_GetIMEStatus +; _GUICtrlEdit_GetThumb +; _GUICtrlEdit_GetWordBreakProc +; _GUICtrlEdit_SetHandle +; _GUICtrlEdit_SetIMEStatus +; _GUICtrlEdit_SetWordBreakProc +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _GUICtrlEdit_AppendText +; _GUICtrlEdit_BeginUpdate +; _GUICtrlEdit_CanUndo +; _GUICtrlEdit_CharFromPos +; _GUICtrlEdit_Create +; _GUICtrlEdit_Destroy +; _GUICtrlEdit_EmptyUndoBuffer +; _GUICtrlEdit_EndUpdate +; _GUICtrlEdit_FmtLines +; _GUICtrlEdit_Find +; _GUICtrlEdit_GetCueBanner +; _GUICtrlEdit_GetFirstVisibleLine +; _GUICtrlEdit_GetLimitText +; _GUICtrlEdit_GetLine +; _GUICtrlEdit_GetLineCount +; _GUICtrlEdit_GetMargins +; _GUICtrlEdit_GetModify +; _GUICtrlEdit_GetPasswordChar +; _GUICtrlEdit_GetRECT +; _GUICtrlEdit_GetRECTEx +; _GUICtrlEdit_GetSel +; _GUICtrlEdit_GetText +; _GUICtrlEdit_GetTextLen +; _GUICtrlEdit_HideBalloonTip +; _GUICtrlEdit_InsertText +; _GUICtrlEdit_LineFromChar +; _GUICtrlEdit_LineIndex +; _GUICtrlEdit_LineLength +; _GUICtrlEdit_LineScroll +; _GUICtrlEdit_PosFromChar +; _GUICtrlEdit_ReplaceSel +; _GUICtrlEdit_Scroll +; _GUICtrlEdit_SetCueBanner +; _GUICtrlEdit_SetLimitText +; _GUICtrlEdit_SetMargins +; _GUICtrlEdit_SetModify +; _GUICtrlEdit_SetPasswordChar +; _GUICtrlEdit_SetReadOnly +; _GUICtrlEdit_SetRECT +; _GUICtrlEdit_SetRECTEx +; _GUICtrlEdit_SetRECTNP +; _GUICtrlEdit_SetRectNPEx +; _GUICtrlEdit_SetSel +; _GUICtrlEdit_SetTabStops +; _GUICtrlEdit_SetText +; _GUICtrlEdit_ShowBalloonTip +; _GUICtrlEdit_Undo +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; $__tagEDITBALLOONTIP +; __GUICtrlEdit_FindText +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagEDITBALLOONTIP +; Description ...: Contains information about a balloon tip +; Fields ........: Size - Size of this structure, in bytes +; Title - Pointer to the buffer that holds Title of the ToolTip +; Text - Pointer to the buffer that holds Text of the ToolTip +; Icon - Type of Icon. This can be one of the following values: +; |$TTI_ERROR - Use the error icon +; |$TTI_INFO - Use the information icon +; |$TTI_NONE - Use no icon +; |$TTI_WARNING - Use the warning icon +; Author ........: Gary Frost (gafrost) +; Remarks .......: For use with Edit control (minimum O.S. Win XP) +; =============================================================================================================================== +Global Const $__tagEDITBALLOONTIP = "dword Size;ptr Title;ptr Text;int Icon" + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_AppendText($hWnd, $sText) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iLength = _GUICtrlEdit_GetTextLen($hWnd) + _GUICtrlEdit_SetSel($hWnd, $iLength, $iLength) + _SendMessage($hWnd, $EM_REPLACESEL, True, $sText, 0, "wparam", "wstr") +EndFunc ;==>_GUICtrlEdit_AppendText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_BeginUpdate($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $__EDITCONSTANT_WM_SETREDRAW, False) = 0 +EndFunc ;==>_GUICtrlEdit_BeginUpdate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_CanUndo($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_CANUNDO) <> 0 +EndFunc ;==>_GUICtrlEdit_CanUndo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_CharFromPos($hWnd, $iX, $iY) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $aReturn[2] + + Local $iRet = _SendMessage($hWnd, $EM_CHARFROMPOS, 0, _WinAPI_MakeLong($iX, $iY)) + $aReturn[0] = _WinAPI_LoWord($iRet) + $aReturn[1] = _WinAPI_HiWord($iRet) + Return $aReturn +EndFunc ;==>_GUICtrlEdit_CharFromPos + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_Create($hWnd, $sText, $iX, $iY, $iWidth = 150, $iHeight = 150, $iStyle = 0x003010C4, $iExStyle = 0x00000200) + If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlEdit_Create 1st parameter + If Not IsString($sText) Then Return SetError(2, 0, 0) ; 2nd parameter not a string for _GUICtrlEdit_Create + + If $iWidth = -1 Then $iWidth = 150 + If $iHeight = -1 Then $iHeight = 150 + If $iStyle = -1 Then $iStyle = 0x003010C4 + If $iExStyle = -1 Then $iExStyle = 0x00000200 + + If BitAND($iStyle, $ES_READONLY) = $ES_READONLY Then + $iStyle = BitOR($__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE, $iStyle) + Else + $iStyle = BitOR($__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE, $__UDFGUICONSTANT_WS_TABSTOP, $iStyle) + EndIf + ;========================================================================================================= + + Local $nCtrlID = __UDF_GetNextGlobalID($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Local $hEdit = _WinAPI_CreateWindowEx($iExStyle, $__EDITCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID) + _SendMessage($hEdit, $__EDITCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__EDITCONSTANT_DEFAULT_GUI_FONT), True) + _GUICtrlEdit_SetText($hEdit, $sText) + _GUICtrlEdit_SetLimitText($hEdit, 0) + Return $hEdit +EndFunc ;==>_GUICtrlEdit_Create + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_Destroy(ByRef $hWnd) + If Not _WinAPI_IsClassName($hWnd, $__EDITCONSTANT_ClassName) Then Return SetError(2, 2, False) + + Local $iDestroyed = 0 + If IsHWnd($hWnd) Then + If _WinAPI_InProcess($hWnd, $__g_hEditLastWnd) Then + Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd) + Local $hParent = _WinAPI_GetParent($hWnd) + $iDestroyed = _WinAPI_DestroyWindow($hWnd) + Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID) + If Not $iRet Then + ; can check for errors here if needed, for debug + EndIf + Else + ; Not Allowed to Destroy Other Applications Control(s) + Return SetError(1, 1, False) + EndIf + Else + $iDestroyed = GUICtrlDelete($hWnd) + EndIf + If $iDestroyed Then $hWnd = 0 + Return $iDestroyed <> 0 +EndFunc ;==>_GUICtrlEdit_Destroy + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_EmptyUndoBuffer($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_EMPTYUNDOBUFFER) +EndFunc ;==>_GUICtrlEdit_EmptyUndoBuffer + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_EndUpdate($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $__EDITCONSTANT_WM_SETREDRAW, True) = 0 +EndFunc ;==>_GUICtrlEdit_EndUpdate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_FmtLines($hWnd, $bSoftBreak = False) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_FMTLINES, $bSoftBreak) +EndFunc ;==>_GUICtrlEdit_FmtLines + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_Find($hWnd, $bReplace = False) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iPos = 0, $iCase, $iOccurance = 0, $iReplacements = 0 + Local $aPartsRightEdge[3] = [125, 225, -1] + Local $iOldMode = Opt("GUIOnEventMode", 0) + + Local $aSel = _GUICtrlEdit_GetSel($hWnd) + Local $sText = _GUICtrlEdit_GetText($hWnd) + + Local $hGuiSearch = GUICreate("Find", 349, 177, -1, -1, BitOR($__UDFGUICONSTANT_WS_CHILD, $__EDITCONSTANT_WS_MINIMIZEBOX, $__EDITCONSTANT_WS_CAPTION, $__EDITCONSTANT_WS_POPUP, $__EDITCONSTANT_WS_SYSMENU)) + Local $idStatusBar1 = _GUICtrlStatusBar_Create($hGuiSearch, $aPartsRightEdge) + _GUICtrlStatusBar_SetText($idStatusBar1, "Find: ") + + GUISetIcon(@SystemDir & "\shell32.dll", 22, $hGuiSearch) + GUICtrlCreateLabel("Find what:", 9, 10, 53, 16, $__EDITCONSTANT_SS_CENTER) + Local $idInputSearch = GUICtrlCreateInput("", 80, 8, 257, 21) + Local $idLblReplace = GUICtrlCreateLabel("Replace with:", 9, 42, 69, 17, $__EDITCONSTANT_SS_CENTER) + Local $idInputReplace = GUICtrlCreateInput("", 80, 40, 257, 21) + Local $idChkWholeOnly = GUICtrlCreateCheckbox("Match whole word only", 9, 72, 145, 17) + Local $idChkMatchCase = GUICtrlCreateCheckbox("Match case", 9, 96, 145, 17) + Local $idBtnFindNext = GUICtrlCreateButton("Find Next", 168, 72, 161, 21, 0) + Local $idBtnReplace = GUICtrlCreateButton("Replace", 168, 96, 161, 21, 0) + Local $idBtnClose = GUICtrlCreateButton("Close", 104, 130, 161, 21, 0) + If (IsArray($aSel) And $aSel <> $EC_ERR) Then + GUICtrlSetData($idInputSearch, StringMid($sText, $aSel[0] + 1, $aSel[1] - $aSel[0])) + If $aSel[0] <> $aSel[1] Then ; text was selected when function was invoked + $iPos = $aSel[0] + If BitAND(GUICtrlRead($idChkMatchCase), $__EDITCONSTANT_GUI_CHECKED) = $__EDITCONSTANT_GUI_CHECKED Then $iCase = 1 + $iOccurance = 1 + Local $iTPose + While 1 ; set the current occurance so search starts from here + $iTPose = StringInStr($sText, GUICtrlRead($idInputSearch), $iCase, $iOccurance) + If Not $iTPose Then ; this should never happen, but just in case + $iOccurance = 0 + ExitLoop + ElseIf $iTPose = $iPos + 1 Then ; found the occurance + ExitLoop + EndIf + $iOccurance += 1 + WEnd + EndIf + _GUICtrlStatusBar_SetText($idStatusBar1, "Find: " & GUICtrlRead($idInputSearch)) + EndIf + + If $bReplace = False Then + GUICtrlSetState($idLblReplace, $__EDITCONSTANT_GUI_HIDE) + GUICtrlSetState($idInputReplace, $__EDITCONSTANT_GUI_HIDE) + GUICtrlSetState($idBtnReplace, $__EDITCONSTANT_GUI_HIDE) + Else + _GUICtrlStatusBar_SetText($idStatusBar1, "Replacements: " & $iReplacements, 1) + _GUICtrlStatusBar_SetText($idStatusBar1, "With: ", 2) + EndIf + GUISetState(@SW_SHOW) + + Local $iMsgFind + While 1 + $iMsgFind = GUIGetMsg() + Select + Case $iMsgFind = $__EDITCONSTANT_GUI_EVENT_CLOSE Or $iMsgFind = $idBtnClose + ExitLoop + Case $iMsgFind = $idBtnFindNext + GUICtrlSetState($idBtnFindNext, $__EDITCONSTANT_GUI_DISABLE) + GUICtrlSetCursor($idBtnFindNext, 15) + Sleep(100) + _GUICtrlStatusBar_SetText($idStatusBar1, "Find: " & GUICtrlRead($idInputSearch)) + If $bReplace = True Then + _GUICtrlStatusBar_SetText($idStatusBar1, "Find: " & GUICtrlRead($idInputSearch)) + _GUICtrlStatusBar_SetText($idStatusBar1, "With: " & GUICtrlRead($idInputReplace), 2) + EndIf + __GUICtrlEdit_FindText($hWnd, $idInputSearch, $idChkMatchCase, $idChkWholeOnly, $iPos, $iOccurance, $iReplacements) + Sleep(100) + GUICtrlSetState($idBtnFindNext, $__EDITCONSTANT_GUI_ENABLE) + GUICtrlSetCursor($idBtnFindNext, 2) + Case $iMsgFind = $idBtnReplace + GUICtrlSetState($idBtnReplace, $__EDITCONSTANT_GUI_DISABLE) + GUICtrlSetCursor($idBtnReplace, 15) + Sleep(100) + _GUICtrlStatusBar_SetText($idStatusBar1, "Find: " & GUICtrlRead($idInputSearch)) + _GUICtrlStatusBar_SetText($idStatusBar1, "With: " & GUICtrlRead($idInputReplace), 2) + If $iPos Then + _GUICtrlEdit_ReplaceSel($hWnd, GUICtrlRead($idInputReplace)) + $iReplacements += 1 + $iOccurance -= 1 + _GUICtrlStatusBar_SetText($idStatusBar1, "Replacements: " & $iReplacements, 1) + EndIf + __GUICtrlEdit_FindText($hWnd, $idInputSearch, $idChkMatchCase, $idChkWholeOnly, $iPos, $iOccurance, $iReplacements) + Sleep(100) + GUICtrlSetState($idBtnReplace, $__EDITCONSTANT_GUI_ENABLE) + GUICtrlSetCursor($idBtnReplace, 2) + EndSelect + WEnd + GUIDelete($hGuiSearch) + Opt("GUIOnEventMode", $iOldMode) +EndFunc ;==>_GUICtrlEdit_Find + +; #FUNCTION# ==================================================================================================================== +; Author ........: Guinness +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetCueBanner($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $tText = DllStructCreate("wchar[4096]") + If _SendMessage($hWnd, $EM_GETCUEBANNER, $tText, 4096, 0, "struct*") <> 1 Then Return SetError(-1, 0, "") + Return _WinAPI_WideCharToMultiByte($tText) +EndFunc ;==>_GUICtrlEdit_GetCueBanner + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __GUICtrlEdit_FindText +; Description ...: +; Syntax.........: __GUICtrlEdit_FindText ( $hWnd, $idInputSearch, $idChkMatchCase, $idChkWholeOnly, ByRef $iPos, ByRef $iOccurance, ByRef $iReplacements ) +; Parameters ....: $hWnd - Handle to the control +; $idInputSearch - controlID +; $idChkMatchCase - controlID +; $idChkWholeOnly - controlID +; $iPos - position of text found +; $iOccurance - occurance to find +; $iReplacements - # of occurances replaced +; Return values .: +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: _GUICtrlEdit_Find +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __GUICtrlEdit_FindText($hWnd, $idInputSearch, $idChkMatchCase, $idChkWholeOnly, ByRef $iPos, ByRef $iOccurance, ByRef $iReplacements) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iCase = 0, $iWhole = 0 + Local $bExact = False + Local $sFind = GUICtrlRead($idInputSearch) + + Local $sText = _GUICtrlEdit_GetText($hWnd) + + If BitAND(GUICtrlRead($idChkMatchCase), $__EDITCONSTANT_GUI_CHECKED) = $__EDITCONSTANT_GUI_CHECKED Then $iCase = 1 + If BitAND(GUICtrlRead($idChkWholeOnly), $__EDITCONSTANT_GUI_CHECKED) = $__EDITCONSTANT_GUI_CHECKED Then $iWhole = 1 + If $sFind <> "" Then + $iOccurance += 1 + $iPos = StringInStr($sText, $sFind, $iCase, $iOccurance) + If $iWhole And $iPos Then + Local $s_Compare2 = StringMid($sText, $iPos + StringLen($sFind), 1) + If $iPos = 1 Then + If ($iPos + StringLen($sFind)) - 1 = StringLen($sText) Or _ + ($s_Compare2 = " " Or $s_Compare2 = @LF Or $s_Compare2 = @CR Or _ + $s_Compare2 = @CRLF Or $s_Compare2 = @TAB) Then $bExact = True + Else + Local $s_Compare1 = StringMid($sText, $iPos - 1, 1) + If ($iPos + StringLen($sFind)) - 1 = StringLen($sText) Then + If ($s_Compare1 = " " Or $s_Compare1 = @LF Or $s_Compare1 = @CR Or _ + $s_Compare1 = @CRLF Or $s_Compare1 = @TAB) Then $bExact = True + Else + If ($s_Compare1 = " " Or $s_Compare1 = @LF Or $s_Compare1 = @CR Or _ + $s_Compare1 = @CRLF Or $s_Compare1 = @TAB) And _ + ($s_Compare2 = " " Or $s_Compare2 = @LF Or $s_Compare2 = @CR Or _ + $s_Compare2 = @CRLF Or $s_Compare2 = @TAB) Then $bExact = True + EndIf + EndIf + If $bExact = False Then ; found word, but as part of another word, so search again + __GUICtrlEdit_FindText($hWnd, $idInputSearch, $idChkMatchCase, $idChkWholeOnly, $iPos, $iOccurance, $iReplacements) + Else ; found it + _GUICtrlEdit_SetSel($hWnd, $iPos - 1, ($iPos + StringLen($sFind)) - 1) + _GUICtrlEdit_Scroll($hWnd, $__EDITCONSTANT_SB_SCROLLCARET) + EndIf + ElseIf $iWhole And Not $iPos Then ; no more to find + $iOccurance = 0 + MsgBox($MB_SYSTEMMODAL, "Find", "Reached End of document, Can not find the string '" & $sFind & "'") + ElseIf Not $iWhole Then + If Not $iPos Then ; wrap around search and select + $iOccurance = 1 + _GUICtrlEdit_SetSel($hWnd, -1, 0) + _GUICtrlEdit_Scroll($hWnd, $__EDITCONSTANT_SB_SCROLLCARET) + $iPos = StringInStr($sText, $sFind, $iCase, $iOccurance) + If Not $iPos Then ; no more to find + $iOccurance = 0 + MsgBox($MB_SYSTEMMODAL, "Find", "Reached End of document, Can not find the string '" & $sFind & "'") + Else ; found it + _GUICtrlEdit_SetSel($hWnd, $iPos - 1, ($iPos + StringLen($sFind)) - 1) + _GUICtrlEdit_Scroll($hWnd, $__EDITCONSTANT_SB_SCROLLCARET) + EndIf + Else ; set selection + _GUICtrlEdit_SetSel($hWnd, $iPos - 1, ($iPos + StringLen($sFind)) - 1) + _GUICtrlEdit_Scroll($hWnd, $__EDITCONSTANT_SB_SCROLLCARET) + EndIf + EndIf + EndIf +EndFunc ;==>__GUICtrlEdit_FindText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetFirstVisibleLine($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETFIRSTVISIBLELINE) +EndFunc ;==>_GUICtrlEdit_GetFirstVisibleLine + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_GetHandle +; Description ...: Gets a handle of the memory currently allocated for a multiline edit control's text +; Syntax.........: _GUICtrlEdit_GetHandle ( $hWnd ) +; Parameters ....: $hWnd - Handle to the control +; Return values .: Success - Memory handle identifying the buffer that holds the content of the edit control +; Failure - 0 +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: If the function succeeds, the application can access the contents of the edit control by casting the +; return value to HLOCAL and passing it to LocalLock. LocalLock returns a pointer to a buffer that is a +; null-terminated array of CHARs or WCHARs, depending on whether an ANSI or Unicode function created the control. +; For example, if CreateWindowExA was used the buffer is an array of CHARs, but if CreateWindowExW was used the +; buffer is an array of WCHARs. The application may not change the contents of the buffer. To unlock the buffer, +; the application calls LocalUnlock before allowing the edit control to receive new messages. +; + +; If your application cannot abide by the restrictions imposed by EM_GETHANDLE, use the GetWindowTextLength and +; GetWindowText functions to copy the contents of the edit control into an application-provided buffer. +; Related .......: _GUICtrlEdit_SetHandle +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetHandle($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return Ptr(_SendMessage($hWnd, $EM_GETHANDLE)) +EndFunc ;==>_GUICtrlEdit_GetHandle + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_GetIMEStatus +; Description ...: Gets a set of status flags that indicate how the edit control interacts with the Input Method Editor (IME) +; Syntax.........: _GUICtrlEdit_GetIMEStatus ( $hWnd ) +; Parameters ....: $hWnd - Handle to the control +; Return values .: Success - One or More of the Following Flags +; |$EIMES_GETCOMPSTRATONCE - The edit control hooks the WM_IME_COMPOSITION message +; |$EIMES_CANCELCOMPSTRINFOCUS - The edit control cancels the composition string when it receives the WM_SETFOCUS message +; |$EIMES_COMPLETECOMPSTRKILLFOCUS - The edit control completes the composition string upon receiving the WM_KILLFOCUS message +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetIMEStatus($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETIMESTATUS, $EMSIS_COMPOSITIONSTRING) +EndFunc ;==>_GUICtrlEdit_GetIMEStatus + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetLimitText($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETLIMITTEXT) +EndFunc ;==>_GUICtrlEdit_GetLimitText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), Jos van der Zande +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlEdit_GetLine($hWnd, $iLine) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iLength = _GUICtrlEdit_LineLength($hWnd, $iLine) + If $iLength = 0 Then Return "" + Local $tBuffer = DllStructCreate("short Len;wchar Text[" & $iLength & "]") + DllStructSetData($tBuffer, "Len", $iLength + 1) + Local $iRet = _SendMessage($hWnd, $EM_GETLINE, $iLine, $tBuffer, 0, "wparam", "struct*") + + If $iRet = 0 Then Return SetError($EC_ERR, $EC_ERR, "") + + Local $tText = DllStructCreate("wchar Text[" & $iLength & "]", DllStructGetPtr($tBuffer)) + Return DllStructGetData($tText, "Text") +EndFunc ;==>_GUICtrlEdit_GetLine + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetLineCount($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETLINECOUNT) +EndFunc ;==>_GUICtrlEdit_GetLineCount + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetMargins($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $aMargins[2] + Local $iMargins = _SendMessage($hWnd, $EM_GETMARGINS) + $aMargins[0] = _WinAPI_LoWord($iMargins) ; Left Margin + $aMargins[1] = _WinAPI_HiWord($iMargins) ; Right Margin + Return $aMargins +EndFunc ;==>_GUICtrlEdit_GetMargins + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetModify($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETMODIFY) <> 0 +EndFunc ;==>_GUICtrlEdit_GetModify + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetPasswordChar($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETPASSWORDCHAR) +EndFunc ;==>_GUICtrlEdit_GetPasswordChar + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetRECT($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $aRect[4] + + Local $tRECT = _GUICtrlEdit_GetRECTEx($hWnd) + $aRect[0] = DllStructGetData($tRECT, "Left") + $aRect[1] = DllStructGetData($tRECT, "Top") + $aRect[2] = DllStructGetData($tRECT, "Right") + $aRect[3] = DllStructGetData($tRECT, "Bottom") + Return $aRect +EndFunc ;==>_GUICtrlEdit_GetRECT + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetRECTEx($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $tRECT = DllStructCreate($tagRECT) + _SendMessage($hWnd, $EM_GETRECT, 0, $tRECT, 0, "wparam", "struct*") + Return $tRECT +EndFunc ;==>_GUICtrlEdit_GetRECTEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetSel($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $aSel[2] + Local $tStart = DllStructCreate("uint Start") + Local $tEnd = DllStructCreate("uint End") + _SendMessage($hWnd, $EM_GETSEL, $tStart, $tEnd, 0, "struct*", "struct*") + $aSel[0] = DllStructGetData($tStart, "Start") + $aSel[1] = DllStructGetData($tEnd, "End") + Return $aSel +EndFunc ;==>_GUICtrlEdit_GetSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetText($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iTextLen = _GUICtrlEdit_GetTextLen($hWnd) + 1 + Local $tText = DllStructCreate("wchar Text[" & $iTextLen & "]") + _SendMessage($hWnd, $__EDITCONSTANT_WM_GETTEXT, $iTextLen, $tText, 0, "wparam", "struct*") + Return DllStructGetData($tText, "Text") +EndFunc ;==>_GUICtrlEdit_GetText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetTextLen($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $__EDITCONSTANT_WM_GETTEXTLENGTH) +EndFunc ;==>_GUICtrlEdit_GetTextLen + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_GetThumb +; Description ...: Retrieves the position of the scroll box (thumb) in the vertical scroll +; Syntax.........: _GUICtrlEdit_GetThumb ( $hWnd ) +; Parameters ....: $hWnd - Handle to the control +; Return values .: Success - The position of the scroll box +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: I think WM_VSCROLL events probably work better +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetThumb($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETTHUMB) +EndFunc ;==>_GUICtrlEdit_GetThumb + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_GetWordBreakProc +; Description ...: Retrieves the address of the current Wordwrap function +; Syntax.........: _GUICtrlEdit_GetWordBreakProc ( $hWnd ) +; Parameters ....: $hWnd - Handle to the control +; Return values .: Success - The address of the application-defined Wordwrap function +; Failure - 0 +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: _GUICtrlEdit_SetWordBreakProc +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_GetWordBreakProc($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_GETWORDBREAKPROC) +EndFunc ;==>_GUICtrlEdit_GetWordBreakProc + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_HideBalloonTip($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_HIDEBALLOONTIP) <> 0 +EndFunc ;==>_GUICtrlEdit_HideBalloonTip + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_InsertText($hWnd, $sText, $iIndex = -1) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + If $iIndex = -1 Then + _GUICtrlEdit_AppendText($hWnd, $sText) + Else + _GUICtrlEdit_SetSel($hWnd, $iIndex, $iIndex) + _SendMessage($hWnd, $EM_REPLACESEL, True, $sText, 0, "wparam", "wstr") + EndIf +EndFunc ;==>_GUICtrlEdit_InsertText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_LineFromChar($hWnd, $iIndex = -1) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_LINEFROMCHAR, $iIndex) +EndFunc ;==>_GUICtrlEdit_LineFromChar + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_LineIndex($hWnd, $iIndex = -1) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_LINEINDEX, $iIndex) +EndFunc ;==>_GUICtrlEdit_LineIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_LineLength($hWnd, $iIndex = -1) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $iCharIndex = _GUICtrlEdit_LineIndex($hWnd, $iIndex) + Return _SendMessage($hWnd, $EM_LINELENGTH, $iCharIndex) +EndFunc ;==>_GUICtrlEdit_LineLength + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_LineScroll($hWnd, $iHoriz, $iVert) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_LINESCROLL, $iHoriz, $iVert) <> 0 +EndFunc ;==>_GUICtrlEdit_LineScroll + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_PosFromChar($hWnd, $iIndex) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $aCoord[2] + Local $iRet = _SendMessage($hWnd, $EM_POSFROMCHAR, $iIndex) + $aCoord[0] = _WinAPI_LoWord($iRet) + $aCoord[1] = _WinAPI_HiWord($iRet) + Return $aCoord +EndFunc ;==>_GUICtrlEdit_PosFromChar + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_ReplaceSel($hWnd, $sText, $bUndo = True) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_REPLACESEL, $bUndo, $sText, 0, "wparam", "wstr") +EndFunc ;==>_GUICtrlEdit_ReplaceSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_Scroll($hWnd, $iDirection) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + If BitAND($iDirection, $__EDITCONSTANT_SB_LINEDOWN) <> $__EDITCONSTANT_SB_LINEDOWN And _ + BitAND($iDirection, $__EDITCONSTANT_SB_LINEUP) <> $__EDITCONSTANT_SB_LINEUP And _ + BitAND($iDirection, $__EDITCONSTANT_SB_PAGEDOWN) <> $__EDITCONSTANT_SB_PAGEDOWN And _ + BitAND($iDirection, $__EDITCONSTANT_SB_PAGEUP) <> $__EDITCONSTANT_SB_PAGEUP And _ + BitAND($iDirection, $__EDITCONSTANT_SB_SCROLLCARET) <> $__EDITCONSTANT_SB_SCROLLCARET Then Return 0 + + If $iDirection == $__EDITCONSTANT_SB_SCROLLCARET Then + Return _SendMessage($hWnd, $EM_SCROLLCARET) + Else + Return _SendMessage($hWnd, $EM_SCROLL, $iDirection) + EndIf +EndFunc ;==>_GUICtrlEdit_Scroll + +; #FUNCTION# ==================================================================================================================== +; Author ........: Guinness +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetCueBanner($hWnd, $sText, $bOnFocus = False) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $tText = _WinAPI_MultiByteToWideChar($sText) + + Return _SendMessage($hWnd, $EM_SETCUEBANNER, $bOnFocus, $tText, 0, "wparam", "struct*") = 1 +EndFunc ;==>_GUICtrlEdit_SetCueBanner + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_SetHandle +; Description ...: Sets the handle of the memory that will be used +; Syntax.........: _GUICtrlEdit_SetHandle ( $hWnd, $hMemory ) +; Parameters ....: $hWnd - Handle to the control +; $hMemory - A handle to the memory buffer the edit control uses to store the currently displayed text +; +instead of allocating its own memory +; Return values .: +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: _GUICtrlEdit_GetHandle +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetHandle($hWnd, $hMemory) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETHANDLE, $hMemory, 0, 0, "handle") +EndFunc ;==>_GUICtrlEdit_SetHandle + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_SetIMEStatus +; Description ...: Sets the status flags that determine how an edit control interacts with the Input Method Editor (IME) +; Syntax.........: _GUICtrlEdit_SetIMEStatus ( $hWnd, $iComposition ) +; Parameters ....: $hWnd - Handle to the control +; $iComposition - One or more of the following: +; |$EIMES_GETCOMPSTRATONCE - The edit control hooks the WM_IME_COMPOSITION message +; |$EIMES_CANCELCOMPSTRINFOCUS - The edit control cancels the composition string when it receives the WM_SETFOCUS message +; |$EIMES_COMPLETECOMPSTRKILLFOCUS - The edit control completes the composition string upon receiving the WM_KILLFOCUS message +; Return values .: Success - the previous value of the $iComposition parameter +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetIMEStatus($hWnd, $iComposition) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_SETIMESTATUS, $EMSIS_COMPOSITIONSTRING, $iComposition) +EndFunc ;==>_GUICtrlEdit_SetIMEStatus + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetLimitText($hWnd, $iLimit) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETLIMITTEXT, $iLimit) +EndFunc ;==>_GUICtrlEdit_SetLimitText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetMargins($hWnd, $iMargin = 0x1, $iLeft = 0xFFFF, $iRight = 0xFFFF) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETMARGINS, $iMargin, _WinAPI_MakeLong($iLeft, $iRight)) +EndFunc ;==>_GUICtrlEdit_SetMargins + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetModify($hWnd, $bModified) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETMODIFY, $bModified) +EndFunc ;==>_GUICtrlEdit_SetModify + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetPasswordChar($hWnd, $sDisplayChar = "0") + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + $sDisplayChar = StringLeft($sDisplayChar, 1) + If Asc($sDisplayChar) = 48 Then + _SendMessage($hWnd, $EM_SETPASSWORDCHAR) + Else + _SendMessage($hWnd, $EM_SETPASSWORDCHAR, Asc($sDisplayChar)) + EndIf +EndFunc ;==>_GUICtrlEdit_SetPasswordChar + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetReadOnly($hWnd, $bReadOnly) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_SETREADONLY, $bReadOnly) <> 0 +EndFunc ;==>_GUICtrlEdit_SetReadOnly + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetRECT($hWnd, $aRect) + Local $tRECT = DllStructCreate($tagRECT) + DllStructSetData($tRECT, "Left", $aRect[0]) + DllStructSetData($tRECT, "Top", $aRect[1]) + DllStructSetData($tRECT, "Right", $aRect[2]) + DllStructSetData($tRECT, "Bottom", $aRect[3]) + _GUICtrlEdit_SetRECTEx($hWnd, $tRECT) +EndFunc ;==>_GUICtrlEdit_SetRECT + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetRECTEx($hWnd, $tRECT) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETRECT, 0, $tRECT, 0, "wparam", "struct*") +EndFunc ;==>_GUICtrlEdit_SetRECTEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetRECTNP($hWnd, $aRect) + Local $tRECT = DllStructCreate($tagRECT) + DllStructSetData($tRECT, "Left", $aRect[0]) + DllStructSetData($tRECT, "Top", $aRect[1]) + DllStructSetData($tRECT, "Right", $aRect[2]) + DllStructSetData($tRECT, "Bottom", $aRect[3]) + _GUICtrlEdit_SetRectNPEx($hWnd, $tRECT) +EndFunc ;==>_GUICtrlEdit_SetRECTNP + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetRectNPEx($hWnd, $tRECT) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETRECTNP, 0, $tRECT, 0, "wparam", "struct*") +EndFunc ;==>_GUICtrlEdit_SetRectNPEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetSel($hWnd, $iStart, $iEnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETSEL, $iStart, $iEnd) +EndFunc ;==>_GUICtrlEdit_SetSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetTabStops($hWnd, $aTabStops) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + If Not IsArray($aTabStops) Then Return SetError(-1, -1, False) + + Local $sTabStops = "" + Local $iNumTabStops = UBound($aTabStops) + + For $x = 0 To $iNumTabStops - 1 + $sTabStops &= "int;" + Next + $sTabStops = StringTrimRight($sTabStops, 1) + Local $tTabStops = DllStructCreate($sTabStops) + For $x = 0 To $iNumTabStops - 1 + DllStructSetData($tTabStops, $x + 1, $aTabStops[$x]) + Next + Local $iRet = _SendMessage($hWnd, $EM_SETTABSTOPS, $iNumTabStops, $tTabStops, 0, "wparam", "struct*") <> 0 + _WinAPI_InvalidateRect($hWnd) + Return $iRet +EndFunc ;==>_GUICtrlEdit_SetTabStops + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetText($hWnd, $sText) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $__EDITCONSTANT_WM_SETTEXT, 0, $sText, 0, "wparam", "wstr") +EndFunc ;==>_GUICtrlEdit_SetText + +; #NO_DOC_FUNCTION# ============================================================================================================= +; Name...........: _GUICtrlEdit_SetWordBreakProc +; Description ...: Replaces an edit control's default Wordwrap function with an application-defined Wordwrap function +; Syntax.........: _GUICtrlEdit_SetWordBreakProc ( $hWnd, $iAddressFunc ) +; Parameters ....: $hWnd - Handle to the control +; $iAddressFunc - The address of the application-defined Wordwrap function +; Return values .: +; Author ........: Gary Frost (gafrost) +; Modified.......: +; Remarks .......: +; Related .......: _GUICtrlEdit_GetWordBreakProc +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func _GUICtrlEdit_SetWordBreakProc($hWnd, $iAddressFunc) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + _SendMessage($hWnd, $EM_SETWORDBREAKPROC, 0, $iAddressFunc) +EndFunc ;==>_GUICtrlEdit_SetWordBreakProc + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_ShowBalloonTip($hWnd, $sTitle, $sText, $iIcon) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $tTitle = _WinAPI_MultiByteToWideChar($sTitle) + Local $tText = _WinAPI_MultiByteToWideChar($sText) + Local $tTT = DllStructCreate($__tagEDITBALLOONTIP) + DllStructSetData($tTT, "Size", DllStructGetSize($tTT)) + DllStructSetData($tTT, "Title", DllStructGetPtr($tTitle)) + DllStructSetData($tTT, "Text", DllStructGetPtr($tText)) + DllStructSetData($tTT, "Icon", $iIcon) + Return _SendMessage($hWnd, $EM_SHOWBALLOONTIP, 0, $tTT, 0, "wparam", "struct*") <> 0 +EndFunc ;==>_GUICtrlEdit_ShowBalloonTip + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlEdit_Undo($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $EM_UNDO) <> 0 +EndFunc ;==>_GUICtrlEdit_Undo diff --git a/src/include/GuiListBox.au3 b/src/include/GuiListBox.au3 new file mode 100644 index 0000000..f4b896e --- /dev/null +++ b/src/include/GuiListBox.au3 @@ -0,0 +1,921 @@ +#include-once + +#include "DirConstants.au3" +#include "ListBoxConstants.au3" +#include "SendMessage.au3" +#include "UDFGlobalID.au3" +#include "WinAPI.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: ListBox +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with ListBox control management. +; Author(s) .....: Paul Campbell (PaulIA) +; =============================================================================================================================== + +; #VARIABLES# =================================================================================================================== +Global $__g_hLBLastWnd + +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $__LISTBOXCONSTANT_ClassName = "ListBox" +Global Const $__LISTBOXCONSTANT_ClassNames = $__LISTBOXCONSTANT_ClassName & "|TListbox" +Global Const $__LISTBOXCONSTANT_DEFAULT_GUI_FONT = 17 +Global Const $__LISTBOXCONSTANT_WM_SETREDRAW = 0x000B +Global Const $__LISTBOXCONSTANT_WM_GETFONT = 0x0031 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _GUICtrlListBox_AddFile +; _GUICtrlListBox_AddString +; _GUICtrlListBox_BeginUpdate +; _GUICtrlListBox_ClickItem +; _GUICtrlListBox_Create +; _GUICtrlListBox_DeleteString +; _GUICtrlListBox_Destroy +; _GUICtrlListBox_Dir +; _GUICtrlListBox_EndUpdate +; _GUICtrlListBox_FindString +; _GUICtrlListBox_FindInText +; _GUICtrlListBox_GetAnchorIndex +; _GUICtrlListBox_GetCaretIndex +; _GUICtrlListBox_GetCount +; _GUICtrlListBox_GetCurSel +; _GUICtrlListBox_GetHorizontalExtent +; _GUICtrlListBox_GetItemData +; _GUICtrlListBox_GetItemHeight +; _GUICtrlListBox_GetItemRect +; _GUICtrlListBox_GetItemRectEx +; _GUICtrlListBox_GetListBoxInfo +; _GUICtrlListBox_GetLocale +; _GUICtrlListBox_GetLocaleCountry +; _GUICtrlListBox_GetLocaleLang +; _GUICtrlListBox_GetLocalePrimLang +; _GUICtrlListBox_GetLocaleSubLang +; _GUICtrlListBox_GetSel +; _GUICtrlListBox_GetSelCount +; _GUICtrlListBox_GetSelItems +; _GUICtrlListBox_GetSelItemsText +; _GUICtrlListBox_GetText +; _GUICtrlListBox_GetTextLen +; _GUICtrlListBox_GetTopIndex +; _GUICtrlListBox_InitStorage +; _GUICtrlListBox_InsertString +; _GUICtrlListBox_ItemFromPoint +; _GUICtrlListBox_ReplaceString +; _GUICtrlListBox_ResetContent +; _GUICtrlListBox_SelectString +; _GUICtrlListBox_SelItemRange +; _GUICtrlListBox_SelItemRangeEx +; _GUICtrlListBox_SetAnchorIndex +; _GUICtrlListBox_SetCaretIndex +; _GUICtrlListBox_SetColumnWidth +; _GUICtrlListBox_SetCurSel +; _GUICtrlListBox_SetHorizontalExtent +; _GUICtrlListBox_SetItemData +; _GUICtrlListBox_SetItemHeight +; _GUICtrlListBox_SetLocale +; _GUICtrlListBox_SetSel +; _GUICtrlListBox_SetTabStops +; _GUICtrlListBox_SetTopIndex +; _GUICtrlListBox_Sort +; _GUICtrlListBox_SwapString +; _GUICtrlListBox_UpdateHScroll +; =============================================================================================================================== + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_AddFile($hWnd, $sFilePath) + If Not IsString($sFilePath) Then $sFilePath = String($sFilePath) + + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_ADDFILE, 0, $sFilePath, 0, "wparam", "wstr") + Else + Return GUICtrlSendMsg($hWnd, $LB_ADDFILE, 0, $sFilePath) + EndIf +EndFunc ;==>_GUICtrlListBox_AddFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_AddString($hWnd, $sText) + If Not IsString($sText) Then $sText = String($sText) + + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_ADDSTRING, 0, $sText, 0, "wparam", "wstr") + Else + Return GUICtrlSendMsg($hWnd, $LB_ADDSTRING, 0, $sText) + EndIf +EndFunc ;==>_GUICtrlListBox_AddString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_BeginUpdate($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $__LISTBOXCONSTANT_WM_SETREDRAW, False) = 0 +EndFunc ;==>_GUICtrlListBox_BeginUpdate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_ClickItem($hWnd, $iIndex, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 0) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Local $tRECT = _GUICtrlListBox_GetItemRectEx($hWnd, $iIndex) + Local $tPoint = _WinAPI_PointFromRect($tRECT) + $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint) + Local $iX, $iY + _WinAPI_GetXYFromPoint($tPoint, $iX, $iY) + Local $iMode = Opt("MouseCoordMode", 1) + If Not $bMove Then + Local $aPos = MouseGetPos() + _WinAPI_ShowCursor(False) + MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed) + MouseMove($aPos[0], $aPos[1], 0) + _WinAPI_ShowCursor(True) + Else + MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed) + EndIf + Opt("MouseCoordMode", $iMode) +EndFunc ;==>_GUICtrlListBox_ClickItem + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost +; =============================================================================================================================== +Func _GUICtrlListBox_Create($hWnd, $sText, $iX, $iY, $iWidth = 100, $iHeight = 200, $iStyle = 0x00B00002, $iExStyle = 0x00000200) + If Not IsHWnd($hWnd) Then + ; Invalid Window handle for _GUICtrlListBox_Create 1st parameter + Return SetError(1, 0, 0) + EndIf + If Not IsString($sText) Then + ; 2nd parameter not a string for _GUICtrlListBox_Create + Return SetError(2, 0, 0) + EndIf + + If $iWidth = -1 Then $iWidth = 100 + If $iHeight = -1 Then $iHeight = 200 + Local Const $WS_VSCROLL = 0x00200000, $WS_HSCROLL = 0x00100000, $WS_BORDER = 0x00800000 + If $iStyle = -1 Then $iStyle = BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL, $LBS_SORT) + If $iExStyle = -1 Then $iExStyle = 0x00000200 + + $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_VISIBLE, $__UDFGUICONSTANT_WS_TABSTOP, $__UDFGUICONSTANT_WS_CHILD, $LBS_NOTIFY) + + Local $nCtrlID = __UDF_GetNextGlobalID($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Local $hList = _WinAPI_CreateWindowEx($iExStyle, $__LISTBOXCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID) + _WinAPI_SetFont($hList, _WinAPI_GetStockObject($__LISTBOXCONSTANT_DEFAULT_GUI_FONT)) + If StringLen($sText) Then _GUICtrlListBox_AddString($hList, $sText) + Return $hList +EndFunc ;==>_GUICtrlListBox_Create + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_DeleteString($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_DELETESTRING, $iIndex) + Else + Return GUICtrlSendMsg($hWnd, $LB_DELETESTRING, $iIndex, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_DeleteString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_Destroy(ByRef $hWnd) + ;If Not _WinAPI_IsClassName($hWnd, $__LISTBOXCONSTANT_ClassNames) Then Return SetError(2, 2, False) + + Local $iDestroyed = 0 + If IsHWnd($hWnd) Then + If _WinAPI_InProcess($hWnd, $__g_hLBLastWnd) Then + Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd) + Local $hParent = _WinAPI_GetParent($hWnd) + $iDestroyed = _WinAPI_DestroyWindow($hWnd) + Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID) + If Not $iRet Then + ; can check for errors here if needed, for debug + EndIf + Else + ; Not Allowed to Destroy Other Applications Control(s) + Return SetError(1, 1, False) + EndIf + Else + $iDestroyed = GUICtrlDelete($hWnd) + EndIf + If $iDestroyed Then $hWnd = 0 + Return $iDestroyed <> 0 +EndFunc ;==>_GUICtrlListBox_Destroy + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_Dir($hWnd, $sFilePath, $iAttributes = 0, $bBrackets = True) + If Not IsString($sFilePath) Then $sFilePath = String($sFilePath) + + If BitAND($iAttributes, $DDL_DRIVES) = $DDL_DRIVES And Not $bBrackets Then + Local $sText + Local $hGui_no_brackets = GUICreate("no brackets") + Local $idList_no_brackets = GUICtrlCreateList("", 240, 40, 120, 120) + Local $iRet = GUICtrlSendMsg($idList_no_brackets, $LB_DIR, $iAttributes, $sFilePath) + For $i = 0 To _GUICtrlListBox_GetCount($idList_no_brackets) - 1 + $sText = _GUICtrlListBox_GetText($idList_no_brackets, $i) + $sText = StringReplace(StringReplace(StringReplace($sText, "[", ""), "]", ":"), "-", "") + _GUICtrlListBox_InsertString($hWnd, $sText) + Next + GUIDelete($hGui_no_brackets) + Return $iRet + Else + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_DIR, $iAttributes, $sFilePath, 0, "wparam", "wstr") + Else + Return GUICtrlSendMsg($hWnd, $LB_DIR, $iAttributes, $sFilePath) + EndIf + EndIf +EndFunc ;==>_GUICtrlListBox_Dir + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_EndUpdate($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + + Return _SendMessage($hWnd, $__LISTBOXCONSTANT_WM_SETREDRAW, True) = 0 +EndFunc ;==>_GUICtrlListBox_EndUpdate + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_FindString($hWnd, $sText, $bExact = False) + If Not IsString($sText) Then $sText = String($sText) + + If IsHWnd($hWnd) Then + If ($bExact) Then + Return _SendMessage($hWnd, $LB_FINDSTRINGEXACT, -1, $sText, 0, "wparam", "wstr") + Else + Return _SendMessage($hWnd, $LB_FINDSTRING, -1, $sText, 0, "wparam", "wstr") + EndIf + Else + If ($bExact) Then + Return GUICtrlSendMsg($hWnd, $LB_FINDSTRINGEXACT, -1, $sText) + Else + Return GUICtrlSendMsg($hWnd, $LB_FINDSTRING, -1, $sText) + EndIf + EndIf +EndFunc ;==>_GUICtrlListBox_FindString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_FindInText($hWnd, $sText, $iStart = -1, $bWrapOK = True) + Local $sList + + Local $iCount = _GUICtrlListBox_GetCount($hWnd) + For $iI = $iStart + 1 To $iCount - 1 + $sList = _GUICtrlListBox_GetText($hWnd, $iI) + If StringInStr($sList, $sText) Then Return $iI + Next + + If ($iStart = -1) Or Not $bWrapOK Then Return -1 + For $iI = 0 To $iStart - 1 + $sList = _GUICtrlListBox_GetText($hWnd, $iI) + If StringInStr($sList, $sText) Then Return $iI + Next + + Return -1 +EndFunc ;==>_GUICtrlListBox_FindInText + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetAnchorIndex($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETANCHORINDEX) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETANCHORINDEX, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetAnchorIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetCaretIndex($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETCARETINDEX) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETCARETINDEX, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetCaretIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetCount($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETCOUNT) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETCOUNT, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetCount + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetCurSel($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETCURSEL) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETCURSEL, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetCurSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetHorizontalExtent($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETHORIZONTALEXTENT) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETHORIZONTALEXTENT, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetHorizontalExtent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetItemData($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETITEMDATA, $iIndex) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETITEMDATA, $iIndex, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetItemData + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetItemHeight($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETITEMHEIGHT) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETITEMHEIGHT, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetItemHeight + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetItemRect($hWnd, $iIndex) + Local $aRect[4] + + Local $tRECT = _GUICtrlListBox_GetItemRectEx($hWnd, $iIndex) + $aRect[0] = DllStructGetData($tRECT, "Left") + $aRect[1] = DllStructGetData($tRECT, "Top") + $aRect[2] = DllStructGetData($tRECT, "Right") + $aRect[3] = DllStructGetData($tRECT, "Bottom") + Return $aRect +EndFunc ;==>_GUICtrlListBox_GetItemRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetItemRectEx($hWnd, $iIndex) + Local $tRECT = DllStructCreate($tagRECT) + If IsHWnd($hWnd) Then + _SendMessage($hWnd, $LB_GETITEMRECT, $iIndex, $tRECT, 0, "wparam", "struct*") + Else + GUICtrlSendMsg($hWnd, $LB_GETITEMRECT, $iIndex, DllStructGetPtr($tRECT)) + EndIf + Return $tRECT +EndFunc ;==>_GUICtrlListBox_GetItemRectEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetListBoxInfo($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETLISTBOXINFO) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETLISTBOXINFO, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetListBoxInfo + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetLocale($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETLOCALE) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETLOCALE, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetLocale + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetLocaleCountry($hWnd) + Return _WinAPI_HiWord(_GUICtrlListBox_GetLocale($hWnd)) +EndFunc ;==>_GUICtrlListBox_GetLocaleCountry + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetLocaleLang($hWnd) + Return _WinAPI_LoWord(_GUICtrlListBox_GetLocale($hWnd)) +EndFunc ;==>_GUICtrlListBox_GetLocaleLang + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetLocalePrimLang($hWnd) + Return _WinAPI_PrimaryLangId(_GUICtrlListBox_GetLocaleLang($hWnd)) +EndFunc ;==>_GUICtrlListBox_GetLocalePrimLang + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetLocaleSubLang($hWnd) + Return _WinAPI_SubLangId(_GUICtrlListBox_GetLocaleLang($hWnd)) +EndFunc ;==>_GUICtrlListBox_GetLocaleSubLang + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetSel($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETSEL, $iIndex) <> 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_GETSEL, $iIndex, 0) <> 0 + EndIf +EndFunc ;==>_GUICtrlListBox_GetSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetSelCount($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETSELCOUNT) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETSELCOUNT, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetSelCount + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetSelItems($hWnd) + Local $aArray[1] = [0] + + Local $iCount = _GUICtrlListBox_GetSelCount($hWnd) + If $iCount > 0 Then + ReDim $aArray[$iCount + 1] + Local $tArray = DllStructCreate("int[" & $iCount & "]") + If IsHWnd($hWnd) Then + _SendMessage($hWnd, $LB_GETSELITEMS, $iCount, $tArray, 0, "wparam", "struct*") + Else + GUICtrlSendMsg($hWnd, $LB_GETSELITEMS, $iCount, DllStructGetPtr($tArray)) + EndIf + $aArray[0] = $iCount + For $iI = 1 To $iCount + $aArray[$iI] = DllStructGetData($tArray, 1, $iI) + Next + EndIf + Return $aArray +EndFunc ;==>_GUICtrlListBox_GetSelItems + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_GetSelItemsText($hWnd) + Local $aText[1] = [0], $iCount = _GUICtrlListBox_GetSelCount($hWnd) + If $iCount > 0 Then + Local $aIndices = _GUICtrlListBox_GetSelItems($hWnd) + ReDim $aText[UBound($aIndices)] + $aText[0] = $aIndices[0] + For $i = 1 To $aIndices[0] + $aText[$i] = _GUICtrlListBox_GetText($hWnd, $aIndices[$i]) + Next + EndIf + Return $aText +EndFunc ;==>_GUICtrlListBox_GetSelItemsText + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost +; =============================================================================================================================== +Func _GUICtrlListBox_GetText($hWnd, $iIndex) + Local $tText = DllStructCreate("wchar Text[" & _GUICtrlListBox_GetTextLen($hWnd, $iIndex) + 1 & "]") + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + _SendMessage($hWnd, $LB_GETTEXT, $iIndex, $tText, 0, "wparam", "struct*") + Return DllStructGetData($tText, "Text") +EndFunc ;==>_GUICtrlListBox_GetText + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetTextLen($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETTEXTLEN, $iIndex) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETTEXTLEN, $iIndex, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetTextLen + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_GetTopIndex($hWnd) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_GETTOPINDEX) + Else + Return GUICtrlSendMsg($hWnd, $LB_GETTOPINDEX, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_GetTopIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_InitStorage($hWnd, $iItems, $iBytes) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_INITSTORAGE, $iItems, $iBytes) + Else + Return GUICtrlSendMsg($hWnd, $LB_INITSTORAGE, $iItems, $iBytes) + EndIf +EndFunc ;==>_GUICtrlListBox_InitStorage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_InsertString($hWnd, $sText, $iIndex = -1) + If Not IsString($sText) Then $sText = String($sText) + + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_INSERTSTRING, $iIndex, $sText, 0, "wparam", "wstr") + Else + Return GUICtrlSendMsg($hWnd, $LB_INSERTSTRING, $iIndex, $sText) + EndIf +EndFunc ;==>_GUICtrlListBox_InsertString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_ItemFromPoint($hWnd, $iX, $iY) + Local $iRet + + If IsHWnd($hWnd) Then + $iRet = _SendMessage($hWnd, $LB_ITEMFROMPOINT, 0, _WinAPI_MakeLong($iX, $iY)) + Else + $iRet = GUICtrlSendMsg($hWnd, $LB_ITEMFROMPOINT, 0, _WinAPI_MakeLong($iX, $iY)) + EndIf + + If _WinAPI_HiWord($iRet) <> 0 Then $iRet = -1 + Return $iRet +EndFunc ;==>_GUICtrlListBox_ItemFromPoint + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_ReplaceString($hWnd, $iIndex, $sText) + If (_GUICtrlListBox_DeleteString($hWnd, $iIndex) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, False) + If (_GUICtrlListBox_InsertString($hWnd, $sText, $iIndex) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, False) + Return True +EndFunc ;==>_GUICtrlListBox_ReplaceString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_ResetContent($hWnd) + If IsHWnd($hWnd) Then + _SendMessage($hWnd, $LB_RESETCONTENT) + Else + GUICtrlSendMsg($hWnd, $LB_RESETCONTENT, 0, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_ResetContent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SelectString($hWnd, $sText, $iIndex = -1) + If Not IsString($sText) Then $sText = String($sText) + + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SELECTSTRING, $iIndex, $sText, 0, "wparam", "wstr") + Else + Return GUICtrlSendMsg($hWnd, $LB_SELECTSTRING, $iIndex, $sText) + EndIf +EndFunc ;==>_GUICtrlListBox_SelectString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: Gary Frost (gafrost, re-written +; =============================================================================================================================== +Func _GUICtrlListBox_SelItemRange($hWnd, $iFirst, $iLast, $bSelect = True) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SELITEMRANGE, $bSelect, _WinAPI_MakeLong($iFirst, $iLast)) = 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_SELITEMRANGE, $bSelect, _WinAPI_MakeLong($iFirst, $iLast)) = 0 + EndIf +EndFunc ;==>_GUICtrlListBox_SelItemRange + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SelItemRangeEx($hWnd, $iFirst, $iLast) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SELITEMRANGEEX, $iFirst, $iLast) = 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_SELITEMRANGEEX, $iFirst, $iLast) = 0 + EndIf +EndFunc ;==>_GUICtrlListBox_SelItemRangeEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SetAnchorIndex($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETANCHORINDEX, $iIndex) = 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETANCHORINDEX, $iIndex, 0) = 0 + EndIf +EndFunc ;==>_GUICtrlListBox_SetAnchorIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SetCaretIndex($hWnd, $iIndex, $bPartial = False) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETCARETINDEX, $iIndex, $bPartial) = 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETCARETINDEX, $iIndex, $bPartial) = 0 + EndIf +EndFunc ;==>_GUICtrlListBox_SetCaretIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetColumnWidth($hWnd, $iWidth) + If IsHWnd($hWnd) Then + _SendMessage($hWnd, $LB_SETCOLUMNWIDTH, $iWidth) + Else + GUICtrlSendMsg($hWnd, $LB_SETCOLUMNWIDTH, $iWidth, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_SetColumnWidth + +; #FUNCTION# ==================================================================================================================== +; Author ........: Sokko +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetCurSel($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETCURSEL, $iIndex) + Else + Return GUICtrlSendMsg($hWnd, $LB_SETCURSEL, $iIndex, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_SetCurSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SetHorizontalExtent($hWnd, $iWidth) + If IsHWnd($hWnd) Then + _SendMessage($hWnd, $LB_SETHORIZONTALEXTENT, $iWidth) + Else + GUICtrlSendMsg($hWnd, $LB_SETHORIZONTALEXTENT, $iWidth, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_SetHorizontalExtent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetItemData($hWnd, $iIndex, $iValue) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETITEMDATA, $iIndex, $iValue) <> -1 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETITEMDATA, $iIndex, $iValue) <> -1 + EndIf +EndFunc ;==>_GUICtrlListBox_SetItemData + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetItemHeight($hWnd, $iHeight, $iIndex = 0) + Local $iRet + + If IsHWnd($hWnd) Then + $iRet = _SendMessage($hWnd, $LB_SETITEMHEIGHT, $iIndex, $iHeight) + _WinAPI_InvalidateRect($hWnd) + Else + $iRet = GUICtrlSendMsg($hWnd, $LB_SETITEMHEIGHT, $iIndex, $iHeight) + _WinAPI_InvalidateRect(GUICtrlGetHandle($hWnd)) + EndIf + Return $iRet <> -1 +EndFunc ;==>_GUICtrlListBox_SetItemHeight + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetLocale($hWnd, $iLocal) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETLOCALE, $iLocal) + Else + Return GUICtrlSendMsg($hWnd, $LB_SETLOCALE, $iLocal, 0) + EndIf +EndFunc ;==>_GUICtrlListBox_SetLocale + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SetSel($hWnd, $iIndex = -1, $iSelect = -1) + Local $i_Ret = 1 + If IsHWnd($hWnd) Then + If $iIndex == -1 Then ; toggle all + For $iIndex = 0 To _GUICtrlListBox_GetCount($hWnd) - 1 + $i_Ret = _GUICtrlListBox_GetSel($hWnd, $iIndex) + If ($i_Ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, False) + If ($i_Ret > 0) Then ;If Selected Then + $i_Ret = _SendMessage($hWnd, $LB_SETSEL, False, $iIndex) <> -1 + Else + $i_Ret = _SendMessage($hWnd, $LB_SETSEL, True, $iIndex) <> -1 + EndIf + If ($i_Ret == False) Then Return SetError($LB_ERR, $LB_ERR, False) + Next + ElseIf $iSelect == -1 Then ; toggle state of index + If _GUICtrlListBox_GetSel($hWnd, $iIndex) Then ;If Selected Then + Return _SendMessage($hWnd, $LB_SETSEL, False, $iIndex) <> -1 + Else + Return _SendMessage($hWnd, $LB_SETSEL, True, $iIndex) <> -1 + EndIf + Else ; set state according to flag + Return _SendMessage($hWnd, $LB_SETSEL, $iSelect, $iIndex) <> -1 + EndIf + Else + If $iIndex == -1 Then ; toggle all + For $iIndex = 0 To _GUICtrlListBox_GetCount($hWnd) - 1 + $i_Ret = _GUICtrlListBox_GetSel($hWnd, $iIndex) + If ($i_Ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, False) + If ($i_Ret > 0) Then ;If Selected Then + $i_Ret = GUICtrlSendMsg($hWnd, $LB_SETSEL, False, $iIndex) <> -1 + Else + $i_Ret = GUICtrlSendMsg($hWnd, $LB_SETSEL, True, $iIndex) <> -1 + EndIf + If ($i_Ret == 0) Then Return SetError($LB_ERR, $LB_ERR, False) + Next + ElseIf $iSelect == -1 Then ; toggle state of index + If _GUICtrlListBox_GetSel($hWnd, $iIndex) Then ;If Selected Then + Return GUICtrlSendMsg($hWnd, $LB_SETSEL, False, $iIndex) <> -1 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETSEL, True, $iIndex) <> -1 + EndIf + Else ; set state according to flag + Return GUICtrlSendMsg($hWnd, $LB_SETSEL, $iSelect, $iIndex) <> -1 + EndIf + EndIf + Return $i_Ret <> 0 +EndFunc ;==>_GUICtrlListBox_SetSel + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetTabStops($hWnd, $aTabStops) + Local $iCount = $aTabStops[0] + Local $tTabStops = DllStructCreate("int[" & $iCount & "]") + For $iI = 1 To $iCount + DllStructSetData($tTabStops, 1, $aTabStops[$iI], $iI) + Next + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETTABSTOPS, $iCount, $tTabStops, 0, "wparam", "struct*") = 0 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETTABSTOPS, $iCount, DllStructGetPtr($tTabStops)) = 0 + EndIf +EndFunc ;==>_GUICtrlListBox_SetTabStops + +; #FUNCTION# ==================================================================================================================== +; Author ........: CyberSlug +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_SetTopIndex($hWnd, $iIndex) + If IsHWnd($hWnd) Then + Return _SendMessage($hWnd, $LB_SETTOPINDEX, $iIndex) <> -1 + Else + Return GUICtrlSendMsg($hWnd, $LB_SETTOPINDEX, $iIndex, 0) <> -1 + EndIf +EndFunc ;==>_GUICtrlListBox_SetTopIndex + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), CyberSlug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_Sort($hWnd) + Local $sBak = _GUICtrlListBox_GetText($hWnd, 0) + If ($sBak == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + If (_GUICtrlListBox_DeleteString($hWnd, 0) == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + Return _GUICtrlListBox_AddString($hWnd, $sBak) <> -1 +EndFunc ;==>_GUICtrlListBox_Sort + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost), Cyberslug +; Modified.......: +; =============================================================================================================================== +Func _GUICtrlListBox_SwapString($hWnd, $iIndexA, $iIndexB) + Local $sItemA = _GUICtrlListBox_GetText($hWnd, $iIndexA) + Local $sItemB = _GUICtrlListBox_GetText($hWnd, $iIndexB) + If (_GUICtrlListBox_DeleteString($hWnd, $iIndexA) == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + If (_GUICtrlListBox_InsertString($hWnd, $sItemB, $iIndexA) == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + + If (_GUICtrlListBox_DeleteString($hWnd, $iIndexB) == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + If (_GUICtrlListBox_InsertString($hWnd, $sItemA, $iIndexB) == -1) Then Return SetError($LB_ERR, $LB_ERR, False) + Return True +EndFunc ;==>_GUICtrlListBox_SwapString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _GUICtrlListBox_UpdateHScroll($hWnd) + Local $hDC, $hFont, $tSize, $sText + Local $iMax = 0 + If IsHWnd($hWnd) Then + $hFont = _SendMessage($hWnd, $__LISTBOXCONSTANT_WM_GETFONT) + $hDC = _WinAPI_GetDC($hWnd) + _WinAPI_SelectObject($hDC, $hFont) + For $iI = 0 To _GUICtrlListBox_GetCount($hWnd) - 1 + $sText = _GUICtrlListBox_GetText($hWnd, $iI) + $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText & "W") + If DllStructGetData($tSize, "X") > $iMax Then + $iMax = DllStructGetData($tSize, "X") + EndIf + Next + _GUICtrlListBox_SetHorizontalExtent($hWnd, $iMax) + _WinAPI_SelectObject($hDC, $hFont) + _WinAPI_ReleaseDC($hWnd, $hDC) + Else + $hFont = GUICtrlSendMsg($hWnd, $__LISTBOXCONSTANT_WM_GETFONT, 0, 0) + Local $hWnd_t = GUICtrlGetHandle($hWnd) + $hDC = _WinAPI_GetDC($hWnd_t) + _WinAPI_SelectObject($hDC, $hFont) + For $iI = 0 To _GUICtrlListBox_GetCount($hWnd) - 1 + $sText = _GUICtrlListBox_GetText($hWnd, $iI) + $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText & "W") + If DllStructGetData($tSize, "X") > $iMax Then + $iMax = DllStructGetData($tSize, "X") + EndIf + Next + _GUICtrlListBox_SetHorizontalExtent($hWnd, $iMax) + _WinAPI_SelectObject($hDC, $hFont) + _WinAPI_ReleaseDC($hWnd_t, $hDC) + EndIf +EndFunc ;==>_GUICtrlListBox_UpdateHScroll diff --git a/src/include/Misc.au3 b/src/include/Misc.au3 new file mode 100644 index 0000000..337ebbe --- /dev/null +++ b/src/include/Misc.au3 @@ -0,0 +1,530 @@ +#include-once + +#include "FontConstants.au3" +#include "StructureConstants.au3" +#include "WinAPIError.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: Misc +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with Common Dialogs. +; Author(s) .....: Gary Frost, Florian Fida (Piccaso), Dale (Klaatu) Thompson, Valik, ezzetabi, Jon, Paul Campbell (PaulIA) +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $__MISCCONSTANT_CC_ANYCOLOR = 0x0100 +Global Const $__MISCCONSTANT_CC_FULLOPEN = 0x0002 +Global Const $__MISCCONSTANT_CC_RGBINIT = 0x0001 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _ChooseColor +; _ChooseFont +; _ClipPutFile +; _MouseTrap +; _Singleton +; _IsPressed +; _VersionCompare +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; $tagCHOOSECOLOR +; $tagCHOOSEFONT +; __MISC_GetDC +; __MISC_GetDeviceCaps +; __MISC_ReleaseDC +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagCHOOSECOLOR +; Description ...: Contains information the _ChooseColor function uses to initialize the Color dialog box +; Fields ........: Size - Specifies the size, in bytes, of the structure +; hWndOwner - Handle to the window that owns the dialog box +; hInstance - If the $CC_ENABLETEMPLATEHANDLE flag is set in the Flags member, hInstance is a handle to a memory +; +object containing a dialog box template. If the $CC_ENABLETEMPLATE flag is set, hInstance is a handle to a module +; +that contains a dialog box template named by the lpTemplateName member. If neither $CC_ENABLETEMPLATEHANDLE +; +nor $CC_ENABLETEMPLATE is set, this member is ignored. +; rgbResult - If the $CC_RGBINIT flag is set, rgbResult specifies the color initially selected when the dialog +; +box is created. +; CustColors - Pointer to an array of 16 values that contain red, green, blue (RGB) values for the custom color +; +boxes in the dialog box. +; Flags - A set of bit flags that you can use to initialize the Color dialog box. When the dialog box returns, +; +it sets these flags to indicate the user's input. This member can be a combination of the following flags: +; |$CC_ANYCOLOR - Causes the dialog box to display all available colors in the set of basic colors +; |$CC_ENABLEHOOK - Enables the hook procedure specified in the lpfnHook member +; |$CC_ENABLETEMPLATE - Indicates that the hInstance and lpTemplateName members specify a dialog box template +; |$CC_ENABLETEMPLATEHANDLE - Indicates that the hInstance member identifies a data block that contains a preloaded +; +dialog box template +; |$CC_FULLOPEN - Causes the dialog box to display the additional controls that allow the user to create +; +custom colors +; |$CC_PREVENTFULLOPEN - Disables the Define Custom Color +; |$CC_RGBINIT - Causes the dialog box to use the color specified in the rgbResult member as the initial +; +color selection +; |$CC_SHOWHELP - Causes the dialog box to display the Help button +; |$CC_SOLIDCOLOR - Causes the dialog box to display only solid colors in the set of basic colors +; lCustData - Specifies application-defined data that the system passes to the hook procedure identified by the +; +lpfnHook member +; lpfnHook - Pointer to a CCHookProc hook procedure that can process messages intended for the dialog box. +; +This member is ignored unless the CC_ENABLEHOOK flag is set in the Flags member +; lpTemplateName - Pointer to a null-terminated string that names the dialog box template resource in the module +; +identified by the hInstance m +; Author ........: Gary Frost (gafrost) +; Remarks .......: +; =============================================================================================================================== +Global Const $tagCHOOSECOLOR = "dword Size;hwnd hWndOwnder;handle hInstance;dword rgbResult;ptr CustColors;dword Flags;lparam lCustData;" & _ + "ptr lpfnHook;ptr lpTemplateName" + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagCHOOSEFONT +; Description ...: Contains information that the _ChooseFont function uses to initialize the Font dialog box +; Fields ........: Size - Specifies the size, in bytes, of the structure +; hWndOwner - Handle to the window that owns the dialog box +; hDC - Handle to the device context +; LogFont - Pointer to a structure +; PointSize - Specifies the size of the selected font, in units of 1/10 of a point +; Flags - A set of bit flags that you can use to initialize the Font dialog box. +; +This parameter can be one of the following values: +; |$CF_APPLY - Causes the dialog box to display the Apply button +; |$CF_ANSIONLY - This flag is obsolete +; |$CF_TTONLY - Specifies that ChooseFont should only enumerate and allow the selection of TrueType fonts +; |$CF_EFFECTS - Causes the dialog box to display the controls that allow the user to specify strikeout, +; +underline, and text color options +; |$CF_ENABLEHOOK - Enables the hook procedure specified in the lpfnHook member of this structure +; |$CF_ENABLETEMPLATE - Indicates that the hInstance and lpTemplateName members specify a dialog box template to use +; +in place of the default template +; |$CF_ENABLETEMPLATEHANDLE - Indicates that the hInstance member identifies a data block that contains a preloaded +; +dialog box template +; |$CF_FIXEDPITCHONLY - Specifies that ChooseFont should select only fixed-pitch fonts +; |$CF_FORCEFONTEXIST - Specifies that ChooseFont should indicate an error condition if the user attempts to select +; +a font or style that does not exist. +; |$CF_INITTOLOGFONTSTRUCT - Specifies that ChooseFont should use the structure pointed to by the lpLogFont member +; +to initialize the dialog box controls. +; |$CF_LIMITSIZE - Specifies that ChooseFont should select only font sizes within the range specified by the nSizeMin and nSizeMax members. +; |$CF_NOOEMFONTS - Same as the $CF_NOVECTORFONTS flag. +; |$CF_NOFACESEL - When using a LOGFONT structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box +; +from displaying an initial selection for the font name combo box. +; |$CF_NOSCRIPTSEL - Disables the Script combo box. +; |$CF_NOSTYLESEL - When using a LOGFONT structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box +; +from displaying an initial selection for the font style combo box. +; |$CF_NOSIZESEL - When using a structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box from +; +displaying an initial selection for the font size combo box. +; |$CF_NOSIMULATIONS - Specifies that ChooseFont should not allow graphics device interface (GDI) font simulations. +; |$CF_NOVECTORFONTS - Specifies that ChooseFont should not allow vector font selections. +; |$CF_NOVERTFONTS - Causes the Font dialog box to list only horizontally oriented fonts. +; |$CF_PRINTERFONTS - Causes the dialog box to list only the fonts supported by the printer associated with the device context +; +(or information context) identified by the hDC member. +; |$CF_SCALABLEONLY - Specifies that ChooseFont should allow only the selection of scalable fonts. +; |$CF_SCREENFONTS - Causes the dialog box to list only the screen fonts supported by the system. +; |$CF_SCRIPTSONLY - Specifies that ChooseFont should allow selection of fonts for all non-OEM and Symbol character sets, as well as +; +the ANSI character set. This supersedes the $CF_ANSIONLY value. +; |$CF_SELECTSCRIPT - When specified on input, only fonts with the character set identified in the lfCharSet member of the LOGFONT +; +structure are displayed. +; |$CF_SHOWHELP - Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING +; +registered messages that the dialog box sends when the user clicks the Help button. +; |$CF_USESTYLE - Specifies that the lpszStyle member is a pointer to a buffer that contains style data that ChooseFont should use to initialize +; +the Font Style combo box. When the user closes the dialog box, ChooseFont copies style data for the user's selection to this buffer. +; |$CF_WYSIWYG - Specifies that ChooseFont should allow only the selection of fonts available on both the printer and the display +; rgbColors - If the CF_EFFECTS flag is set, rgbColors specifies the initial text color +; CustData - Specifies application-defined data that the system passes to the hook procedure identified by the lpfnHook member +; fnHook - Pointer to a CFHookProc hook procedure that can process messages intended for the dialog box +; TemplateName - Pointer to a null-terminated string that names the dialog box template resource in the module +; +identified by the hInstance member +; hInstance - If the $CF_ENABLETEMPLATEHANDLE flag is set in the Flags member, hInstance is a handle to a memory +; +object containing a dialog box template. If the $CF_ENABLETEMPLATE flag is set, hInstance is a handle to a +; +module that contains a dialog box template named by the TemplateName member. If neither $CF_ENABLETEMPLATEHANDLE +; +nor $CF_ENABLETEMPLATE is set, this member is ignored. +; szStyle - Pointer to a buffer that contains style data +; FontType - Specifies the type of the selected font when ChooseFont returns. This member can be one or more of the following values. +; |$BOLD_FONTTYPE - The font weight is bold. This information is duplicated in the lfWeight member of the LOGFONT +; +structure and is equivalent to FW_BOLD. +; |$iItalic_FONTTYPE - The italic font attribute is set. This information is duplicated in the lfItalic member of the LOGFONT structure. +; |$PRINTER_FONTTYPE - The font is a printer font. +; |$REGULAR_FONTTYPE - The font weight is normal. This information is duplicated in the lfWeight member of the LOGFONT structure and is +; +equivalent to FW_REGULAR. +; |$SCREEN_FONTTYPE - The font is a screen font. +; |$SIMULATED_FONTTYPE - The font is simulated by the graphics device interface (GDI). +; SizeMin - Specifies the minimum point size a user can select +; SizeMax - Specifies the maximum point size a user can select +; Author ........: Gary Frost (gafrost) +; Remarks .......: +; =============================================================================================================================== +Global Const $tagCHOOSEFONT = "dword Size;hwnd hWndOwner;handle hDC;ptr LogFont;int PointSize;dword Flags;dword rgbColors;lparam CustData;" & _ + "ptr fnHook;ptr TemplateName;handle hInstance;ptr szStyle;word FontType;int SizeMin;int SizeMax" + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _ChooseColor($iReturnType = 0, $iColorRef = 0, $iRefType = 0, $hWndOwnder = 0) + Local $tagCustcolors = "dword[16]" + + Local $tChoose = DllStructCreate($tagCHOOSECOLOR) + Local $tCc = DllStructCreate($tagCustcolors) + + If $iRefType = 1 Then ; BGR hex color to colorref + $iColorRef = Int($iColorRef) + ElseIf $iRefType = 2 Then ; RGB hex color to colorref + $iColorRef = Hex(String($iColorRef), 6) + $iColorRef = '0x' & StringMid($iColorRef, 5, 2) & StringMid($iColorRef, 3, 2) & StringMid($iColorRef, 1, 2) + EndIf + + DllStructSetData($tChoose, "Size", DllStructGetSize($tChoose)) + DllStructSetData($tChoose, "hWndOwnder", $hWndOwnder) + DllStructSetData($tChoose, "rgbResult", $iColorRef) + DllStructSetData($tChoose, "CustColors", DllStructGetPtr($tCc)) + DllStructSetData($tChoose, "Flags", BitOR($__MISCCONSTANT_CC_ANYCOLOR, $__MISCCONSTANT_CC_FULLOPEN, $__MISCCONSTANT_CC_RGBINIT)) + + Local $aResult = DllCall("comdlg32.dll", "bool", "ChooseColor", "struct*", $tChoose) + If @error Then Return SetError(@error, @extended, -1) + If $aResult[0] = 0 Then Return SetError(-3, -3, -1) ; user selected cancel or struct settings incorrect + + Local $sColor_picked = DllStructGetData($tChoose, "rgbResult") + + If $iReturnType = 1 Then ; return Hex BGR Color + Return '0x' & Hex(String($sColor_picked), 6) + ElseIf $iReturnType = 2 Then ; return Hex RGB Color + $sColor_picked = Hex(String($sColor_picked), 6) + Return '0x' & StringMid($sColor_picked, 5, 2) & StringMid($sColor_picked, 3, 2) & StringMid($sColor_picked, 1, 2) + ElseIf $iReturnType = 0 Then ; return RGB COLORREF + Return $sColor_picked + Else + Return SetError(-4, -4, -1) + EndIf +EndFunc ;==>_ChooseColor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _ChooseFont($sFontName = "Courier New", $iPointSize = 10, $iFontColorRef = 0, $iFontWeight = 0, $bItalic = False, $bUnderline = False, $bStrikethru = False, $hWndOwner = 0) + Local $iItalic = 0, $iUnderline = 0, $iStrikeout = 0 + $iFontColorRef = BitOR(BitShift(BitAND($iFontColorRef, 0x000000FF), -16), BitAND($iFontColorRef, 0x0000FF00), BitShift(BitAND($iFontColorRef, 0x00FF0000), 16)) + + Local $hDC = __MISC_GetDC(0) + Local $iHeight = Round(($iPointSize * __MISC_GetDeviceCaps($hDC, $LOGPIXELSX)) / 72, 0) + __MISC_ReleaseDC(0, $hDC) + + Local $tChooseFont = DllStructCreate($tagCHOOSEFONT) + Local $tLogFont = DllStructCreate($tagLOGFONT) + + DllStructSetData($tChooseFont, "Size", DllStructGetSize($tChooseFont)) + DllStructSetData($tChooseFont, "hWndOwner", $hWndOwner) + DllStructSetData($tChooseFont, "LogFont", DllStructGetPtr($tLogFont)) + DllStructSetData($tChooseFont, "PointSize", $iPointSize) + DllStructSetData($tChooseFont, "Flags", BitOR($CF_SCREENFONTS, $CF_PRINTERFONTS, $CF_EFFECTS, $CF_INITTOLOGFONTSTRUCT, $CF_NOSCRIPTSEL)) + DllStructSetData($tChooseFont, "rgbColors", $iFontColorRef) + DllStructSetData($tChooseFont, "FontType", 0) + + DllStructSetData($tLogFont, "Height", $iHeight) + DllStructSetData($tLogFont, "Weight", $iFontWeight) + DllStructSetData($tLogFont, "Italic", $bItalic) + DllStructSetData($tLogFont, "Underline", $bUnderline) + DllStructSetData($tLogFont, "Strikeout", $bStrikethru) + DllStructSetData($tLogFont, "FaceName", $sFontName) + + Local $aResult = DllCall("comdlg32.dll", "bool", "ChooseFontW", "struct*", $tChooseFont) + If @error Then Return SetError(@error, @extended, -1) + If $aResult[0] = 0 Then Return SetError(-3, -3, -1) ; user selected cancel or struct settings incorrect + + Local $sFaceName = DllStructGetData($tLogFont, "FaceName") + If StringLen($sFaceName) = 0 And StringLen($sFontName) > 0 Then $sFaceName = $sFontName + + If DllStructGetData($tLogFont, "Italic") Then $iItalic = 2 + If DllStructGetData($tLogFont, "Underline") Then $iUnderline = 4 + If DllStructGetData($tLogFont, "Strikeout") Then $iStrikeout = 8 + + Local $iAttributes = BitOR($iItalic, $iUnderline, $iStrikeout) + Local $iSize = DllStructGetData($tChooseFont, "PointSize") / 10 + Local $iColorRef = DllStructGetData($tChooseFont, "rgbColors") + Local $iWeight = DllStructGetData($tLogFont, "Weight") + + Local $sColor_picked = Hex(String($iColorRef), 6) + + Return StringSplit($iAttributes & "," & $sFaceName & "," & $iSize & "," & $iWeight & "," & $iColorRef & "," & '0x' & $sColor_picked & "," & '0x' & StringMid($sColor_picked, 5, 2) & StringMid($sColor_picked, 3, 2) & StringMid($sColor_picked, 1, 2), ",") +EndFunc ;==>_ChooseFont + +; #FUNCTION# ==================================================================================================================== +; Author ........: Piccaso (Florian Fida) +; Modified.......: Gary Frost (gafrost) +; =============================================================================================================================== +Func _ClipPutFile($sFilePath, $sDelimiter = "|") + Local Const $GMEM_MOVEABLE = 0x0002, $CF_HDROP = 15 + + $sFilePath &= $sDelimiter & $sDelimiter + Local $nGlobMemSize = 2 * (StringLen($sFilePath) + 20) + + Local $aResult = DllCall("user32.dll", "bool", "OpenClipboard", "hwnd", 0) + If @error Or $aResult[0] = 0 Then Return SetError(1, _WinAPI_GetLastError(), False) + Local $iError = 0, $iLastError = 0 + $aResult = DllCall("user32.dll", "bool", "EmptyClipboard") + If @error Or Not $aResult[0] Then + $iError = 2 + $iLastError = _WinAPI_GetLastError() + Else + $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $nGlobMemSize) + If @error Or Not $aResult[0] Then + $iError = 3 + $iLastError = _WinAPI_GetLastError() + Else + Local $hGlobal = $aResult[0] + $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal) + If @error Or Not $aResult[0] Then + $iError = 4 + $iLastError = _WinAPI_GetLastError() + Else + Local $hLock = $aResult[0] + Local $tDROPFILES = DllStructCreate("dword pFiles;" & $tagPOINT & ";bool fNC;bool fWide;wchar[" & StringLen($sFilePath) + 1 & "]", $hLock) + If @error Then Return SetError(5, 6, False) + + Local $tStruct = DllStructCreate("dword;long;long;bool;bool") + + DllStructSetData($tDROPFILES, "pFiles", DllStructGetSize($tStruct)) + DllStructSetData($tDROPFILES, "X", 0) + DllStructSetData($tDROPFILES, "Y", 0) + DllStructSetData($tDROPFILES, "fNC", 0) + DllStructSetData($tDROPFILES, "fWide", 1) + DllStructSetData($tDROPFILES, 6, $sFilePath) + For $i = 1 To StringLen($sFilePath) + If DllStructGetData($tDROPFILES, 6, $i) = $sDelimiter Then DllStructSetData($tDROPFILES, 6, Chr(0), $i) + Next + + $aResult = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $CF_HDROP, "handle", $hGlobal) + If @error Or Not $aResult[0] Then + $iError = 6 + $iLastError = _WinAPI_GetLastError() + EndIf + + $aResult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal) + If (@error Or Not $aResult[0]) And Not $iError And _WinAPI_GetLastError() Then + $iError = 8 + $iLastError = _WinAPI_GetLastError() + EndIf + EndIf + $aResult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal) + If (@error Or $aResult[0]) And Not $iError Then + $iError = 9 + $iLastError = _WinAPI_GetLastError() + EndIf + EndIf + EndIf + $aResult = DllCall("user32.dll", "bool", "CloseClipboard") + If (@error Or Not $aResult[0]) And Not $iError Then Return SetError(7, _WinAPI_GetLastError(), False) + If $iError Then Return SetError($iError, $iLastError, False) + Return True +EndFunc ;==>_ClipPutFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _MouseTrap($iLeft = 0, $iTop = 0, $iRight = 0, $iBottom = 0) + Local $aReturn = 0 + If $iLeft = Default Then $iLeft = 0 + If $iTop = Default Then $iTop = 0 + If $iRight = Default Then $iRight = 0 + If $iBottom = Default Then $iBottom = 0 + If @NumParams = 0 Then + $aReturn = DllCall("user32.dll", "bool", "ClipCursor", "ptr", 0) + If @error Or Not $aReturn[0] Then Return SetError(1, _WinAPI_GetLastError(), False) + Else + If @NumParams = 2 Then + $iRight = $iLeft + 1 + $iBottom = $iTop + 1 + EndIf + Local $tRECT = DllStructCreate($tagRECT) + DllStructSetData($tRECT, "Left", $iLeft) + DllStructSetData($tRECT, "Top", $iTop) + DllStructSetData($tRECT, "Right", $iRight) + DllStructSetData($tRECT, "Bottom", $iBottom) + $aReturn = DllCall("user32.dll", "bool", "ClipCursor", "struct*", $tRECT) + If @error Or Not $aReturn[0] Then Return SetError(2, _WinAPI_GetLastError(), False) + EndIf + Return True +EndFunc ;==>_MouseTrap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Valik +; Modified.......: +; =============================================================================================================================== +Func _Singleton($sOccurrenceName, $iFlag = 0) + Local Const $ERROR_ALREADY_EXISTS = 183 + Local Const $SECURITY_DESCRIPTOR_REVISION = 1 + Local $tSecurityAttributes = 0 + + If BitAND($iFlag, 2) Then + ; The size of SECURITY_DESCRIPTOR is 20 bytes. We just + ; need a block of memory the right size, we aren't going to + ; access any members directly so it's not important what + ; the members are, just that the total size is correct. + Local $tSecurityDescriptor = DllStructCreate("byte;byte;word;ptr[4]") + ; Initialize the security descriptor. + Local $aRet = DllCall("advapi32.dll", "bool", "InitializeSecurityDescriptor", _ + "struct*", $tSecurityDescriptor, "dword", $SECURITY_DESCRIPTOR_REVISION) + If @error Then Return SetError(@error, @extended, 0) + If $aRet[0] Then + ; Add the NULL DACL specifying access to everybody. + $aRet = DllCall("advapi32.dll", "bool", "SetSecurityDescriptorDacl", _ + "struct*", $tSecurityDescriptor, "bool", 1, "ptr", 0, "bool", 0) + If @error Then Return SetError(@error, @extended, 0) + If $aRet[0] Then + ; Create a SECURITY_ATTRIBUTES structure. + $tSecurityAttributes = DllStructCreate($tagSECURITY_ATTRIBUTES) + ; Assign the members. + DllStructSetData($tSecurityAttributes, 1, DllStructGetSize($tSecurityAttributes)) + DllStructSetData($tSecurityAttributes, 2, DllStructGetPtr($tSecurityDescriptor)) + DllStructSetData($tSecurityAttributes, 3, 0) + EndIf + EndIf + EndIf + + Local $aHandle = DllCall("kernel32.dll", "handle", "CreateMutexW", "struct*", $tSecurityAttributes, "bool", 1, "wstr", $sOccurrenceName) + If @error Then Return SetError(@error, @extended, 0) + Local $aLastError = DllCall("kernel32.dll", "dword", "GetLastError") + If @error Then Return SetError(@error, @extended, 0) + If $aLastError[0] = $ERROR_ALREADY_EXISTS Then + If BitAND($iFlag, 1) Then + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aHandle[0]) + If @error Then Return SetError(@error, @extended, 0) + Return SetError($aLastError[0], $aLastError[0], 0) + Else + Exit -1 + EndIf + EndIf + Return $aHandle[0] +EndFunc ;==>_Singleton + +; #FUNCTION# ==================================================================================================================== +; Author ........: ezzetabi and Jon +; Modified.......: +; =============================================================================================================================== +Func _IsPressed($sHexKey, $vDLL = 'user32.dll') + ; $hexKey must be the value of one of the keys. + ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is. + Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey) + If @error Then Return SetError(@error, @extended, False) + Return BitAND($a_R[0], 0x8000) <> 0 +EndFunc ;==>_IsPressed + +; #FUNCTION# ==================================================================================================================== +; Author ........: Valik +; Modified.......: +; =============================================================================================================================== +Func _VersionCompare($sVersion1, $sVersion2) + If $sVersion1 = $sVersion2 Then Return 0 + Local $sSubVersion1 = "", $sSubVersion2 = "" + If StringIsAlpha(StringRight($sVersion1, 1)) Then + $sSubVersion1 = StringRight($sVersion1, 1) + $sVersion1 = StringTrimRight($sVersion1, 1) + EndIf + If StringIsAlpha(StringRight($sVersion2, 1)) Then + $sSubVersion2 = StringRight($sVersion2, 1) + $sVersion2 = StringTrimRight($sVersion2, 1) + EndIf + + Local $aVersion1 = StringSplit($sVersion1, ".,"), _ + $aVersion2 = StringSplit($sVersion2, ".,") + Local $iPartDifference = ($aVersion1[0] - $aVersion2[0]) + If $iPartDifference < 0 Then + ;$sVersion1 consists of less parts, fill the missing parts with zeros + ReDim $aVersion1[UBound($aVersion2)] + $aVersion1[0] = UBound($aVersion1) - 1 + For $i = (UBound($aVersion1) - Abs($iPartDifference)) To $aVersion1[0] + $aVersion1[$i] = "0" + Next + ElseIf $iPartDifference > 0 Then + ;$sVersion2 consists of less parts, fill the missing parts with zeros + ReDim $aVersion2[UBound($aVersion1)] + $aVersion2[0] = UBound($aVersion2) - 1 + For $i = (UBound($aVersion2) - Abs($iPartDifference)) To $aVersion2[0] + $aVersion2[$i] = "0" + Next + EndIf + For $i = 1 To $aVersion1[0] + ; Compare this segment as numbers + If StringIsDigit($aVersion1[$i]) And StringIsDigit($aVersion2[$i]) Then + If Number($aVersion1[$i]) > Number($aVersion2[$i]) Then + Return SetExtended(2, 1) ; @extended set to 2 for number comparison. + ElseIf Number($aVersion1[$i]) < Number($aVersion2[$i]) Then + Return SetExtended(2, -1) ; @extended set to 2 for number comparison. + ElseIf $i = $aVersion1[0] Then + ; compare extra version informtion as string + If $sSubVersion1 > $sSubVersion2 Then + Return SetExtended(3, 1) ; @extended set to 3 for subversion comparison. + ElseIf $sSubVersion1 < $sSubVersion2 Then + Return SetExtended(3, -1) ; @extended set to 3 for subversion comparison. + EndIf + EndIf + Else ; Compare the segment as strings + If $aVersion1[$i] > $aVersion2[$i] Then + Return SetExtended(1, 1) ; @extended set to 1 for string comparison. + ElseIf $aVersion1[$i] < $aVersion2[$i] Then + Return SetExtended(1, -1) ; @extended set to 1 for string comparison. + EndIf + EndIf + Next + ; Versions are equal + Return SetExtended(Abs($iPartDifference), 0) +EndFunc ;==>_VersionCompare + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __MISC_GetDC +; Description ...: Retrieves a handle of a display device context for the client area a window +; Syntax.........: __MISC_GetDC ( $hWnd ) +; Parameters ....: $hWnd - Handle of window +; Return values .: Success - The device context for the given window's client area +; Failure - 0 +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; Remarks .......: After painting with a common device context, the __MISC_ReleaseDC function must be called to release the DC +; Related .......: +; Link ..........: @@MsdnLink@@ GetDC +; Example .......: +; =============================================================================================================================== +Func __MISC_GetDC($hWnd) + Local $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd) + If @error Or Not $aResult[0] Then Return SetError(1, _WinAPI_GetLastError(), 0) + Return $aResult[0] +EndFunc ;==>__MISC_GetDC + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __MISC_GetDeviceCaps +; Description ...: Retrieves device specific information about a specified device +; Syntax.........: __MISC_GetDeviceCaps ( $hDC, $iIndex ) +; Parameters ....: $hDC - Identifies the device context +; $iIndex - Specifies the item to return +; Return values .: Success - The value of the desired item +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; Remarks .......: +; Related .......: +; Link ..........: @@MsdnLink@@ GetDeviceCaps +; Example .......: +; =============================================================================================================================== +Func __MISC_GetDeviceCaps($hDC, $iIndex) + Local $aResult = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", $iIndex) + If @error Then Return SetError(@error, @extended, 0) + Return $aResult[0] +EndFunc ;==>__MISC_GetDeviceCaps + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __MISC_ReleaseDC +; Description ...: Releases a device context +; Syntax.........: __MISC_ReleaseDC ( $hWnd, $hDC ) +; Parameters ....: $hWnd - Handle of window +; $hDC - Identifies the device context to be released +; Return values .: Success - True +; Failure - False +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; Remarks .......: The application must call the __MISC_ReleaseDC function for each call to the _WinAPI_GetWindowDC function and for +; each call to the _WinAPI_GetDC function that retrieves a common device context. +; Related .......: _WinAPI_GetDC, _WinAPI_GetWindowDC +; Link ..........: @@MsdnLink@@ ReleaseDC +; Example .......: +; =============================================================================================================================== +Func __MISC_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] <> 0 +EndFunc ;==>__MISC_ReleaseDC diff --git a/src/include/NamedPipes.au3 b/src/include/NamedPipes.au3 new file mode 100644 index 0000000..91b5001 --- /dev/null +++ b/src/include/NamedPipes.au3 @@ -0,0 +1,260 @@ +#include-once + +#include "StructureConstants.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: Pipes +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with Named Pipes. +; A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe +; clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and +; handles, and provides a separate conduit for client server communication. The use of instances enables +; multiple pipe clients to use the same named pipe simultaneously. Any process can access named pipes, subject +; to security checks, making named pipes an easy form of communication between related or unrelated processes. +; Any process can act as both a server and a client, making peer-to-peer communication possible. As used here, +; the term pipe server refers to a process that creates a named pipe, and the term pipe client refers to a +; process that connects to an instance of a named pipe. Named pipes can be used to provide communication between +; processes on the same computer or between processes on different computers across a network. If the server +; service is running, all named pipes are accessible remotely. +; Author(s) .....: Paul Campbell (PaulIA) +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $PIPE_FLAG_FIRST_PIPE_INSTANCE = 1 +Global Const $PIPE_FLAG_OVERLAPPED = 2 +Global Const $PIPE_FLAG_WRITE_THROUGH = 4 + +Global Const $__FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000 +Global Const $__FILE_FLAG_OVERLAPPED = 0x40000000 +Global Const $__FILE_FLAG_WRITE_THROUGH = 0x80000000 + +Global Const $__PIPE_ACCESS_INBOUND = 0x00000001 +Global Const $__PIPE_ACCESS_OUTBOUND = 0x00000002 +Global Const $__PIPE_ACCESS_DUPLEX = 0x00000003 + +Global Const $__PIPE_WAIT = 0x00000000 +Global Const $__PIPE_NOWAIT = 0x00000001 + +Global Const $__PIPE_READMODE_BYTE = 0x00000000 +Global Const $__PIPE_READMODE_MESSAGE = 0x00000002 + +Global Const $__PIPE_TYPE_BYTE = 0x00000000 +Global Const $__PIPE_TYPE_MESSAGE = 0x00000004 + +Global Const $__PIPE_CLIENT_END = 0x00000000 +Global Const $__PIPE_SERVER_END = 0x00000001 + +Global Const $__WRITE_DAC = 0x00040000 +Global Const $__WRITE_OWNER = 0x00080000 +Global Const $__ACCESS_SYSTEM_SECURITY = 0x01000000 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _NamedPipes_CallNamedPipe +; _NamedPipes_ConnectNamedPipe +; _NamedPipes_CreateNamedPipe +; _NamedPipes_CreatePipe +; _NamedPipes_DisconnectNamedPipe +; _NamedPipes_GetNamedPipeHandleState +; _NamedPipes_GetNamedPipeInfo +; _NamedPipes_PeekNamedPipe +; _NamedPipes_SetNamedPipeHandleState +; _NamedPipes_TransactNamedPipe +; _NamedPipes_WaitNamedPipe +; =============================================================================================================================== + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_CallNamedPipe($sPipeName, $pInpBuf, $iInpSize, $pOutBuf, $iOutSize, ByRef $iRead, $iTimeOut = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "CallNamedPipeW", "wstr", $sPipeName, "struct*", $pInpBuf, "dword", $iInpSize, "struct*", $pOutBuf, _ + "dword", $iOutSize, "dword*", 0, "dword", $iTimeOut) + If @error Then Return SetError(@error, @extended, False) + $iRead = $aResult[6] + Return $aResult[0] +EndFunc ;==>_NamedPipes_CallNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _NamedPipes_ConnectNamedPipe($hNamedPipe, $tOverlapped = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "ConnectNamedPipe", "handle", $hNamedPipe, "struct*", $tOverlapped) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_NamedPipes_ConnectNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _NamedPipes_CreateNamedPipe($sName, $iAccess = 2, $iFlags = 2, $iACL = 0, $iType = 1, $iRead = 1, $iWait = 0, $iMaxInst = 25, _ + $iOutBufSize = 4096, $iInpBufSize = 4096, $iDefaultTimeout = 5000, $tSecurity = 0) + Local $iOpenMode, $iPipeMode + + Switch $iAccess + Case 1 + $iOpenMode = $__PIPE_ACCESS_OUTBOUND + Case 2 + $iOpenMode = $__PIPE_ACCESS_DUPLEX + Case Else + $iOpenMode = $__PIPE_ACCESS_INBOUND + EndSwitch + If BitAND($iFlags, 1) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__FILE_FLAG_FIRST_PIPE_INSTANCE) + If BitAND($iFlags, 2) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__FILE_FLAG_OVERLAPPED) + If BitAND($iFlags, 4) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__FILE_FLAG_WRITE_THROUGH) + + If BitAND($iACL, 1) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__WRITE_DAC) + If BitAND($iACL, 2) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__WRITE_OWNER) + If BitAND($iACL, 4) <> 0 Then $iOpenMode = BitOR($iOpenMode, $__ACCESS_SYSTEM_SECURITY) + + Switch $iType + Case 1 + $iPipeMode = $__PIPE_TYPE_MESSAGE + Case Else + $iPipeMode = $__PIPE_TYPE_BYTE + EndSwitch + + Switch $iRead + Case 1 + $iPipeMode = BitOR($iPipeMode, $__PIPE_READMODE_MESSAGE) + Case Else + $iPipeMode = BitOR($iPipeMode, $__PIPE_READMODE_BYTE) + EndSwitch + + Switch $iWait + Case 1 + $iPipeMode = BitOR($iPipeMode, $__PIPE_NOWAIT) + Case Else + $iPipeMode = BitOR($iPipeMode, $__PIPE_WAIT) + EndSwitch + + Local $aResult = DllCall("kernel32.dll", "handle", "CreateNamedPipeW", "wstr", $sName, "dword", $iOpenMode, "dword", $iPipeMode, "dword", $iMaxInst, _ + "dword", $iOutBufSize, "dword", $iInpBufSize, "dword", $iDefaultTimeout, "struct*", $tSecurity) + If @error Then Return SetError(@error, @extended, -1) + Return $aResult[0] +EndFunc ;==>_NamedPipes_CreateNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_CreatePipe(ByRef $hReadPipe, ByRef $hWritePipe, $tSecurity = 0, $iSize = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "CreatePipe", "handle*", 0, "handle*", 0, "struct*", $tSecurity, "dword", $iSize) + If @error Then Return SetError(@error, @extended, False) + $hReadPipe = $aResult[1] ; read pipe handle + $hWritePipe = $aResult[2] ; write pipe handle + Return $aResult[0] +EndFunc ;==>_NamedPipes_CreatePipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_DisconnectNamedPipe($hNamedPipe) + Local $aResult = DllCall("kernel32.dll", "bool", "DisconnectNamedPipe", "handle", $hNamedPipe) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_NamedPipes_DisconnectNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_GetNamedPipeHandleState($hNamedPipe) + Local $aResult = DllCall("kernel32.dll", "bool", "GetNamedPipeHandleStateW", "handle", $hNamedPipe, "dword*", 0, "dword*", 0, _ + "dword*", 0, "dword*", 0, "wstr", "", "dword", 4096) + If @error Then Return SetError(@error, @extended, 0) + Local $aState[6] + $aState[0] = BitAND($aResult[2], $__PIPE_NOWAIT) <> 0 ; State + $aState[1] = BitAND($aResult[2], $__PIPE_READMODE_MESSAGE) <> 0 ; State + $aState[2] = $aResult[3] ; CurInst + $aState[3] = $aResult[4] ; MaxCount + $aState[4] = $aResult[5] ; TimeOut + $aState[5] = $aResult[6] ; Username + Return SetError(0, $aResult[0], $aState) +EndFunc ;==>_NamedPipes_GetNamedPipeHandleState + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_GetNamedPipeInfo($hNamedPipe) + Local $aResult = DllCall("kernel32.dll", "bool", "GetNamedPipeInfo", "handle", $hNamedPipe, "dword*", 0, "dword*", 0, "dword*", 0, _ + "dword*", 0) + If @error Then Return SetError(@error, @extended, 0) + Local $aInfo[5] + $aInfo[0] = BitAND($aResult[2], $__PIPE_SERVER_END) <> 0 ; Flags + $aInfo[1] = BitAND($aResult[2], $__PIPE_TYPE_MESSAGE) <> 0 ; Flags + $aInfo[2] = $aResult[3] ; OutSize + $aInfo[3] = $aResult[4] ; InpSize + $aInfo[4] = $aResult[5] ; MaxInst + Return SetError(0, $aResult[0], $aInfo) +EndFunc ;==>_NamedPipes_GetNamedPipeInfo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_PeekNamedPipe($hNamedPipe) + Local $tBuffer = DllStructCreate("char Text[4096]") + + Local $aResult = DllCall("kernel32.dll", "bool", "PeekNamedPipe", "handle", $hNamedPipe, "struct*", $tBuffer, "int", 4096, "dword*", 0, _ + "dword*", 0, "dword*", 0) + If @error Then Return SetError(@error, @extended, 0) + Local $aInfo[4] + $aInfo[0] = DllStructGetData($tBuffer, "Text") + $aInfo[1] = $aResult[4] ; Read + $aInfo[2] = $aResult[5] ; Total + $aInfo[3] = $aResult[6] ; Left + Return SetError(0, $aResult[0], $aInfo) +EndFunc ;==>_NamedPipes_PeekNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_SetNamedPipeHandleState($hNamedPipe, $iRead, $iWait, $iBytes = 0, $iTimeOut = 0) + Local $iMode = 0, $pBytes = 0, $pTimeOut = 0 + + Local $tInt = DllStructCreate("dword Bytes;dword Timeout") + If $iRead = 1 Then $iMode = BitOR($iMode, $__PIPE_READMODE_MESSAGE) + If $iWait = 1 Then $iMode = BitOR($iMode, $__PIPE_NOWAIT) + + If $iBytes <> 0 Then + $pBytes = DllStructGetPtr($tInt, "Bytes") + DllStructSetData($tInt, "Bytes", $iBytes) + EndIf + + If $iTimeOut <> 0 Then + $pTimeOut = DllStructGetPtr($tInt, "TimeOut") + DllStructSetData($tInt, "TimeOut", $iTimeOut) + EndIf + + Local $aResult = DllCall("kernel32.dll", "bool", "SetNamedPipeHandleState", "handle", $hNamedPipe, "dword*", $iMode, "ptr", $pBytes, "ptr", $pTimeOut) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_NamedPipes_SetNamedPipeHandleState + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _NamedPipes_TransactNamedPipe($hNamedPipe, $pInpBuf, $iInpSize, $pOutBuf, $iOutSize, $tOverlapped = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "TransactNamedPipe", "handle", $hNamedPipe, "struct*", $pInpBuf, "dword", $iInpSize, _ + "struct*", $pOutBuf, "dword", $iOutSize, "dword*", 0, "struct*", $tOverlapped) + If @error Then Return SetError(@error, @extended, 0) + Return SetError(0, $aResult[0], $aResult[6]) +EndFunc ;==>_NamedPipes_TransactNamedPipe + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _NamedPipes_WaitNamedPipe($sPipeName, $iTimeOut = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "WaitNamedPipeW", "wstr", $sPipeName, "dword", $iTimeOut) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_NamedPipes_WaitNamedPipe diff --git a/src/include/Process.au3 b/src/include/Process.au3 new file mode 100644 index 0000000..5b2ebc2 --- /dev/null +++ b/src/include/Process.au3 @@ -0,0 +1,94 @@ +#include-once + +#include "ProcessConstants.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: Process +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Functions that assist with Process management. +; Author(s) .....: Erifash, Wouter, Matthew Tucker, Jeremy Landes, Valik +; Dll ...........: kernel32.dll +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _ProcessGetName +; _ProcessGetPriority +; _RunDOS +; =============================================================================================================================== + +; #FUNCTION# ==================================================================================================================== +; Author ........: Erifash , Wouter van Kesteren. guinness - Removed ProcessExists for speed. +; =============================================================================================================================== +Func _ProcessGetName($iPID) + Local $aProcessList = ProcessList() + If Not @error Then + For $i = 1 To $aProcessList[0][0] + If $aProcessList[$i][1] = $iPID Then + Return $aProcessList[$i][0] + EndIf + Next + EndIf + Return SetError(1, 0, "") +EndFunc ;==>_ProcessGetName + +; #FUNCTION# ==================================================================================================================== +; Author ........: Matthew Tucker +; =============================================================================================================================== +Func _ProcessGetPriority($vProcess) + Local $iError = 0, $iExtended = 0, $iReturn = -1 + Local $iPID = ProcessExists($vProcess) + If Not $iPID Then Return SetError(1, 0, -1) + Local $hDLL = DllOpen('kernel32.dll') + + Do ; Pseudo loop + Local $aProcessHandle = DllCall($hDLL, 'handle', 'OpenProcess', 'dword', $PROCESS_QUERY_INFORMATION, 'bool', False, 'dword', $iPID) + If @error Then + $iError = @error + 10 + $iExtended = @extended + ExitLoop + EndIf + If Not $aProcessHandle[0] Then ExitLoop + + Local $aPriority = DllCall($hDLL, 'dword', 'GetPriorityClass', 'handle', $aProcessHandle[0]) + If @error Then + $iError = @error + $iExtended = @extended + ; Fall-through so the handle is closed. + EndIf + + DllCall($hDLL, 'bool', 'CloseHandle', 'handle', $aProcessHandle[0]) + ; No need to test @error. + + If $iError Then ExitLoop + + Switch $aPriority[0] + Case 0x00000040 ; IDLE_PRIORITY_CLASS + $iReturn = 0 + Case 0x00004000 ; BELOW_NORMAL_PRIORITY_CLASS + $iReturn = 1 + Case 0x00000020 ; NORMAL_PRIORITY_CLASS + $iReturn = 2 + Case 0x00008000 ; ABOVE_NORMAL_PRIORITY_CLASS + $iReturn = 3 + Case 0x00000080 ; HIGH_PRIORITY_CLASS + $iReturn = 4 + Case 0x00000100 ; REALTIME_PRIORITY_CLASS + $iReturn = 5 + Case Else + $iError = 1 + $iExtended = $aPriority[0] + $iReturn = -1 + EndSwitch + Until True ; Executes once + DllClose($hDLL) + Return SetError($iError, $iExtended, $iReturn) +EndFunc ;==>_ProcessGetPriority + +; #FUNCTION# ==================================================================================================================== +; Author ........: Jeremy Landes +; =============================================================================================================================== +Func _RunDos($sCommand) + Local $nResult = RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE) + Return SetError(@error, @extended, $nResult) +EndFunc ;==>_RunDos diff --git a/src/include/ScrollBarsConstants.au3 b/src/include/ScrollBarsConstants.au3 new file mode 100644 index 0000000..191387e --- /dev/null +++ b/src/include/ScrollBarsConstants.au3 @@ -0,0 +1,51 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: ScrollBar_Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Constants for ScrollBar functions. +; Author(s) .....: Valik, Gary Frost, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $SIF_POS = 0x04 +Global Const $SIF_PAGE = 0x02 +Global Const $SIF_RANGE = 0x01 +Global Const $SIF_TRACKPOS = 0x10 +Global Const $SIF_ALL = BitOR($SIF_RANGE, $SIF_PAGE, $SIF_POS, $SIF_TRACKPOS) + +Global Const $SB_HORZ = 0 +Global Const $SB_VERT = 1 +Global Const $SB_CTL = 2 +Global Const $SB_BOTH = 3 + +Global Const $SB_LINELEFT = 0 +Global Const $SB_LINERIGHT = 1 +Global Const $SB_PAGELEFT = 2 +Global Const $SB_PAGERIGHT = 3 + +Global Const $SB_THUMBPOSITION = 0x4 +Global Const $SB_THUMBTRACK = 0x5 +Global Const $SB_LINEDOWN = 1 +Global Const $SB_LINEUP = 0 +Global Const $SB_PAGEDOWN = 3 +Global Const $SB_PAGEUP = 2 +Global Const $SB_SCROLLCARET = 4 +Global Const $SB_TOP = 6 +Global Const $SB_BOTTOM = 7 + +Global Const $ESB_DISABLE_BOTH = 0x3 +Global Const $ESB_DISABLE_DOWN = 0x2 +Global Const $ESB_DISABLE_LEFT = 0x1 +Global Const $ESB_DISABLE_LTUP = $ESB_DISABLE_LEFT +Global Const $ESB_DISABLE_RIGHT = 0x2 +Global Const $ESB_DISABLE_RTDN = $ESB_DISABLE_RIGHT +Global Const $ESB_DISABLE_UP = 0x1 +Global Const $ESB_ENABLE_BOTH = 0x0 + +; Reserved IDs for System Objects +Global Const $OBJID_HSCROLL = 0xFFFFFFFA +Global Const $OBJID_VSCROLL = 0xFFFFFFFB +Global Const $OBJID_CLIENT = 0xFFFFFFFC +; =============================================================================================================================== diff --git a/src/include/StaticConstants.au3 b/src/include/StaticConstants.au3 new file mode 100644 index 0000000..fca84c3 --- /dev/null +++ b/src/include/StaticConstants.au3 @@ -0,0 +1,48 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: Static_Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: GUI control Label/Static styles and Pic, Icon constants. +; Author(s) .....: Valik, Gary Frost, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +; Label/Pic/Icon +Global Const $SS_LEFT = 0x0 +Global Const $SS_CENTER = 0x1 +Global Const $SS_RIGHT = 0x2 +Global Const $SS_ICON = 0x3 +Global Const $SS_BLACKRECT = 0x4 +Global Const $SS_GRAYRECT = 0x5 +Global Const $SS_WHITERECT = 0x6 +Global Const $SS_BLACKFRAME = 0x7 +Global Const $SS_GRAYFRAME = 0x8 +Global Const $SS_WHITEFRAME = 0x9 +Global Const $SS_SIMPLE = 0xB +Global Const $SS_LEFTNOWORDWRAP = 0xC +Global Const $SS_BITMAP = 0xE +Global Const $SS_ENHMETAFILE = 0xF +Global Const $SS_ETCHEDHORZ = 0x10 +Global Const $SS_ETCHEDVERT = 0x11 +Global Const $SS_ETCHEDFRAME = 0x12 +Global Const $SS_REALSIZECONTROL = 0x40 +Global Const $SS_NOPREFIX = 0x0080 +Global Const $SS_NOTIFY = 0x0100 +Global Const $SS_CENTERIMAGE = 0x0200 +Global Const $SS_RIGHTJUST = 0x0400 +Global Const $SS_SUNKEN = 0x1000 + +; Control default styles +Global Const $GUI_SS_DEFAULT_LABEL = 0 +Global Const $GUI_SS_DEFAULT_GRAPHIC = 0 +Global Const $GUI_SS_DEFAULT_ICON = $SS_NOTIFY +Global Const $GUI_SS_DEFAULT_PIC = $SS_NOTIFY + +; Messages +Global Const $STM_SETICON = 0x0170 +Global Const $STM_GETICON = 0x0171 +Global Const $STM_SETIMAGE = 0x0172 +Global Const $STM_GETIMAGE = 0x0173 +; =============================================================================================================================== diff --git a/src/include/TrayConstants.au3 b/src/include/TrayConstants.au3 new file mode 100644 index 0000000..a2335c7 --- /dev/null +++ b/src/include/TrayConstants.au3 @@ -0,0 +1,68 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: Constants to be included in an AutoIt v3 script. +; Author(s) .....: JLandes, Nutster, CyberSlug, Holger, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== + +; Tray predefined ID's +Global Const $TRAY_ITEM_EXIT = 3 +Global Const $TRAY_ITEM_PAUSE = 4 +Global Const $TRAY_ITEM_FIRST = 7 + +; Tray menu/item state values +Global Const $TRAY_CHECKED = 1 +Global Const $TRAY_UNCHECKED = 4 +Global Const $TRAY_ENABLE = 64 +Global Const $TRAY_DISABLE = 128 +Global Const $TRAY_FOCUS = 256 +Global Const $TRAY_DEFAULT = 512 + +; Tray event values +Global Const $TRAY_EVENT_NONE = 0 +Global Const $TRAY_EVENT_SHOWICON = -3 +Global Const $TRAY_EVENT_HIDEICON = -4 +Global Const $TRAY_EVENT_FLASHICON = -5 +Global Const $TRAY_EVENT_NOFLASHICON = -6 +Global Const $TRAY_EVENT_PRIMARYDOWN = -7 +Global Const $TRAY_EVENT_PRIMARYUP = -8 +Global Const $TRAY_EVENT_SECONDARYDOWN = -9 +Global Const $TRAY_EVENT_SECONDARYUP = -10 +Global Const $TRAY_EVENT_MOUSEOVER = -11 +Global Const $TRAY_EVENT_MOUSEOUT = -12 +Global Const $TRAY_EVENT_PRIMARYDOUBLE = -13 +Global Const $TRAY_EVENT_SECONDARYDOUBLE = -14 + +; Indicates the type of Balloon Tip to display +Global Const $TIP_ICONNONE = 0 ; No icon (default) +Global Const $TIP_ICONASTERISK = 1 ; Info icon +Global Const $TIP_ICONEXCLAMATION = 2 ; Warning icon +Global Const $TIP_ICONHAND = 3 ; Error icon +Global Const $TIP_NOSOUND = 16 ; No sound + +; TrayCreateItem values +Global Const $TRAY_ITEM_NORMAL = 0 +Global Const $TRAY_ITEM_RADIO = 1 + +; TraySetClick values +Global Const $TRAY_CLICK_SHOW = 0 +Global Const $TRAY_CLICK_PRIMARYDOWN = 1 +Global Const $TRAY_CLICK_PRIMARYUP = 2 +Global Const $TRAY_DBLCLICK_PRIMARY= 4 +Global Const $TRAY_CLICK_SECONDARYDOWN = 8 +Global Const $TRAY_CLICK_SECONDARYUP = 16 +Global Const $TRAY_DBLCLICK_SECONDARY= 32 +Global Const $TRAY_CLICK_HOVERING= 64 + +; TraySetState values +Global Const $TRAY_ICONSTATE_SHOW = 1 +Global Const $TRAY_ICONSTATE_HIDE = 2 +Global Const $TRAY_ICONSTATE_FLASH = 4 +Global Const $TRAY_ICONSTATE_STOPFLASH = 8 +Global Const $TRAY_ICONSTATE_RESET = 16 +; =============================================================================================================================== diff --git a/src/include/WinAPI.au3 b/src/include/WinAPI.au3 new file mode 100644 index 0000000..7d54535 --- /dev/null +++ b/src/include/WinAPI.au3 @@ -0,0 +1,3216 @@ +#include-once + +#include "AutoItConstants.au3" +#include "FileConstants.au3" +#include "MsgBoxConstants.au3" +#include "Security.au3" +#include "SendMessage.au3" +#include "StringConstants.au3" +#include "StructureConstants.au3" +#include "WinAPIConstants.au3" +#include "WinAPIError.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: Windows API +; AutoIt Version : 3.3.14.2 +; Description ...: Windows API calls that have been translated to AutoIt functions. +; Author(s) .....: Paul Campbell (PaulIA), gafrost, Siao, Zedna, arcker, Prog@ndy, PsaltyDS, Raik, jpm +; Dll ...........: kernel32.dll, user32.dll, gdi32.dll, comdlg32.dll, shell32.dll, ole32.dll, winspool.drv +; =============================================================================================================================== + +; #VARIABLES# =================================================================================================================== +Global $__g_aInProcess_WinAPI[64][2] = [[0, 0]] +Global $__g_aWinList_WinAPI[64][2] = [[0, 0]] +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== +Global Const $__WINAPICONSTANT_WM_SETFONT = 0x0030 +Global Const $__WINAPICONSTANT_FW_NORMAL = 400 +Global Const $__WINAPICONSTANT_DEFAULT_CHARSET = 1 +Global Const $__WINAPICONSTANT_OUT_DEFAULT_PRECIS = 0 +Global Const $__WINAPICONSTANT_CLIP_DEFAULT_PRECIS = 0 +Global Const $__WINAPICONSTANT_DEFAULT_QUALITY = 0 + +Global Const $__WINAPICONSTANT_LOGPIXELSX = 88 +Global Const $__WINAPICONSTANT_LOGPIXELSY = 90 +; =============================================================================================================================== + +; #CURRENT# ===================================================================================================================== +; _WinAPI_AttachConsole +; _WinAPI_AttachThreadInput +; _WinAPI_Beep +; _WinAPI_BitBlt +; _WinAPI_CallNextHookEx +; _WinAPI_CallWindowProc +; _WinAPI_ClientToScreen +; _WinAPI_CloseHandle +; _WinAPI_CombineRgn +; _WinAPI_CommDlgExtendedError +; _WinAPI_CopyIcon +; _WinAPI_CreateBitmap +; _WinAPI_CreateCompatibleBitmap +; _WinAPI_CreateCompatibleDC +; _WinAPI_CreateEvent +; _WinAPI_CreateFile +; _WinAPI_CreateFont +; _WinAPI_CreateFontIndirect +; _WinAPI_CreatePen +; _WinAPI_CreateProcess +; _WinAPI_CreateRectRgn +; _WinAPI_CreateRoundRectRgn +; _WinAPI_CreateSolidBitmap +; _WinAPI_CreateSolidBrush +; _WinAPI_CreateWindowEx +; _WinAPI_DefWindowProc +; _WinAPI_DeleteDC +; _WinAPI_DeleteObject +; _WinAPI_DestroyIcon +; _WinAPI_DestroyWindow +; _WinAPI_DrawEdge +; _WinAPI_DrawFrameControl +; _WinAPI_DrawIcon +; _WinAPI_DrawIconEx +; _WinAPI_DrawLine +; _WinAPI_DrawText +; _WinAPI_DuplicateHandle +; _WinAPI_EnableWindow +; _WinAPI_EnumDisplayDevices +; _WinAPI_EnumWindows +; _WinAPI_EnumWindowsPopup +; _WinAPI_EnumWindowsTop +; _WinAPI_ExpandEnvironmentStrings +; _WinAPI_ExtractIconEx +; _WinAPI_FatalAppExit +; _WinAPI_FillRect +; _WinAPI_FindExecutable +; _WinAPI_FindWindow +; _WinAPI_FlashWindow +; _WinAPI_FlashWindowEx +; _WinAPI_FloatToInt +; _WinAPI_FlushFileBuffers +; _WinAPI_FormatMessage +; _WinAPI_FrameRect +; _WinAPI_FreeLibrary +; _WinAPI_GetAncestor +; _WinAPI_GetAsyncKeyState +; _WinAPI_GetBkMode +; _WinAPI_GetClassName +; _WinAPI_GetClientHeight +; _WinAPI_GetClientWidth +; _WinAPI_GetClientRect +; _WinAPI_GetCurrentProcess +; _WinAPI_GetCurrentProcessID +; _WinAPI_GetCurrentThread +; _WinAPI_GetCurrentThreadId +; _WinAPI_GetCursorInfo +; _WinAPI_GetDC +; _WinAPI_GetDesktopWindow +; _WinAPI_GetDeviceCaps +; _WinAPI_GetDIBits +; _WinAPI_GetDlgCtrlID +; _WinAPI_GetDlgItem +; _WinAPI_GetFocus +; _WinAPI_GetForegroundWindow +; _WinAPI_GetGuiResources +; _WinAPI_GetIconInfo +; _WinAPI_GetFileSizeEx +; _WinAPI_GetLastErrorMessage +; _WinAPI_GetLayeredWindowAttributes +; _WinAPI_GetModuleHandle +; _WinAPI_GetMousePos +; _WinAPI_GetMousePosX +; _WinAPI_GetMousePosY +; _WinAPI_GetObject +; _WinAPI_GetOpenFileName +; _WinAPI_GetOverlappedResult +; _WinAPI_GetParent +; _WinAPI_GetProcAddress +; _WinAPI_GetProcessAffinityMask +; _WinAPI_GetSaveFileName +; _WinAPI_GetStockObject +; _WinAPI_GetStdHandle +; _WinAPI_GetSysColor +; _WinAPI_GetSysColorBrush +; _WinAPI_GetSystemMetrics +; _WinAPI_GetTextExtentPoint32 +; _WinAPI_GetTextMetrics +; _WinAPI_GetWindow +; _WinAPI_GetWindowDC +; _WinAPI_GetWindowHeight +; _WinAPI_GetWindowLong +; _WinAPI_GetWindowPlacement +; _WinAPI_GetWindowRect +; _WinAPI_GetWindowRgn +; _WinAPI_GetWindowText +; _WinAPI_GetWindowThreadProcessId +; _WinAPI_GetWindowWidth +; _WinAPI_GetXYFromPoint +; _WinAPI_GlobalMemStatus +; _WinAPI_GUIDFromString +; _WinAPI_GUIDFromStringEx +; _WinAPI_HiWord +; _WinAPI_InProcess +; _WinAPI_IntToFloat +; _WinAPI_IsClassName +; _WinAPI_IsWindow +; _WinAPI_IsWindowVisible +; _WinAPI_InvalidateRect +; _WinAPI_LineTo +; _WinAPI_LoadBitmap +; _WinAPI_LoadImage +; _WinAPI_LoadLibrary +; _WinAPI_LoadLibraryEx +; _WinAPI_LoadShell32Icon +; _WinAPI_LoadString +; _WinAPI_LocalFree +; _WinAPI_LoWord +; _WinAPI_MAKELANGID +; _WinAPI_MAKELCID +; _WinAPI_MakeLong +; _WinAPI_MakeQWord +; _WinAPI_MessageBeep +; _WinAPI_Mouse_Event +; _WinAPI_MoveTo +; _WinAPI_MoveWindow +; _WinAPI_MsgBox +; _WinAPI_MulDiv +; _WinAPI_MultiByteToWideChar +; _WinAPI_MultiByteToWideCharEx +; _WinAPI_OpenProcess +; _WinAPI_PathFindOnPath +; _WinAPI_PointFromRect +; _WinAPI_PostMessage +; _WinAPI_PrimaryLangId +; _WinAPI_PtInRect +; _WinAPI_ReadFile +; _WinAPI_ReadProcessMemory +; _WinAPI_RectIsEmpty +; _WinAPI_RedrawWindow +; _WinAPI_RegisterWindowMessage +; _WinAPI_ReleaseCapture +; _WinAPI_ReleaseDC +; _WinAPI_ScreenToClient +; _WinAPI_SelectObject +; _WinAPI_SetBkColor +; _WinAPI_SetBkMode +; _WinAPI_SetCapture +; _WinAPI_SetCursor +; _WinAPI_SetDefaultPrinter +; _WinAPI_SetDIBits +; _WinAPI_SetEndOfFile +; _WinAPI_SetEvent +; _WinAPI_SetFilePointer +; _WinAPI_SetFocus +; _WinAPI_SetFont +; _WinAPI_SetHandleInformation +; _WinAPI_SetLayeredWindowAttributes +; _WinAPI_SetParent +; _WinAPI_SetProcessAffinityMask +; _WinAPI_SetSysColors +; _WinAPI_SetTextColor +; _WinAPI_SetWindowLong +; _WinAPI_SetWindowPlacement +; _WinAPI_SetWindowPos +; _WinAPI_SetWindowRgn +; _WinAPI_SetWindowsHookEx +; _WinAPI_SetWindowText +; _WinAPI_ShowCursor +; _WinAPI_ShowError +; _WinAPI_ShowMsg +; _WinAPI_ShowWindow +; _WinAPI_StringFromGUID +; _WinAPI_StringLenA +; _WinAPI_StringLenW +; _WinAPI_SubLangId +; _WinAPI_SystemParametersInfo +; _WinAPI_TwipsPerPixelX +; _WinAPI_TwipsPerPixelY +; _WinAPI_UnhookWindowsHookEx +; _WinAPI_UpdateLayeredWindow +; _WinAPI_UpdateWindow +; _WinAPI_WaitForInputIdle +; _WinAPI_WaitForMultipleObjects +; _WinAPI_WaitForSingleObject +; _WinAPI_WideCharToMultiByte +; _WinAPI_WindowFromPoint +; _WinAPI_WriteConsole +; _WinAPI_WriteFile +; _WinAPI_WriteProcessMemory +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; $tagCURSORINFO +; $tagDISPLAY_DEVICE +; $tagFLASHWINFO +; $tagICONINFO +; $tagMEMORYSTATUSEX +; __WinAPI_EnumWindowsAdd +; __WinAPI_EnumWindowsChild +; __WinAPI_EnumWindowsInit +; __WinAPI_ParseFileDialogPath +; =============================================================================================================================== + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagCURSORINFO +; Description ...: Contains global cursor information +; Fields ........: Size - Specifies the size, in bytes, of the structure +; Flags - Specifies the cursor state. This parameter can be one of the following values: +; |0 - The cursor is hidden +; |$CURSOR_SHOWING - The cursor is showing +; hCursor - Handle to the cursor +; X - X position of the cursor, in screen coordinates +; Y - Y position of the cursor, in screen coordinates +; Author ........: Paul Campbell (PaulIA) +; Remarks .......: +; =============================================================================================================================== +Global Const $tagCURSORINFO = "dword Size;dword Flags;handle hCursor;" & $tagPOINT + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagDISPLAY_DEVICE +; Description ...: Receives information about the display device +; Fields ........: Size - Specifies the size, in bytes, of the structure +; Name - Either the adapter device or the monitor device +; String - Either a description of the display adapter or of the display monitor +; Flags - Device state flags: +; |$DISPLAY_DEVICE_ATTACHED_TO_DESKTOP - The device is part of the desktop +; |$DISPLAY_DEVICE_MIRRORING_DRIVER - Represents a pseudo device used to mirror drawing for remoting or other +; +purposes. An invisible pseudo monitor is associated with this device. +; |$DISPLAY_DEVICE_MODESPRUNED - The device has more display modes than its output devices support +; |$DISPLAY_DEVICE_PRIMARY_DEVICE - The primary desktop is on the device +; |$DISPLAY_DEVICE_REMOVABLE - The device is removable; it cannot be the primary display +; |$DISPLAY_DEVICE_VGA_COMPATIBLE - The device is VGA compatible. +; ID - This is the Plug and Play identifier +; Key - Reserved +; Author ........: Paul Campbell (PaulIA) +; Remarks .......: +; =============================================================================================================================== +Global Const $tagDISPLAY_DEVICE = "dword Size;wchar Name[32];wchar String[128];dword Flags;wchar ID[128];wchar Key[128]" + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagFLASHWINFO +; Description ...: Contains the flash status for a window and the number of times the system should flash the window +; Fields ........: Size - The size of the structure, in bytes +; hWnd - A handle to the window to be flashed. The window can be either opened or minimized. +; Flags - The flash status. This parameter can be one or more of the following values: +; |$FLASHW_ALL - Flash both the window caption and taskbar button +; |$FLASHW_CAPTION - Flash the window caption +; |$FLASHW_STOP - Stop flashing +; |$FLASHW_TIMER - Flash continuously, until the $FLASHW_STOP flag is set +; |$FLASHW_TIMERNOFG - Flash continuously until the window comes to the foreground +; |$FLASHW_TRAY - Flash the taskbar button +; Count - The number of times to flash the window +; Timeout - The rate at which the window is to be flashed, in milliseconds +; Author ........: Paul Campbell (PaulIA) +; Remarks .......: Needs Constants.au3 for pre-defined constants +; =============================================================================================================================== +Global Const $tagFLASHWINFO = "uint Size;hwnd hWnd;dword Flags;uint Count;dword TimeOut" + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagICONINFO +; Description ...: Contains information about an icon or a cursor +; Fields ........: Icon - Specifies the contents of the structure: +; |True - Icon +; |False - Cursor +; XHotSpot - Specifies the x-coordinate of a cursor's hot spot +; YHotSpot - Specifies the y-coordinate of the cursor's hot spot +; hMask - Specifies the icon bitmask bitmap +; hColor - Handle to the icon color bitmap +; Author ........: Paul Campbell (PaulIA) +; Remarks .......: +; =============================================================================================================================== +Global Const $tagICONINFO = "bool Icon;dword XHotSpot;dword YHotSpot;handle hMask;handle hColor" + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: $tagMEMORYSTATUSEX +; Description ...: Contains information memory usage +; Fields ........: Length - size of the structure, must be set before calling GlobalMemoryStatusEx +; MemoryLoad - +; TotalPhys - +; AvailPhys - +; TotalPageFile - +; AvailPageFile - +; TotalVirtual - +; AvailVirtual - +; AvailExtendedVirtual - Reserved +; Author ........: jpm +; Remarks .......: +; =============================================================================================================================== +Global Const $tagMEMORYSTATUSEX = "dword Length;dword MemoryLoad;" & _ + "uint64 TotalPhys;uint64 AvailPhys;uint64 TotalPageFile;uint64 AvailPageFile;" & _ + "uint64 TotalVirtual;uint64 AvailVirtual;uint64 AvailExtendedVirtual" + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_AttachConsole($iPID = -1) + Local $aResult = DllCall("kernel32.dll", "bool", "AttachConsole", "dword", $iPID) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_WinAPI_AttachConsole + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_AttachThreadInput($iAttach, $iAttachTo, $bAttach) + Local $aResult = DllCall("user32.dll", "bool", "AttachThreadInput", "dword", $iAttach, "dword", $iAttachTo, "bool", $bAttach) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_AttachThreadInput + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_Beep($iFreq = 500, $iDuration = 1000) + Local $aResult = DllCall("kernel32.dll", "bool", "Beep", "dword", $iFreq, "dword", $iDuration) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_Beep + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_BitBlt + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CallNextHookEx($hHook, $iCode, $wParam, $lParam) + Local $aResult = DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", $hHook, "int", $iCode, "wparam", $wParam, "lparam", $lParam) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CallNextHookEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Siao +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CallWindowProc($pPrevWndFunc, $hWnd, $iMsg, $wParam, $lParam) + Local $aResult = DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $pPrevWndFunc, "hwnd", $hWnd, "uint", $iMsg, _ + "wparam", $wParam, "lparam", $lParam) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CallWindowProc + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_ClientToScreen($hWnd, ByRef $tPoint) + Local $aRet = DllCall("user32.dll", "bool", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tPoint +EndFunc ;==>_WinAPI_ClientToScreen + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CloseHandle($hObject) + Local $aResult = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hObject) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CloseHandle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CombineRgn($hRgnDest, $hRgnSrc1, $hRgnSrc2, $iCombineMode) + Local $aResult = DllCall("gdi32.dll", "int", "CombineRgn", "handle", $hRgnDest, "handle", $hRgnSrc1, "handle", $hRgnSrc2, _ + "int", $iCombineMode) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CombineRgn + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_CommDlgExtendedError() + Local Const $CDERR_DIALOGFAILURE = 0xFFFF + Local Const $CDERR_FINDRESFAILURE = 0x06 + Local Const $CDERR_INITIALIZATION = 0x02 + Local Const $CDERR_LOADRESFAILURE = 0x07 + Local Const $CDERR_LOADSTRFAILURE = 0x05 + Local Const $CDERR_LOCKRESFAILURE = 0x08 + Local Const $CDERR_MEMALLOCFAILURE = 0x09 + Local Const $CDERR_MEMLOCKFAILURE = 0x0A + Local Const $CDERR_NOHINSTANCE = 0x04 + Local Const $CDERR_NOHOOK = 0x0B + Local Const $CDERR_NOTEMPLATE = 0x03 + Local Const $CDERR_REGISTERMSGFAIL = 0x0C + Local Const $CDERR_STRUCTSIZE = 0x01 + Local Const $FNERR_BUFFERTOOSMALL = 0x3003 + Local Const $FNERR_INVALIDFILENAME = 0x3002 + Local Const $FNERR_SUBCLASSFAILURE = 0x3001 + Local $aResult = DllCall("comdlg32.dll", "dword", "CommDlgExtendedError") + If Not @error Then + Switch $aResult[0] + Case $CDERR_DIALOGFAILURE + Return SetError($aResult[0], 0, "The dialog box could not be created." & @LF & _ + "The common dialog box function's call to the DialogBox function failed." & @LF & _ + "For example, this error occurs if the common dialog box call specifies an invalid window handle.") + Case $CDERR_FINDRESFAILURE + Return SetError($aResult[0], 0, "The common dialog box function failed to find a specified resource.") + Case $CDERR_INITIALIZATION + Return SetError($aResult[0], 0, "The common dialog box function failed during initialization." & @LF & "This error often occurs when sufficient memory is not available.") + Case $CDERR_LOADRESFAILURE + Return SetError($aResult[0], 0, "The common dialog box function failed to load a specified resource.") + Case $CDERR_LOADSTRFAILURE + Return SetError($aResult[0], 0, "The common dialog box function failed to load a specified string.") + Case $CDERR_LOCKRESFAILURE + Return SetError($aResult[0], 0, "The common dialog box function failed to lock a specified resource.") + Case $CDERR_MEMALLOCFAILURE + Return SetError($aResult[0], 0, "The common dialog box function was unable to allocate memory for internal structures.") + Case $CDERR_MEMLOCKFAILURE + Return SetError($aResult[0], 0, "The common dialog box function was unable to lock the memory associated with a handle.") + Case $CDERR_NOHINSTANCE + Return SetError($aResult[0], 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ + "but you failed to provide a corresponding instance handle.") + Case $CDERR_NOHOOK + Return SetError($aResult[0], 0, "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ + "but you failed to provide a pointer to a corresponding hook procedure.") + Case $CDERR_NOTEMPLATE + Return SetError($aResult[0], 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ + "but you failed to provide a corresponding template.") + Case $CDERR_REGISTERMSGFAIL + Return SetError($aResult[0], 0, "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function.") + Case $CDERR_STRUCTSIZE + Return SetError($aResult[0], 0, "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid") + Case $FNERR_BUFFERTOOSMALL + Return SetError($aResult[0], 0, "The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the file name specified by the user." & @LF & _ + "The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in TCHARs, required to receive the full name.") + Case $FNERR_INVALIDFILENAME + Return SetError($aResult[0], 0, "A file name is invalid.") + Case $FNERR_SUBCLASSFAILURE + Return SetError($aResult[0], 0, "An attempt to subclass a list box failed because sufficient memory was not available.") + EndSwitch + EndIf + Return SetError(@error, @extended, '0x' & Hex($aResult[0])) +EndFunc ;==>_WinAPI_CommDlgExtendedError + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_CopyIcon + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreateBitmap($iWidth, $iHeight, $iPlanes = 1, $iBitsPerPel = 1, $pBits = 0) + Local $aResult = DllCall("gdi32.dll", "handle", "CreateBitmap", "int", $iWidth, "int", $iHeight, "uint", $iPlanes, _ + "uint", $iBitsPerPel, "struct*", $pBits) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateBitmap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_CreateCompatibleBitmap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_CreateCompatibleDC + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_CreateEvent($tAttributes = 0, $bManualReset = True, $bInitialState = True, $sName = "") + Local $sNameType = "wstr" + If $sName = "" Then + $sName = 0 + $sNameType = "ptr" + EndIf + + Local $aResult = DllCall("kernel32.dll", "handle", "CreateEventW", "struct*", $tAttributes, "bool", $bManualReset, _ + "bool", $bInitialState, $sNameType, $sName) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateEvent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_CreateFile($sFileName, $iCreation, $iAccess = 4, $iShare = 0, $iAttributes = 0, $tSecurity = 0) + Local $iDA = 0, $iSM = 0, $iCD = 0, $iFA = 0 + + If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($iDA, $GENERIC_EXECUTE) + If BitAND($iAccess, 2) <> 0 Then $iDA = BitOR($iDA, $GENERIC_READ) + If BitAND($iAccess, 4) <> 0 Then $iDA = BitOR($iDA, $GENERIC_WRITE) + + If BitAND($iShare, 1) <> 0 Then $iSM = BitOR($iSM, $FILE_SHARE_DELETE) + If BitAND($iShare, 2) <> 0 Then $iSM = BitOR($iSM, $FILE_SHARE_READ) + If BitAND($iShare, 4) <> 0 Then $iSM = BitOR($iSM, $FILE_SHARE_WRITE) + + Switch $iCreation + Case 0 + $iCD = $CREATE_NEW + Case 1 + $iCD = $CREATE_ALWAYS + Case 2 + $iCD = $OPEN_EXISTING + Case 3 + $iCD = $OPEN_ALWAYS + Case 4 + $iCD = $TRUNCATE_EXISTING + EndSwitch + + If BitAND($iAttributes, 1) <> 0 Then $iFA = BitOR($iFA, $FILE_ATTRIBUTE_ARCHIVE) + If BitAND($iAttributes, 2) <> 0 Then $iFA = BitOR($iFA, $FILE_ATTRIBUTE_HIDDEN) + If BitAND($iAttributes, 4) <> 0 Then $iFA = BitOR($iFA, $FILE_ATTRIBUTE_READONLY) + If BitAND($iAttributes, 8) <> 0 Then $iFA = BitOR($iFA, $FILE_ATTRIBUTE_SYSTEM) + + Local $aResult = DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sFileName, "dword", $iDA, "dword", $iSM, _ + "struct*", $tSecurity, "dword", $iCD, "dword", $iFA, "ptr", 0) + If @error Or ($aResult[0] = $INVALID_HANDLE_VALUE) Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_CreateFont($iHeight, $iWidth, $iEscape = 0, $iOrientn = 0, $iWeight = $__WINAPICONSTANT_FW_NORMAL, $bItalic = False, $bUnderline = False, $bStrikeout = False, $iCharset = $__WINAPICONSTANT_DEFAULT_CHARSET, $iOutputPrec = $__WINAPICONSTANT_OUT_DEFAULT_PRECIS, $iClipPrec = $__WINAPICONSTANT_CLIP_DEFAULT_PRECIS, $iQuality = $__WINAPICONSTANT_DEFAULT_QUALITY, $iPitch = 0, $sFace = 'Arial') + Local $aResult = DllCall("gdi32.dll", "handle", "CreateFontW", "int", $iHeight, "int", $iWidth, "int", $iEscape, _ + "int", $iOrientn, "int", $iWeight, "dword", $bItalic, "dword", $bUnderline, "dword", $bStrikeout, _ + "dword", $iCharset, "dword", $iOutputPrec, "dword", $iClipPrec, "dword", $iQuality, "dword", $iPitch, "wstr", $sFace) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateFont + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreateFontIndirect($tLogFont) + Local $aResult = DllCall("gdi32.dll", "handle", "CreateFontIndirectW", "struct*", $tLogFont) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateFontIndirect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreatePen($iPenStyle, $iWidth, $iColor) + Local $aResult = DllCall("gdi32.dll", "handle", "CreatePen", "int", $iPenStyle, "int", $iWidth, "INT", $iColor) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreatePen + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_CreateProcess($sAppName, $sCommand, $tSecurity, $tThread, $bInherit, $iFlags, $pEnviron, $sDir, $tStartupInfo, $tProcess) + Local $tCommand = 0 + Local $sAppNameType = "wstr", $sDirType = "wstr" + If $sAppName = "" Then + $sAppNameType = "ptr" + $sAppName = 0 + EndIf + If $sCommand <> "" Then + ; must be MAX_PATH characters, can be updated by CreateProcessW + $tCommand = DllStructCreate("wchar Text[" & 260 + 1 & "]") + DllStructSetData($tCommand, "Text", $sCommand) + EndIf + If $sDir = "" Then + $sDirType = "ptr" + $sDir = 0 + EndIf + + Local $aResult = DllCall("kernel32.dll", "bool", "CreateProcessW", $sAppNameType, $sAppName, "struct*", $tCommand, _ + "struct*", $tSecurity, "struct*", $tThread, "bool", $bInherit, "dword", $iFlags, "struct*", $pEnviron, $sDirType, $sDir, _ + "struct*", $tStartupInfo, "struct*", $tProcess) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateProcess + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreateRectRgn($iLeftRect, $iTopRect, $iRightRect, $iBottomRect) + Local $aResult = DllCall("gdi32.dll", "handle", "CreateRectRgn", "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, _ + "int", $iBottomRect) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateRectRgn + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreateRoundRectRgn($iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iWidthEllipse, $iHeightEllipse) + Local $aResult = DllCall("gdi32.dll", "handle", "CreateRoundRectRgn", "int", $iLeftRect, "int", $iTopRect, _ + "int", $iRightRect, "int", $iBottomRect, "int", $iWidthEllipse, "int", $iHeightEllipse) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateRoundRectRgn + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost (Release DC), Yashied (rewritten) +; =============================================================================================================================== +Func _WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight, $bRGB = 1) + Local $hDC = _WinAPI_GetDC($hWnd) + Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) + Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) + Local $hOld = _WinAPI_SelectObject($hDestDC, $hBitmap) + Local $tRECT = DllStructCreate($tagRECT) + DllStructSetData($tRECT, 1, 0) + DllStructSetData($tRECT, 2, 0) + DllStructSetData($tRECT, 3, $iWidth) + DllStructSetData($tRECT, 4, $iHeight) + If $bRGB Then + $iColor = BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16)) + EndIf + Local $hBrush = _WinAPI_CreateSolidBrush($iColor) + If Not _WinAPI_FillRect($hDestDC, $tRECT, $hBrush) Then + _WinAPI_DeleteObject($hBitmap) + $hBitmap = 0 + EndIf + _WinAPI_DeleteObject($hBrush) + _WinAPI_ReleaseDC($hWnd, $hDC) + _WinAPI_SelectObject($hDestDC, $hOld) + _WinAPI_DeleteDC($hDestDC) + If Not $hBitmap Then Return SetError(1, 0, 0) + Return $hBitmap +EndFunc ;==>_WinAPI_CreateSolidBitmap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_CreateSolidBrush($iColor) + Local $aResult = DllCall("gdi32.dll", "handle", "CreateSolidBrush", "INT", $iColor) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateSolidBrush + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_CreateWindowEx($iExStyle, $sClass, $sName, $iStyle, $iX, $iY, $iWidth, $iHeight, $hParent, $hMenu = 0, $hInstance = 0, $pParam = 0) + If $hInstance = 0 Then $hInstance = _WinAPI_GetModuleHandle("") + Local $aResult = DllCall("user32.dll", "hwnd", "CreateWindowExW", "dword", $iExStyle, "wstr", $sClass, "wstr", $sName, _ + "dword", $iStyle, "int", $iX, "int", $iY, "int", $iWidth, "int", $iHeight, "hwnd", $hParent, "handle", $hMenu, _ + "handle", $hInstance, "struct*", $pParam) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_CreateWindowEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) + Local $aResult = DllCall("user32.dll", "lresult", "DefWindowProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, _ + "lparam", $lParam) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DefWindowProc + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_DeleteDC + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_DeleteObject + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_DestroyIcon + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_DestroyWindow($hWnd) + Local $aResult = DllCall("user32.dll", "bool", "DestroyWindow", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DestroyWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_DrawEdge($hDC, $tRECT, $iEdgeType, $iFlags) + Local $aResult = DllCall("user32.dll", "bool", "DrawEdge", "handle", $hDC, "struct*", $tRECT, "uint", $iEdgeType, _ + "uint", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DrawEdge + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_DrawFrameControl($hDC, $tRECT, $iType, $iState) + Local $aResult = DllCall("user32.dll", "bool", "DrawFrameControl", "handle", $hDC, "struct*", $tRECT, "uint", $iType, _ + "uint", $iState) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DrawFrameControl + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_DrawIcon + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_DrawIconEx($hDC, $iX, $iY, $hIcon, $iWidth = 0, $iHeight = 0, $iStep = 0, $hBrush = 0, $iFlags = 3) + Local $iOptions + Switch $iFlags + Case 1 + $iOptions = $DI_MASK + Case 2 + $iOptions = $DI_IMAGE + Case 3 + $iOptions = $DI_NORMAL + Case 4 + $iOptions = $DI_COMPAT + Case 5 + $iOptions = $DI_DEFAULTSIZE + Case Else + $iOptions = $DI_NOMIRROR + EndSwitch + + Local $aResult = DllCall("user32.dll", "bool", "DrawIconEx", "handle", $hDC, "int", $iX, "int", $iY, "handle", $hIcon, _ + "int", $iWidth, "int", $iHeight, "uint", $iStep, "handle", $hBrush, "uint", $iOptions) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DrawIconEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2) + _WinAPI_MoveTo($hDC, $iX1, $iY1) + If @error Then Return SetError(@error, @extended, False) + _WinAPI_LineTo($hDC, $iX2, $iY2) + If @error Then Return SetError(@error + 10, @extended, False) + Return True +EndFunc ;==>_WinAPI_DrawLine + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_DrawText($hDC, $sText, ByRef $tRECT, $iFlags) + Local $aResult = DllCall("user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sText, "int", -1, "struct*", $tRECT, _ + "uint", $iFlags) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_DrawText + +; #FUNCTION# ==================================================================================================================== +; Author ........: trancexx +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_DuplicateHandle($hSourceProcessHandle, $hSourceHandle, $hTargetProcessHandle, $iDesiredAccess, $iInheritHandle, $iOptions) + Local $aResult = DllCall("kernel32.dll", "bool", "DuplicateHandle", _ + "handle", $hSourceProcessHandle, _ + "handle", $hSourceHandle, _ + "handle", $hTargetProcessHandle, _ + "handle*", 0, _ + "dword", $iDesiredAccess, _ + "bool", $iInheritHandle, _ + "dword", $iOptions) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0) + + Return $aResult[4] +EndFunc ;==>_WinAPI_DuplicateHandle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_EnableWindow($hWnd, $bEnable = True) + Local $aResult = DllCall("user32.dll", "bool", "EnableWindow", "hwnd", $hWnd, "bool", $bEnable) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_EnableWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_EnumDisplayDevices($sDevice, $iDevNum) + Local $tName = 0, $iFlags = 0, $aDevice[5] + + If $sDevice <> "" Then + $tName = DllStructCreate("wchar Text[" & StringLen($sDevice) + 1 & "]") + DllStructSetData($tName, "Text", $sDevice) + EndIf + Local $tDevice = DllStructCreate($tagDISPLAY_DEVICE) + Local $iDevice = DllStructGetSize($tDevice) + DllStructSetData($tDevice, "Size", $iDevice) + Local $aRet = DllCall("user32.dll", "bool", "EnumDisplayDevicesW", "struct*", $tName, "dword", $iDevNum, "struct*", $tDevice, "dword", 1) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Local $iN = DllStructGetData($tDevice, "Flags") + If BitAND($iN, $DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) <> 0 Then $iFlags = BitOR($iFlags, 1) + If BitAND($iN, $DISPLAY_DEVICE_PRIMARY_DEVICE) <> 0 Then $iFlags = BitOR($iFlags, 2) + If BitAND($iN, $DISPLAY_DEVICE_MIRRORING_DRIVER) <> 0 Then $iFlags = BitOR($iFlags, 4) + If BitAND($iN, $DISPLAY_DEVICE_VGA_COMPATIBLE) <> 0 Then $iFlags = BitOR($iFlags, 8) + If BitAND($iN, $DISPLAY_DEVICE_REMOVABLE) <> 0 Then $iFlags = BitOR($iFlags, 16) + If BitAND($iN, $DISPLAY_DEVICE_MODESPRUNED) <> 0 Then $iFlags = BitOR($iFlags, 32) + $aDevice[0] = True + $aDevice[1] = DllStructGetData($tDevice, "Name") + $aDevice[2] = DllStructGetData($tDevice, "String") + $aDevice[3] = $iFlags + $aDevice[4] = DllStructGetData($tDevice, "ID") + Return $aDevice +EndFunc ;==>_WinAPI_EnumDisplayDevices + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumWindows($bVisible = True, $hWnd = Default) + __WinAPI_EnumWindowsInit() + If $hWnd = Default Then $hWnd = _WinAPI_GetDesktopWindow() + __WinAPI_EnumWindowsChild($hWnd, $bVisible) + Return $__g_aWinList_WinAPI +EndFunc ;==>_WinAPI_EnumWindows + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __WinAPI_EnumWindowsAdd +; Description ...: Adds window information to the windows enumeration list +; Syntax.........: __WinAPI_EnumWindowsAdd ( $hWnd [, $sClass = ""] ) +; Parameters ....: $hWnd - Handle to the window +; $sClass - Window class name +; Return values .: +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; Remarks .......: This function is used internally by the windows enumeration functions +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __WinAPI_EnumWindowsAdd($hWnd, $sClass = "") + If $sClass = "" Then $sClass = _WinAPI_GetClassName($hWnd) + $__g_aWinList_WinAPI[0][0] += 1 + Local $iCount = $__g_aWinList_WinAPI[0][0] + If $iCount >= $__g_aWinList_WinAPI[0][1] Then + ReDim $__g_aWinList_WinAPI[$iCount + 64][2] + $__g_aWinList_WinAPI[0][1] += 64 + EndIf + $__g_aWinList_WinAPI[$iCount][0] = $hWnd + $__g_aWinList_WinAPI[$iCount][1] = $sClass +EndFunc ;==>__WinAPI_EnumWindowsAdd + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __WinAPI_EnumWindowsChild +; Description ...: Enumerates child windows of a specific window +; Syntax.........: __WinAPI_EnumWindowsChild ( $hWnd [, $bVisible = True] ) +; Parameters ....: $hWnd - Handle of parent window +; $bVisible - Window selection flag: +; | True - Returns only visible windows +; |False - Returns all windows +; Return values .: +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; Remarks .......: This function is used internally by the windows enumeration functions +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __WinAPI_EnumWindowsChild($hWnd, $bVisible = True) + $hWnd = _WinAPI_GetWindow($hWnd, $GW_CHILD) + While $hWnd <> 0 + If (Not $bVisible) Or _WinAPI_IsWindowVisible($hWnd) Then + __WinAPI_EnumWindowsAdd($hWnd) + __WinAPI_EnumWindowsChild($hWnd, $bVisible) + EndIf + $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT) + WEnd +EndFunc ;==>__WinAPI_EnumWindowsChild + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __WinAPI_EnumWindowsInit +; Description ...: Initializes the windows enumeration list +; Syntax.........: __WinAPI_EnumWindowsInit ( ) +; Parameters ....: +; Return values .: +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; Remarks .......: This function is used internally by the windows enumeration functions +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __WinAPI_EnumWindowsInit() + ReDim $__g_aWinList_WinAPI[64][2] + $__g_aWinList_WinAPI[0][0] = 0 + $__g_aWinList_WinAPI[0][1] = 64 +EndFunc ;==>__WinAPI_EnumWindowsInit + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_EnumWindowsPopup() + __WinAPI_EnumWindowsInit() + Local $hWnd = _WinAPI_GetWindow(_WinAPI_GetDesktopWindow(), $GW_CHILD) + Local $sClass + While $hWnd <> 0 + If _WinAPI_IsWindowVisible($hWnd) Then + $sClass = _WinAPI_GetClassName($hWnd) + If $sClass = "#32768" Then + __WinAPI_EnumWindowsAdd($hWnd) + ElseIf $sClass = "ToolbarWindow32" Then + __WinAPI_EnumWindowsAdd($hWnd) + ElseIf $sClass = "ToolTips_Class32" Then + __WinAPI_EnumWindowsAdd($hWnd) + ElseIf $sClass = "BaseBar" Then + __WinAPI_EnumWindowsChild($hWnd) + EndIf + EndIf + $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT) + WEnd + Return $__g_aWinList_WinAPI +EndFunc ;==>_WinAPI_EnumWindowsPopup + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_EnumWindowsTop() + __WinAPI_EnumWindowsInit() + Local $hWnd = _WinAPI_GetWindow(_WinAPI_GetDesktopWindow(), $GW_CHILD) + While $hWnd <> 0 + If _WinAPI_IsWindowVisible($hWnd) Then __WinAPI_EnumWindowsAdd($hWnd) + $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT) + WEnd + Return $__g_aWinList_WinAPI +EndFunc ;==>_WinAPI_EnumWindowsTop + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_ExpandEnvironmentStrings($sString) + Local $aResult = DllCall("kernel32.dll", "dword", "ExpandEnvironmentStringsW", "wstr", $sString, "wstr", "", "dword", 4096) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, "") + + Return $aResult[2] +EndFunc ;==>_WinAPI_ExpandEnvironmentStrings + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_ExtractIconEx($sFilePath, $iIndex, $paLarge, $paSmall, $iIcons) + Local $aResult = DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sFilePath, "int", $iIndex, "struct*", $paLarge, _ + "struct*", $paSmall, "uint", $iIcons) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_ExtractIconEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_FatalAppExit($sMessage) + DllCall("kernel32.dll", "none", "FatalAppExitW", "uint", 0, "wstr", $sMessage) + If @error Then Return SetError(@error, @extended) +EndFunc ;==>_WinAPI_FatalAppExit + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_FillRect($hDC, $tRECT, $hBrush) + Local $aResult + If IsPtr($hBrush) Then + $aResult = DllCall("user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRECT, "handle", $hBrush) + Else + $aResult = DllCall("user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRECT, "dword_ptr", $hBrush) + EndIf + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FillRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_FindExecutable($sFileName, $sDirectory = "") + Local $aResult = DllCall("shell32.dll", "INT", "FindExecutableW", "wstr", $sFileName, "wstr", $sDirectory, "wstr", "") + If @error Then Return SetError(@error, @extended, '') + If $aResult[0] <= 32 Then Return SetError(10, $aResult[0], '') + + Return SetExtended($aResult[0], $aResult[3]) +EndFunc ;==>_WinAPI_FindExecutable + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_FindWindow($sClassName, $sWindowName) + Local $aResult = DllCall("user32.dll", "hwnd", "FindWindowW", "wstr", $sClassName, "wstr", $sWindowName) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FindWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_FlashWindow($hWnd, $bInvert = True) + Local $aResult = DllCall("user32.dll", "bool", "FlashWindow", "hwnd", $hWnd, "bool", $bInvert) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FlashWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Yoan Roblet (arcker) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_FlashWindowEx($hWnd, $iFlags = 3, $iCount = 3, $iTimeout = 0) + Local $tFlash = DllStructCreate($tagFLASHWINFO) + Local $iFlash = DllStructGetSize($tFlash) + Local $iMode = 0 + If BitAND($iFlags, 1) <> 0 Then $iMode = BitOR($iMode, $FLASHW_CAPTION) + If BitAND($iFlags, 2) <> 0 Then $iMode = BitOR($iMode, $FLASHW_TRAY) + If BitAND($iFlags, 4) <> 0 Then $iMode = BitOR($iMode, $FLASHW_TIMER) + If BitAND($iFlags, 8) <> 0 Then $iMode = BitOR($iMode, $FLASHW_TIMERNOFG) + DllStructSetData($tFlash, "Size", $iFlash) + DllStructSetData($tFlash, "hWnd", $hWnd) + DllStructSetData($tFlash, "Flags", $iMode) + DllStructSetData($tFlash, "Count", $iCount) + DllStructSetData($tFlash, "Timeout", $iTimeout) + Local $aResult = DllCall("user32.dll", "bool", "FlashWindowEx", "struct*", $tFlash) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FlashWindowEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_FloatToInt($nFloat) + Local $tFloat = DllStructCreate("float") + Local $tInt = DllStructCreate("int", DllStructGetPtr($tFloat)) + DllStructSetData($tFloat, 1, $nFloat) + + Return DllStructGetData($tInt, 1) +EndFunc ;==>_WinAPI_FloatToInt + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_FlushFileBuffers($hFile) + Local $aResult = DllCall("kernel32.dll", "bool", "FlushFileBuffers", "handle", $hFile) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FlushFileBuffers + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_FormatMessage($iFlags, $pSource, $iMessageID, $iLanguageID, ByRef $pBuffer, $iSize, $vArguments) + Local $sBufferType = "struct*" + If IsString($pBuffer) Then $sBufferType = "wstr" + Local $aResult = DllCall("kernel32.dll", "dword", "FormatMessageW", "dword", $iFlags, "struct*", $pSource, "dword", $iMessageID, _ + "dword", $iLanguageID, $sBufferType, $pBuffer, "dword", $iSize, "ptr", $vArguments) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, 0) + + If $sBufferType = "wstr" Then $pBuffer = $aResult[5] + Return $aResult[0] +EndFunc ;==>_WinAPI_FormatMessage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_FrameRect($hDC, $tRECT, $hBrush) + Local $aResult = DllCall("user32.dll", "int", "FrameRect", "handle", $hDC, "struct*", $tRECT, "handle", $hBrush) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FrameRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_FreeLibrary($hModule) + Local $aResult = DllCall("kernel32.dll", "bool", "FreeLibrary", "handle", $hModule) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_FreeLibrary + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetAncestor($hWnd, $iFlags = 1) + Local $aResult = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", $iFlags) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetAncestor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetAsyncKeyState($iKey) + Local $aResult = DllCall("user32.dll", "short", "GetAsyncKeyState", "int", $iKey) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetAsyncKeyState + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetBkMode($hDC) + Local $aResult = DllCall("gdi32.dll", "int", "GetBkMode", "handle", $hDC) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetBkMode + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetClassName($hWnd) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + Local $aResult = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $hWnd, "wstr", "", "int", 4096) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, '') + + Return SetExtended($aResult[0], $aResult[2]) +EndFunc ;==>_WinAPI_GetClassName + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetClientHeight($hWnd) + Local $tRECT = _WinAPI_GetClientRect($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tRECT, "Bottom") - DllStructGetData($tRECT, "Top") +EndFunc ;==>_WinAPI_GetClientHeight + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetClientWidth($hWnd) + Local $tRECT = _WinAPI_GetClientRect($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tRECT, "Right") - DllStructGetData($tRECT, "Left") +EndFunc ;==>_WinAPI_GetClientWidth + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetClientRect($hWnd) + Local $tRECT = DllStructCreate($tagRECT) + Local $aRet = DllCall("user32.dll", "bool", "GetClientRect", "hwnd", $hWnd, "struct*", $tRECT) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tRECT +EndFunc ;==>_WinAPI_GetClientRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetCurrentProcess() + Local $aResult = DllCall("kernel32.dll", "handle", "GetCurrentProcess") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetCurrentProcess + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetCurrentProcessID() + Local $aResult = DllCall("kernel32.dll", "dword", "GetCurrentProcessId") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetCurrentProcessID + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetCurrentThread() + Local $aResult = DllCall("kernel32.dll", "handle", "GetCurrentThread") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetCurrentThread + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetCurrentThreadId() + Local $aResult = DllCall("kernel32.dll", "dword", "GetCurrentThreadId") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetCurrentThreadId + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +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 ;==>_WinAPI_GetCursorInfo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_GetDC + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetDesktopWindow() + Local $aResult = DllCall("user32.dll", "hwnd", "GetDesktopWindow") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetDesktopWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetDeviceCaps($hDC, $iIndex) + Local $aResult = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", $iIndex) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetDeviceCaps + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetDIBits($hDC, $hBitmap, $iStartScan, $iScanLines, $pBits, $tBI, $iUsage) + Local $aResult = DllCall("gdi32.dll", "int", "GetDIBits", "handle", $hDC, "handle", $hBitmap, "uint", $iStartScan, _ + "uint", $iScanLines, "struct*", $pBits, "struct*", $tBI, "uint", $iUsage) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetDIBits + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetDlgCtrlID($hWnd) + Local $aResult = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetDlgCtrlID + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetDlgItem($hWnd, $iItemID) + Local $aResult = DllCall("user32.dll", "hwnd", "GetDlgItem", "hwnd", $hWnd, "int", $iItemID) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetDlgItem + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetFileSizeEx($hFile) + Local $aResult = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, -1) + + Return $aResult[2] +EndFunc ;==>_WinAPI_GetFileSizeEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetFocus() + Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetFocus + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetForegroundWindow() + Local $aResult = DllCall("user32.dll", "hwnd", "GetForegroundWindow") + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetForegroundWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: jpm +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetGuiResources($iFlag = 0, $hProcess = -1) + If $hProcess = -1 Then $hProcess = _WinAPI_GetCurrentProcess() + Local $aResult = DllCall("user32.dll", "dword", "GetGuiResources", "handle", $hProcess, "dword", $iFlag) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetGuiResources + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +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 ;==>_WinAPI_GetIconInfo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm, danielkza, Valik +; =============================================================================================================================== +Func _WinAPI_GetLastErrorMessage() + Local $iLastError = _WinAPI_GetLastError() + Local $tBufferPtr = DllStructCreate("ptr") + + Local $nCount = _WinAPI_FormatMessage(BitOR($FORMAT_MESSAGE_ALLOCATE_BUFFER, $FORMAT_MESSAGE_FROM_SYSTEM), _ + 0, $iLastError, 0, $tBufferPtr, 0, 0) + If @error Then Return SetError(@error, 0, "") + + Local $sText = "" + Local $pBuffer = DllStructGetData($tBufferPtr, 1) + If $pBuffer Then + If $nCount > 0 Then + Local $tBuffer = DllStructCreate("wchar[" & ($nCount + 1) & "]", $pBuffer) + $sText = DllStructGetData($tBuffer, 1) + If StringRight($sText, 2) = @CRLF Then $sText = StringTrimRight($sText, 2) + EndIf + _WinAPI_LocalFree($pBuffer) + EndIf + + Return $sText +EndFunc ;==>_WinAPI_GetLastErrorMessage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Prog@ndy +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetLayeredWindowAttributes($hWnd, ByRef $iTransColor, ByRef $iTransGUI, $bColorRef = False) + $iTransColor = -1 + $iTransGUI = -1 + Local $aResult = DllCall("user32.dll", "bool", "GetLayeredWindowAttributes", "hwnd", $hWnd, "INT*", $iTransColor, _ + "byte*", $iTransGUI, "dword*", 0) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0) + + If Not $bColorRef Then + $aResult[2] = Int(BinaryMid($aResult[2], 3, 1) & BinaryMid($aResult[2], 2, 1) & BinaryMid($aResult[2], 1, 1)) + EndIf + $iTransColor = $aResult[2] + $iTransGUI = $aResult[3] + Return $aResult[4] +EndFunc ;==>_WinAPI_GetLayeredWindowAttributes + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetModuleHandle($sModuleName) + Local $sModuleNameType = "wstr" + If $sModuleName = "" Then + $sModuleName = 0 + $sModuleNameType = "ptr" + EndIf + + Local $aResult = DllCall("kernel32.dll", "handle", "GetModuleHandleW", $sModuleNameType, $sModuleName) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetModuleHandle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetMousePos($bToClient = False, $hWnd = 0) + Local $iMode = Opt("MouseCoordMode", 1) + Local $aPos = MouseGetPos() + Opt("MouseCoordMode", $iMode) + + Local $tPoint = DllStructCreate($tagPOINT) + DllStructSetData($tPoint, "X", $aPos[0]) + DllStructSetData($tPoint, "Y", $aPos[1]) + If $bToClient And Not _WinAPI_ScreenToClient($hWnd, $tPoint) Then Return SetError(@error + 20, @extended, 0) + + Return $tPoint +EndFunc ;==>_WinAPI_GetMousePos + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetMousePosX($bToClient = False, $hWnd = 0) + Local $tPoint = _WinAPI_GetMousePos($bToClient, $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tPoint, "X") +EndFunc ;==>_WinAPI_GetMousePosX + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetMousePosY($bToClient = False, $hWnd = 0) + Local $tPoint = _WinAPI_GetMousePos($bToClient, $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tPoint, "Y") +EndFunc ;==>_WinAPI_GetMousePosY + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetObject($hObject, $iSize, $pObject) + Local $aResult = DllCall("gdi32.dll", "int", "GetObjectW", "handle", $hObject, "int", $iSize, "struct*", $pObject) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetObject + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetOpenFileName($sTitle = "", $sFilter = "All files (*.*)", $sInitalDir = ".", $sDefaultFile = "", $sDefaultExt = "", $iFilterIndex = 1, $iFlags = 0, $iFlagsEx = 0, $hWndOwner = 0) + Local $iPathLen = 4096 ; Max chars in returned string + Local $iNulls = 0 + Local $tOFN = DllStructCreate($tagOPENFILENAME) + Local $aFiles[1] = [0] + + Local $iFlag = $iFlags + + ; Filter string to array conversion + Local $asFLines = StringSplit($sFilter, "|") + Local $asFilter[$asFLines[0] * 2 + 1] + Local $iStart, $iFinal, $tagFilter + $asFilter[0] = $asFLines[0] * 2 + For $i = 1 To $asFLines[0] + $iStart = StringInStr($asFLines[$i], "(", 0, 1) + $iFinal = StringInStr($asFLines[$i], ")", 0, -1) + $asFilter[$i * 2 - 1] = StringStripWS(StringLeft($asFLines[$i], $iStart - 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) + $asFilter[$i * 2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) - $iFinal + 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) + $tagFilter &= "wchar[" & StringLen($asFilter[$i * 2 - 1]) + 1 & "];wchar[" & StringLen($asFilter[$i * 2]) + 1 & "];" + Next + + Local $tTitle = DllStructCreate("wchar Title[" & StringLen($sTitle) + 1 & "]") + Local $tInitialDir = DllStructCreate("wchar InitDir[" & StringLen($sInitalDir) + 1 & "]") + Local $tFilter = DllStructCreate($tagFilter & "wchar") + Local $tPath = DllStructCreate("wchar Path[" & $iPathLen & "]") + Local $tExtn = DllStructCreate("wchar Extension[" & StringLen($sDefaultExt) + 1 & "]") + For $i = 1 To $asFilter[0] + DllStructSetData($tFilter, $i, $asFilter[$i]) + Next + + ; Set Data of API structures + DllStructSetData($tTitle, "Title", $sTitle) + DllStructSetData($tInitialDir, "InitDir", $sInitalDir) + DllStructSetData($tPath, "Path", $sDefaultFile) + DllStructSetData($tExtn, "Extension", $sDefaultExt) + + DllStructSetData($tOFN, "StructSize", DllStructGetSize($tOFN)) + DllStructSetData($tOFN, "hwndOwner", $hWndOwner) + DllStructSetData($tOFN, "lpstrFilter", DllStructGetPtr($tFilter)) + DllStructSetData($tOFN, "nFilterIndex", $iFilterIndex) + DllStructSetData($tOFN, "lpstrFile", DllStructGetPtr($tPath)) + DllStructSetData($tOFN, "nMaxFile", $iPathLen) + DllStructSetData($tOFN, "lpstrInitialDir", DllStructGetPtr($tInitialDir)) + DllStructSetData($tOFN, "lpstrTitle", DllStructGetPtr($tTitle)) + DllStructSetData($tOFN, "Flags", $iFlag) + DllStructSetData($tOFN, "lpstrDefExt", DllStructGetPtr($tExtn)) + DllStructSetData($tOFN, "FlagsEx", $iFlagsEx) + Local $aRes = DllCall("comdlg32.dll", "bool", "GetOpenFileNameW", "struct*", $tOFN) + If @error Or Not $aRes[0] Then Return SetError(@error + 10, @extended, $aFiles) + + If BitAND($iFlags, $OFN_ALLOWMULTISELECT) = $OFN_ALLOWMULTISELECT And BitAND($iFlags, $OFN_EXPLORER) = $OFN_EXPLORER Then + For $x = 1 To $iPathLen + If DllStructGetData($tPath, "Path", $x) = Chr(0) Then + DllStructSetData($tPath, "Path", "|", $x) + $iNulls += 1 + Else + $iNulls = 0 + EndIf + If $iNulls = 2 Then ExitLoop + Next + DllStructSetData($tPath, "Path", Chr(0), $x - 1) + $aFiles = StringSplit(DllStructGetData($tPath, "Path"), "|") + If $aFiles[0] = 1 Then Return __WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) + Return StringSplit(DllStructGetData($tPath, "Path"), "|") + ElseIf BitAND($iFlags, $OFN_ALLOWMULTISELECT) = $OFN_ALLOWMULTISELECT Then + $aFiles = StringSplit(DllStructGetData($tPath, "Path"), " ") + If $aFiles[0] = 1 Then Return __WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) + Return StringSplit(StringReplace(DllStructGetData($tPath, "Path"), " ", "|"), "|") + Else + Return __WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) + EndIf +EndFunc ;==>_WinAPI_GetOpenFileName + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetOverlappedResult($hFile, $tOverlapped, ByRef $iBytes, $bWait = False) + Local $aResult = DllCall("kernel32.dll", "bool", "GetOverlappedResult", "handle", $hFile, "struct*", $tOverlapped, "dword*", 0, _ + "bool", $bWait) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, False) + + $iBytes = $aResult[3] + Return $aResult[0] +EndFunc ;==>_WinAPI_GetOverlappedResult + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetParent($hWnd) + Local $aResult = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetParent + +; #FUNCTION# ==================================================================================================================== +; Author ........: trancexx +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetProcAddress($hModule, $vName) + Local $sType = "str" + If IsNumber($vName) Then $sType = "word" ; if ordinal value passed + Local $aResult = DllCall("kernel32.dll", "ptr", "GetProcAddress", "handle", $hModule, $sType, $vName) + If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetProcAddress + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetProcessAffinityMask($hProcess) + Local $aResult = DllCall("kernel32.dll", "bool", "GetProcessAffinityMask", "handle", $hProcess, "dword_ptr*", 0, "dword_ptr*", 0) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, 0) + + Local $aMask[3] + $aMask[0] = True + $aMask[1] = $aResult[2] + $aMask[2] = $aResult[3] + Return $aMask +EndFunc ;==>_WinAPI_GetProcessAffinityMask + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetSaveFileName($sTitle = "", $sFilter = "All files (*.*)", $sInitalDir = ".", $sDefaultFile = "", $sDefaultExt = "", $iFilterIndex = 1, $iFlags = 0, $iFlagsEx = 0, $hWndOwner = 0) + Local $iPathLen = 4096 ; Max chars in returned string + Local $tOFN = DllStructCreate($tagOPENFILENAME) + Local $aFiles[1] = [0] + + Local $iFlag = $iFlags + + ; Filter string to array conversion + Local $asFLines = StringSplit($sFilter, "|") + Local $asFilter[$asFLines[0] * 2 + 1] + Local $iStart, $iFinal, $tagFilter + $asFilter[0] = $asFLines[0] * 2 + For $i = 1 To $asFLines[0] + $iStart = StringInStr($asFLines[$i], "(", 0, 1) + $iFinal = StringInStr($asFLines[$i], ")", 0, -1) + $asFilter[$i * 2 - 1] = StringStripWS(StringLeft($asFLines[$i], $iStart - 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) + $asFilter[$i * 2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) - $iFinal + 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) + $tagFilter &= "wchar[" & StringLen($asFilter[$i * 2 - 1]) + 1 & "];wchar[" & StringLen($asFilter[$i * 2]) + 1 & "];" + Next + + Local $tTitle = DllStructCreate("wchar Title[" & StringLen($sTitle) + 1 & "]") + Local $tInitialDir = DllStructCreate("wchar InitDir[" & StringLen($sInitalDir) + 1 & "]") + Local $tFilter = DllStructCreate($tagFilter & "wchar") + Local $tPath = DllStructCreate("wchar Path[" & $iPathLen & "]") + Local $tExtn = DllStructCreate("wchar Extension[" & StringLen($sDefaultExt) + 1 & "]") + For $i = 1 To $asFilter[0] + DllStructSetData($tFilter, $i, $asFilter[$i]) + Next + + ; Set Data of API structures + DllStructSetData($tTitle, "Title", $sTitle) + DllStructSetData($tInitialDir, "InitDir", $sInitalDir) + DllStructSetData($tPath, "Path", $sDefaultFile) + DllStructSetData($tExtn, "Extension", $sDefaultExt) + + DllStructSetData($tOFN, "StructSize", DllStructGetSize($tOFN)) + DllStructSetData($tOFN, "hwndOwner", $hWndOwner) + DllStructSetData($tOFN, "lpstrFilter", DllStructGetPtr($tFilter)) + DllStructSetData($tOFN, "nFilterIndex", $iFilterIndex) + DllStructSetData($tOFN, "lpstrFile", DllStructGetPtr($tPath)) + DllStructSetData($tOFN, "nMaxFile", $iPathLen) + DllStructSetData($tOFN, "lpstrInitialDir", DllStructGetPtr($tInitialDir)) + DllStructSetData($tOFN, "lpstrTitle", DllStructGetPtr($tTitle)) + DllStructSetData($tOFN, "Flags", $iFlag) + DllStructSetData($tOFN, "lpstrDefExt", DllStructGetPtr($tExtn)) + DllStructSetData($tOFN, "FlagsEx", $iFlagsEx) + Local $aRes = DllCall("comdlg32.dll", "bool", "GetSaveFileNameW", "struct*", $tOFN) + If @error Or Not $aRes[0] Then Return SetError(@error + 10, @extended, $aFiles) + + Return __WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) +EndFunc ;==>_WinAPI_GetSaveFileName + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetStockObject($iObject) + Local $aResult = DllCall("gdi32.dll", "handle", "GetStockObject", "int", $iObject) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetStockObject + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetStdHandle($iStdHandle) + If $iStdHandle < 0 Or $iStdHandle > 2 Then Return SetError(2, 0, -1) + Local Const $aHandle[3] = [-10, -11, -12] + + Local $aResult = DllCall("kernel32.dll", "handle", "GetStdHandle", "dword", $aHandle[$iStdHandle]) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetStdHandle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetSysColor($iIndex) + Local $aResult = DllCall("user32.dll", "INT", "GetSysColor", "int", $iIndex) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetSysColor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetSysColorBrush($iIndex) + Local $aResult = DllCall("user32.dll", "handle", "GetSysColorBrush", "int", $iIndex) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetSysColorBrush + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_GetSystemMetrics + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetTextExtentPoint32($hDC, $sText) + Local $tSize = DllStructCreate($tagSIZE) + Local $iSize = StringLen($sText) + Local $aRet = DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sText, "int", $iSize, "struct*", $tSize) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tSize +EndFunc ;==>_WinAPI_GetTextExtentPoint32 + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetTextMetrics($hDC) + Local $tTEXTMETRIC = DllStructCreate($tagTEXTMETRIC) + Local $aRet = DllCall('gdi32.dll', 'bool', 'GetTextMetricsW', 'handle', $hDC, 'struct*', $tTEXTMETRIC) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tTEXTMETRIC +EndFunc ;==>_WinAPI_GetTextMetrics + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetWindow($hWnd, $iCmd) + Local $aResult = DllCall("user32.dll", "hwnd", "GetWindow", "hwnd", $hWnd, "uint", $iCmd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetWindowDC($hWnd) + Local $aResult = DllCall("user32.dll", "handle", "GetWindowDC", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetWindowDC + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetWindowHeight($hWnd) + Local $tRECT = _WinAPI_GetWindowRect($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tRECT, "Bottom") - DllStructGetData($tRECT, "Top") +EndFunc ;==>_WinAPI_GetWindowHeight + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetWindowLong($hWnd, $iIndex) + Local $sFuncName = "GetWindowLongW" + If @AutoItX64 Then $sFuncName = "GetWindowLongPtrW" + Local $aResult = DllCall("user32.dll", "long_ptr", $sFuncName, "hwnd", $hWnd, "int", $iIndex) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetWindowLong + +; #FUNCTION# ==================================================================================================================== +; Author ........: PsaltyDS, with help from Siao and SmOke_N, at www.autoitscript.com/forum +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetWindowPlacement($hWnd) + ; Create struct to receive data + Local $tWindowPlacement = DllStructCreate($tagWINDOWPLACEMENT) + DllStructSetData($tWindowPlacement, "length", DllStructGetSize($tWindowPlacement)) + Local $aRet = DllCall("user32.dll", "bool", "GetWindowPlacement", "hwnd", $hWnd, "struct*", $tWindowPlacement) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tWindowPlacement +EndFunc ;==>_WinAPI_GetWindowPlacement + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetWindowRect($hWnd) + Local $tRECT = DllStructCreate($tagRECT) + Local $aRet = DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $hWnd, "struct*", $tRECT) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tRECT +EndFunc ;==>_WinAPI_GetWindowRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetWindowRgn($hWnd, $hRgn) + Local $aResult = DllCall("user32.dll", "int", "GetWindowRgn", "hwnd", $hWnd, "handle", $hRgn) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_GetWindowRgn + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GetWindowText($hWnd) + Local $aResult = DllCall("user32.dll", "int", "GetWindowTextW", "hwnd", $hWnd, "wstr", "", "int", 4096) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, "") + + Return SetExtended($aResult[0], $aResult[2]) +EndFunc ;==>_WinAPI_GetWindowText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetWindowThreadProcessId($hWnd, ByRef $iPID) + Local $aResult = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0) + If @error Then Return SetError(@error, @extended, 0) + + $iPID = $aResult[2] + Return $aResult[0] +EndFunc ;==>_WinAPI_GetWindowThreadProcessId + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetWindowWidth($hWnd) + Local $tRECT = _WinAPI_GetWindowRect($hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return DllStructGetData($tRECT, "Right") - DllStructGetData($tRECT, "Left") +EndFunc ;==>_WinAPI_GetWindowWidth + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_GetXYFromPoint(ByRef $tPoint, ByRef $iX, ByRef $iY) + $iX = DllStructGetData($tPoint, "X") + $iY = DllStructGetData($tPoint, "Y") +EndFunc ;==>_WinAPI_GetXYFromPoint + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_GlobalMemoryStatus() + Local $tMem = DllStructCreate($tagMEMORYSTATUSEX) + DllStructSetData($tMem, 1, DllStructGetSize($tMem)) + Local $aRet = DllCall("kernel32.dll", "bool", "GlobalMemoryStatusEx", "struct*", $tMem) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Local $aMem[7] + $aMem[0] = DllStructGetData($tMem, 2) + $aMem[1] = DllStructGetData($tMem, 3) + $aMem[2] = DllStructGetData($tMem, 4) + $aMem[3] = DllStructGetData($tMem, 5) + $aMem[4] = DllStructGetData($tMem, 6) + $aMem[5] = DllStructGetData($tMem, 7) + $aMem[6] = DllStructGetData($tMem, 8) + Return $aMem +EndFunc ;==>_WinAPI_GlobalMemoryStatus + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM, guinness +; =============================================================================================================================== +Func _WinAPI_GUIDFromString($sGUID) + Local $tGUID = DllStructCreate($tagGUID) + _WinAPI_GUIDFromStringEx($sGUID, $tGUID) + If @error Then Return SetError(@error + 10, @extended, 0) + ; If Not _WinAPI_GUIDFromStringEx($sGUID, $tGUID) Then Return SetError(@error + 10, @extended, 0) + + Return $tGUID +EndFunc ;==>_WinAPI_GUIDFromString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +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 ;==>_WinAPI_GUIDFromStringEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_HiWord($iLong) + Return BitShift($iLong, 16) +EndFunc ;==>_WinAPI_HiWord + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_InProcess($hWnd, ByRef $hLastWnd) + If $hWnd = $hLastWnd Then Return True + For $iI = $__g_aInProcess_WinAPI[0][0] To 1 Step -1 + If $hWnd = $__g_aInProcess_WinAPI[$iI][0] Then + If $__g_aInProcess_WinAPI[$iI][1] Then + $hLastWnd = $hWnd + Return True + Else + Return False + EndIf + EndIf + Next + Local $iPID + _WinAPI_GetWindowThreadProcessId($hWnd, $iPID) + Local $iCount = $__g_aInProcess_WinAPI[0][0] + 1 + If $iCount >= 64 Then $iCount = 1 + $__g_aInProcess_WinAPI[0][0] = $iCount + $__g_aInProcess_WinAPI[$iCount][0] = $hWnd + $__g_aInProcess_WinAPI[$iCount][1] = ($iPID = @AutoItPID) + Return $__g_aInProcess_WinAPI[$iCount][1] +EndFunc ;==>_WinAPI_InProcess + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_IntToFloat($iInt) + Local $tInt = DllStructCreate("int") + Local $tFloat = DllStructCreate("float", DllStructGetPtr($tInt)) + DllStructSetData($tInt, 1, $iInt) + + Return DllStructGetData($tFloat, 1) +EndFunc ;==>_WinAPI_IntToFloat + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_IsClassName($hWnd, $sClassName) + Local $sSeparator = Opt("GUIDataSeparatorChar") + Local $aClassName = StringSplit($sClassName, $sSeparator) + If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) + Local $sClassCheck = _WinAPI_GetClassName($hWnd) ; ClassName from Handle + ; check array of ClassNames against ClassName Returned + For $x = 1 To UBound($aClassName) - 1 + If StringUpper(StringMid($sClassCheck, 1, StringLen($aClassName[$x]))) = StringUpper($aClassName[$x]) Then Return True + Next + Return False +EndFunc ;==>_WinAPI_IsClassName + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_IsWindow($hWnd) + Local $aResult = DllCall("user32.dll", "bool", "IsWindow", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_IsWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_IsWindowVisible($hWnd) + Local $aResult = DllCall("user32.dll", "bool", "IsWindowVisible", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_IsWindowVisible + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_InvalidateRect($hWnd, $tRECT = 0, $bErase = True) + Local $aResult = DllCall("user32.dll", "bool", "InvalidateRect", "hwnd", $hWnd, "struct*", $tRECT, "bool", $bErase) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_InvalidateRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LineTo($hDC, $iX, $iY) + Local $aResult = DllCall("gdi32.dll", "bool", "LineTo", "handle", $hDC, "int", $iX, "int", $iY) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LineTo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LoadBitmap($hInstance, $sBitmap) + Local $sBitmapType = "int" + If IsString($sBitmap) Then $sBitmapType = "wstr" + Local $aResult = DllCall("user32.dll", "handle", "LoadBitmapW", "handle", $hInstance, $sBitmapType, $sBitmap) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LoadBitmap + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LoadImage($hInstance, $sImage, $iType, $iXDesired, $iYDesired, $iLoad) + Local $aResult, $sImageType = "int" + If IsString($sImage) Then $sImageType = "wstr" + $aResult = DllCall("user32.dll", "handle", "LoadImageW", "handle", $hInstance, $sImageType, $sImage, "uint", $iType, _ + "int", $iXDesired, "int", $iYDesired, "uint", $iLoad) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LoadImage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LoadLibrary($sFileName) + Local $aResult = DllCall("kernel32.dll", "handle", "LoadLibraryW", "wstr", $sFileName) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LoadLibrary + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LoadLibraryEx($sFileName, $iFlags = 0) + Local $aResult = DllCall("kernel32.dll", "handle", "LoadLibraryExW", "wstr", $sFileName, "ptr", 0, "dword", $iFlags) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LoadLibraryEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_LoadShell32Icon($iIconID) + Local $tIcons = DllStructCreate("ptr Data") + Local $iIcons = _WinAPI_ExtractIconEx("shell32.dll", $iIconID, 0, $tIcons, 1) + If @error Then Return SetError(@error, @extended, 0) + If $iIcons <= 0 Then Return SetError(10, 0, 0) + + Return DllStructGetData($tIcons, "Data") +EndFunc ;==>_WinAPI_LoadShell32Icon + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost used correct syntax, Original concept Raik +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_LoadString($hInstance, $iStringID) + Local $aResult = DllCall("user32.dll", "int", "LoadStringW", "handle", $hInstance, "uint", $iStringID, "wstr", "", "int", 4096) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, "") + + Return SetExtended($aResult[0], $aResult[3]) +EndFunc ;==>_WinAPI_LoadString + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_LocalFree($hMemory) + Local $aResult = DllCall("kernel32.dll", "handle", "LocalFree", "handle", $hMemory) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_LocalFree + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_LoWord($iLong) + Return BitAND($iLong, 0xFFFF) +EndFunc ;==>_WinAPI_LoWord + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MAKELANGID($iLngIDPrimary, $iLngIDSub) + Return BitOR(BitShift($iLngIDSub, -10), $iLngIDPrimary) +EndFunc ;==>_WinAPI_MAKELANGID + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MAKELCID($iLngID, $iSortID) + Return BitOR(BitShift($iSortID, -16), $iLngID) +EndFunc ;==>_WinAPI_MAKELCID + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MakeLong($iLo, $iHi) + Return BitOR(BitShift($iHi, -16), BitAND($iLo, 0xFFFF)) +EndFunc ;==>_WinAPI_MakeLong + +; #FUNCTION# ==================================================================================================================== +; Author ........: jpm +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MakeQWord($iLoDWORD, $iHiDWORD) + Local $tInt64 = DllStructCreate("uint64") + Local $tDwords = DllStructCreate("dword;dword", DllStructGetPtr($tInt64)) + DllStructSetData($tDwords, 1, $iLoDWORD) + DllStructSetData($tDwords, 2, $iHiDWORD) + + Return DllStructGetData($tInt64, 1) +EndFunc ;==>_WinAPI_MakeQWord + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MessageBeep($iType = 1) + Local $iSound + Switch $iType + Case 1 + $iSound = 0 + Case 2 + $iSound = 16 + Case 3 + $iSound = 32 + Case 4 + $iSound = 48 + Case 5 + $iSound = 64 + Case Else + $iSound = -1 + EndSwitch + + Local $aResult = DllCall("user32.dll", "bool", "MessageBeep", "uint", $iSound) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_MessageBeep + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MsgBox($iFlags, $sTitle, $sText) + BlockInput(0) + MsgBox($iFlags, $sTitle, $sText & " ") +EndFunc ;==>_WinAPI_MsgBox + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_Mouse_Event($iFlags, $iX = 0, $iY = 0, $iData = 0, $iExtraInfo = 0) + DllCall("user32.dll", "none", "mouse_event", "dword", $iFlags, "dword", $iX, "dword", $iY, "dword", $iData, _ + "ulong_ptr", $iExtraInfo) + If @error Then Return SetError(@error, @extended) +EndFunc ;==>_WinAPI_Mouse_Event + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MoveTo($hDC, $iX, $iY) + Local $aResult = DllCall("gdi32.dll", "bool", "MoveToEx", "handle", $hDC, "int", $iX, "int", $iY, "ptr", 0) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_MoveTo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MoveWindow($hWnd, $iX, $iY, $iWidth, $iHeight, $bRepaint = True) + Local $aResult = DllCall("user32.dll", "bool", "MoveWindow", "hwnd", $hWnd, "int", $iX, "int", $iY, "int", $iWidth, _ + "int", $iHeight, "bool", $bRepaint) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_MoveWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MulDiv($iNumber, $iNumerator, $iDenominator) + Local $aResult = DllCall("kernel32.dll", "int", "MulDiv", "int", $iNumber, "int", $iNumerator, "int", $iDenominator) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_MulDiv + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM, Alexander Samuelsson (AdmiralAlkex) +; =============================================================================================================================== +Func _WinAPI_MultiByteToWideChar($vText, $iCodePage = 0, $iFlags = 0, $bRetString = False) + Local $sTextType = "str" + If Not IsString($vText) Then $sTextType = "struct*" + + ; compute size for the output WideChar + Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodePage, "dword", $iFlags, _ + $sTextType, $vText, "int", -1, "ptr", 0, "int", 0) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, 0) + + ; allocate space for output WideChar + Local $iOut = $aResult[0] + Local $tOut = DllStructCreate("wchar[" & $iOut & "]") + + $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodePage, "dword", $iFlags, $sTextType, $vText, _ + "int", -1, "struct*", $tOut, "int", $iOut) + If @error Or Not $aResult[0] Then Return SetError(@error + 20, @extended, 0) + + If $bRetString Then Return DllStructGetData($tOut, 1) + Return $tOut +EndFunc ;==>_WinAPI_MultiByteToWideChar + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_MultiByteToWideCharEx($sText, $pText, $iCodePage = 0, $iFlags = 0) + Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodePage, "dword", $iFlags, "STR", $sText, _ + "int", -1, "struct*", $pText, "int", (StringLen($sText) + 1) * 2) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_MultiByteToWideCharEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_OpenProcess($iAccess, $bInherit, $iPID, $bDebugPriv = False) + ; Attempt to open process with standard security priviliges + Local $aResult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iAccess, "bool", $bInherit, "dword", $iPID) + If @error Then Return SetError(@error, @extended, 0) + If $aResult[0] Then Return $aResult[0] + If Not $bDebugPriv Then Return SetError(100, 0, 0) + + ; Enable debug privileged mode + Local $hToken = _Security__OpenThreadTokenEx(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY)) + If @error Then Return SetError(@error + 10, @extended, 0) + _Security__SetPrivilege($hToken, "SeDebugPrivilege", True) + Local $iError = @error + Local $iExtended = @extended + Local $iRet = 0 + If Not @error Then + ; Attempt to open process with debug privileges + $aResult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iAccess, "bool", $bInherit, "dword", $iPID) + $iError = @error + $iExtended = @extended + If $aResult[0] Then $iRet = $aResult[0] + + ; Disable debug privileged mode + _Security__SetPrivilege($hToken, "SeDebugPrivilege", False) + If @error Then + $iError = @error + 20 + $iExtended = @extended + EndIf + Else + $iError = @error + 30 ; SeDebugPrivilege=True error + EndIf + _WinAPI_CloseHandle($hToken) + + Return SetError($iError, $iExtended, $iRet) +EndFunc ;==>_WinAPI_OpenProcess + +; #INTERNAL_USE_ONLY# =========================================================================================================== +; Name...........: __WinAPI_ParseFileDialogPath +; Description ...: Returns array from the path string +; Syntax.........: __WinAPI_ParseFileDialogPath ( $sPath ) +; Parameters ....: $sPath - string conataining the path and file(s) +; Return values .: Success - array containing path and file(s) +; Author ........: Gary Frost +; Modified.......: +; Remarks .......: +; Related .......: +; Link ..........: +; Example .......: +; =============================================================================================================================== +Func __WinAPI_ParseFileDialogPath($sPath) + Local $aFiles[3] + $aFiles[0] = 2 + Local $sTemp = StringMid($sPath, 1, StringInStr($sPath, "\", 0, -1) - 1) + $aFiles[1] = $sTemp + $aFiles[2] = StringMid($sPath, StringInStr($sPath, "\", 0, -1) + 1) + Return $aFiles +EndFunc ;==>__WinAPI_ParseFileDialogPath + +; #FUNCTION# ==================================================================================================================== +; Author ........: Daniel Miranda (danielkza) +; Modified.......: JPM +; =============================================================================================================================== +Func _WinAPI_PathFindOnPath(Const $sFilePath, $aExtraPaths = "", Const $sPathDelimiter = @LF) + Local $iExtraCount = 0 + If IsString($aExtraPaths) Then + If StringLen($aExtraPaths) Then + $aExtraPaths = StringSplit($aExtraPaths, $sPathDelimiter, $STR_ENTIRESPLIT + $STR_NOCOUNT) + $iExtraCount = UBound($aExtraPaths, $UBOUND_ROWS) + EndIf + ElseIf IsArray($aExtraPaths) Then + $iExtraCount = UBound($aExtraPaths) + EndIf + + Local $tPaths, $tPathPtrs + If $iExtraCount Then + Local $tagStruct = "" + For $path In $aExtraPaths + $tagStruct &= "wchar[" & StringLen($path) + 1 & "];" + Next + + $tPaths = DllStructCreate($tagStruct) + $tPathPtrs = DllStructCreate("ptr[" & $iExtraCount + 1 & "]") + + For $i = 1 To $iExtraCount + DllStructSetData($tPaths, $i, $aExtraPaths[$i - 1]) + DllStructSetData($tPathPtrs, 1, DllStructGetPtr($tPaths, $i), $i) + Next + DllStructSetData($tPathPtrs, 1, Ptr(0), $iExtraCount + 1) + EndIf + + Local $aResult = DllCall("shlwapi.dll", "bool", "PathFindOnPathW", "wstr", $sFilePath, "struct*", $tPathPtrs) + If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, $sFilePath) + + Return $aResult[1] +EndFunc ;==>_WinAPI_PathFindOnPath + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_PointFromRect(ByRef $tRECT, $bCenter = True) + Local $iX1 = DllStructGetData($tRECT, "Left") + Local $iY1 = DllStructGetData($tRECT, "Top") + Local $iX2 = DllStructGetData($tRECT, "Right") + Local $iY2 = DllStructGetData($tRECT, "Bottom") + If $bCenter Then + $iX1 = $iX1 + (($iX2 - $iX1) / 2) + $iY1 = $iY1 + (($iY2 - $iY1) / 2) + EndIf + Local $tPoint = DllStructCreate($tagPOINT) + DllStructSetData($tPoint, "X", $iX1) + DllStructSetData($tPoint, "Y", $iY1) + Return $tPoint +EndFunc ;==>_WinAPI_PointFromRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_PostMessage($hWnd, $iMsg, $wParam, $lParam) + Local $aResult = DllCall("user32.dll", "bool", "PostMessage", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, _ + "lparam", $lParam) + If @error Then Return SetError(@error, @extended, False) + Return $aResult[0] +EndFunc ;==>_WinAPI_PostMessage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_PrimaryLangId($iLngID) + Return BitAND($iLngID, 0x3FF) +EndFunc ;==>_WinAPI_PrimaryLangId + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: trancexx +; =============================================================================================================================== +Func _WinAPI_PtInRect(ByRef $tRECT, ByRef $tPoint) + Local $aResult = DllCall("user32.dll", "bool", "PtInRect", "struct*", $tRECT, "struct", $tPoint) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_PtInRect + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_ReadFile($hFile, $pBuffer, $iToRead, ByRef $iRead, $tOverlapped = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "ReadFile", "handle", $hFile, "struct*", $pBuffer, "dword", $iToRead, _ + "dword*", 0, "struct*", $tOverlapped) + If @error Then Return SetError(@error, @extended, False) + + $iRead = $aResult[4] + Return $aResult[0] +EndFunc ;==>_WinAPI_ReadFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_ReadProcessMemory($hProcess, $pBaseAddress, $pBuffer, $iSize, ByRef $iRead) + Local $aResult = DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $hProcess, _ + "ptr", $pBaseAddress, "struct*", $pBuffer, "ulong_ptr", $iSize, "ulong_ptr*", 0) + If @error Then Return SetError(@error, @extended, False) + + $iRead = $aResult[5] + Return $aResult[0] +EndFunc ;==>_WinAPI_ReadProcessMemory + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_RectIsEmpty(ByRef $tRECT) + Return (DllStructGetData($tRECT, "Left") = 0) And (DllStructGetData($tRECT, "Top") = 0) And _ + (DllStructGetData($tRECT, "Right") = 0) And (DllStructGetData($tRECT, "Bottom") = 0) +EndFunc ;==>_WinAPI_RectIsEmpty + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_RedrawWindow($hWnd, $tRECT = 0, $hRegion = 0, $iFlags = 5) + Local $aResult = DllCall("user32.dll", "bool", "RedrawWindow", "hwnd", $hWnd, "struct*", $tRECT, "handle", $hRegion, _ + "uint", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_RedrawWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_RegisterWindowMessage($sMessage) + Local $aResult = DllCall("user32.dll", "uint", "RegisterWindowMessageW", "wstr", $sMessage) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_RegisterWindowMessage + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ReleaseCapture() + Local $aResult = DllCall("user32.dll", "bool", "ReleaseCapture") + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_ReleaseCapture + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_ReleaseDC + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ScreenToClient($hWnd, ByRef $tPoint) + Local $aResult = DllCall("user32.dll", "bool", "ScreenToClient", "hwnd", $hWnd, "struct*", $tPoint) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_ScreenToClient + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +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 ;==>_WinAPI_SelectObject + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetBkColor($hDC, $iColor) + Local $aResult = DllCall("gdi32.dll", "INT", "SetBkColor", "handle", $hDC, "INT", $iColor) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetBkColor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetBkMode($hDC, $iBkMode) + Local $aResult = DllCall("gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $iBkMode) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetBkMode + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetCapture($hWnd) + Local $aResult = DllCall("user32.dll", "hwnd", "SetCapture", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetCapture + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetCursor($hCursor) + Local $aResult = DllCall("user32.dll", "handle", "SetCursor", "handle", $hCursor) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetCursor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetDefaultPrinter($sPrinter) + Local $aResult = DllCall("winspool.drv", "bool", "SetDefaultPrinterW", "wstr", $sPrinter) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetDefaultPrinter + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetDIBits($hDC, $hBitmap, $iStartScan, $iScanLines, $pBits, $tBMI, $iColorUse = 0) + Local $aResult = DllCall("gdi32.dll", "int", "SetDIBits", "handle", $hDC, "handle", $hBitmap, "uint", $iStartScan, _ + "uint", $iScanLines, "struct*", $pBits, "struct*", $tBMI, "INT", $iColorUse) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetDIBits + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetEndOfFile($hFile) + Local $aResult = DllCall("kernel32.dll", "bool", "SetEndOfFile", "handle", $hFile) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetEndOfFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetEvent($hEvent) + Local $aResult = DllCall("kernel32.dll", "bool", "SetEvent", "handle", $hEvent) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetEvent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetFilePointer($hFile, $iPos, $iMethod = 0) + Local $aResult = DllCall("kernel32.dll", "INT", "SetFilePointer", "handle", $hFile, "long", $iPos, "ptr", 0, "long", $iMethod) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetFilePointer + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetFocus($hWnd) + Local $aResult = DllCall("user32.dll", "hwnd", "SetFocus", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetFocus + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetFont($hWnd, $hFont, $bRedraw = True) + _SendMessage($hWnd, $__WINAPICONSTANT_WM_SETFONT, $hFont, $bRedraw, 0, "hwnd") +EndFunc ;==>_WinAPI_SetFont + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetHandleInformation($hObject, $iMask, $iFlags) + Local $aResult = DllCall("kernel32.dll", "bool", "SetHandleInformation", "handle", $hObject, "dword", $iMask, "dword", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetHandleInformation + +; #FUNCTION# ==================================================================================================================== +; Author ........: Prog@ndy +; Modified.......: PsaltyDS +; =============================================================================================================================== +Func _WinAPI_SetLayeredWindowAttributes($hWnd, $iTransColor, $iTransGUI = 255, $iFlags = 0x03, $bColorRef = False) + If $iFlags = Default Or $iFlags = "" Or $iFlags < 0 Then $iFlags = 0x03 + If Not $bColorRef Then + $iTransColor = Int(BinaryMid($iTransColor, 3, 1) & BinaryMid($iTransColor, 2, 1) & BinaryMid($iTransColor, 1, 1)) + EndIf + Local $aResult = DllCall("user32.dll", "bool", "SetLayeredWindowAttributes", "hwnd", $hWnd, "INT", $iTransColor, _ + "byte", $iTransGUI, "dword", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetLayeredWindowAttributes + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetParent($hWndChild, $hWndParent) + Local $aResult = DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $hWndParent) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetParent + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetProcessAffinityMask($hProcess, $iMask) + Local $aResult = DllCall("kernel32.dll", "bool", "SetProcessAffinityMask", "handle", $hProcess, "ulong_ptr", $iMask) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetProcessAffinityMask + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetSysColors($vElements, $vColors) + Local $bIsEArray = IsArray($vElements), $bIsCArray = IsArray($vColors) + Local $iElementNum + + If Not $bIsCArray And Not $bIsEArray Then + $iElementNum = 1 + ElseIf $bIsCArray Or $bIsEArray Then + If Not $bIsCArray Or Not $bIsEArray Then Return SetError(-1, -1, False) + If UBound($vElements) <> UBound($vColors) Then Return SetError(-1, -1, False) + $iElementNum = UBound($vElements) + EndIf + + Local $tElements = DllStructCreate("int Element[" & $iElementNum & "]") + Local $tColors = DllStructCreate("INT NewColor[" & $iElementNum & "]") + + If Not $bIsEArray Then + DllStructSetData($tElements, "Element", $vElements, 1) + Else + For $x = 0 To $iElementNum - 1 + DllStructSetData($tElements, "Element", $vElements[$x], $x + 1) + Next + EndIf + + If Not $bIsCArray Then + DllStructSetData($tColors, "NewColor", $vColors, 1) + Else + For $x = 0 To $iElementNum - 1 + DllStructSetData($tColors, "NewColor", $vColors[$x], $x + 1) + Next + EndIf + Local $aResult = DllCall("user32.dll", "bool", "SetSysColors", "int", $iElementNum, "struct*", $tElements, "struct*", $tColors) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetSysColors + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetTextColor($hDC, $iColor) + Local $aResult = DllCall("gdi32.dll", "INT", "SetTextColor", "handle", $hDC, "INT", $iColor) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetTextColor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetWindowLong($hWnd, $iIndex, $iValue) + _WinAPI_SetLastError(0) ; as suggested in MSDN + Local $sFuncName = "SetWindowLongW" + If @AutoItX64 Then $sFuncName = "SetWindowLongPtrW" + Local $aResult = DllCall("user32.dll", "long_ptr", $sFuncName, "hwnd", $hWnd, "int", $iIndex, "long_ptr", $iValue) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowLong + +; #FUNCTION# ==================================================================================================================== +; Author ........: PsaltyDS +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetWindowPlacement($hWnd, $tWindowPlacement) + Local $aResult = DllCall("user32.dll", "bool", "SetWindowPlacement", "hwnd", $hWnd, "struct*", $tWindowPlacement) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowPlacement + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetWindowPos($hWnd, $hAfter, $iX, $iY, $iCX, $iCY, $iFlags) + Local $aResult = DllCall("user32.dll", "bool", "SetWindowPos", "hwnd", $hWnd, "hwnd", $hAfter, "int", $iX, "int", $iY, _ + "int", $iCX, "int", $iCY, "uint", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowPos + +; #FUNCTION# ==================================================================================================================== +; Author ........: Zedna +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SetWindowRgn($hWnd, $hRgn, $bRedraw = True) + Local $aResult = DllCall("user32.dll", "int", "SetWindowRgn", "hwnd", $hWnd, "handle", $hRgn, "bool", $bRedraw) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowRgn + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetWindowsHookEx($iHook, $pProc, $hDll, $iThreadId = 0) + Local $aResult = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", $iHook, "ptr", $pProc, "handle", $hDll, _ + "dword", $iThreadId) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowsHookEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetWindowText($hWnd, $sText) + Local $aResult = DllCall("user32.dll", "bool", "SetWindowTextW", "hwnd", $hWnd, "wstr", $sText) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SetWindowText + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ShowCursor($bShow) + Local $aResult = DllCall("user32.dll", "int", "ShowCursor", "bool", $bShow) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_ShowCursor + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ShowError($sText, $bExit = True) + _WinAPI_MsgBox($MB_SYSTEMMODAL, "Error", $sText) + If $bExit Then Exit +EndFunc ;==>_WinAPI_ShowError + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ShowMsg($sText) + _WinAPI_MsgBox($MB_SYSTEMMODAL, "Information", $sText) +EndFunc ;==>_WinAPI_ShowMsg + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_ShowWindow($hWnd, $iCmdShow = 5) + Local $aResult = DllCall("user32.dll", "bool", "ShowWindow", "hwnd", $hWnd, "int", $iCmdShow) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_ShowWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM +; =============================================================================================================================== +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 ;==>_WinAPI_StringFromGUID + +; #FUNCTION# ==================================================================================================================== +; Author ........: trancexx +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_StringLenA(Const ByRef $tString) + Local $aResult = DllCall("kernel32.dll", "int", "lstrlenA", "struct*", $tString) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_StringLenA + +; #FUNCTION# ==================================================================================================================== +; Author ........: trancexx +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_StringLenW(Const ByRef $tString) + Local $aResult = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $tString) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_StringLenW + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_SubLangId($iLngID) + Return BitShift($iLngID, 10) +EndFunc ;==>_WinAPI_SubLangId + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SystemParametersInfo($iAction, $iParam = 0, $vParam = 0, $iWinIni = 0) + Local $aResult = DllCall("user32.dll", "bool", "SystemParametersInfoW", "uint", $iAction, "uint", $iParam, "struct*", $vParam, _ + "uint", $iWinIni) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_SystemParametersInfo + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_TwipsPerPixelX() + Local $hDC, $iTwipsPerPixelX + $hDC = _WinAPI_GetDC(0) + $iTwipsPerPixelX = 1440 / _WinAPI_GetDeviceCaps($hDC, $__WINAPICONSTANT_LOGPIXELSX) + _WinAPI_ReleaseDC(0, $hDC) + Return $iTwipsPerPixelX +EndFunc ;==>_WinAPI_TwipsPerPixelX + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost (gafrost) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_TwipsPerPixelY() + Local $hDC, $iTwipsPerPixelY + $hDC = _WinAPI_GetDC(0) + $iTwipsPerPixelY = 1440 / _WinAPI_GetDeviceCaps($hDC, $__WINAPICONSTANT_LOGPIXELSY) + _WinAPI_ReleaseDC(0, $hDC) + Return $iTwipsPerPixelY +EndFunc ;==>_WinAPI_TwipsPerPixelY + +; #FUNCTION# ==================================================================================================================== +; Author ........: Gary Frost +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_UnhookWindowsHookEx($hHook) + Local $aResult = DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $hHook) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_UnhookWindowsHookEx + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_UpdateLayeredWindow($hWnd, $hDestDC, $tPTDest, $tSize, $hSrcDC, $tPTSrce, $iRGB, $tBlend, $iFlags) + Local $aResult = DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hWnd, "handle", $hDestDC, "struct*", $tPTDest, _ + "struct*", $tSize, "handle", $hSrcDC, "struct*", $tPTSrce, "dword", $iRGB, "struct*", $tBlend, "dword", $iFlags) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_UpdateLayeredWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_UpdateWindow($hWnd) + Local $aResult = DllCall("user32.dll", "bool", "UpdateWindow", "hwnd", $hWnd) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_UpdateWindow + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_WaitForInputIdle($hProcess, $iTimeout = -1) + Local $aResult = DllCall("user32.dll", "dword", "WaitForInputIdle", "handle", $hProcess, "dword", $iTimeout) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_WaitForInputIdle + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_WaitForMultipleObjects($iCount, $paHandles, $bWaitAll = False, $iTimeout = -1) + Local $aResult = DllCall("kernel32.dll", "INT", "WaitForMultipleObjects", "dword", $iCount, "struct*", $paHandles, "bool", $bWaitAll, "dword", $iTimeout) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_WaitForMultipleObjects + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_WaitForSingleObject($hHandle, $iTimeout = -1) + Local $aResult = DllCall("kernel32.dll", "INT", "WaitForSingleObject", "handle", $hHandle, "dword", $iTimeout) + If @error Then Return SetError(@error, @extended, -1) + + Return $aResult[0] +EndFunc ;==>_WinAPI_WaitForSingleObject + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: JPM, Alexander Samuelsson (AdmiralAlkex) +; =============================================================================================================================== +Func _WinAPI_WideCharToMultiByte($vUnicode, $iCodePage = 0, $bRetString = True) + 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("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 $bRetString Then Return DllStructGetData($tMultiByte, 1) + Return $tMultiByte +EndFunc ;==>_WinAPI_WideCharToMultiByte + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: Gary Frost, trancexx +; =============================================================================================================================== +Func _WinAPI_WindowFromPoint(ByRef $tPoint) + Local $aResult = DllCall("user32.dll", "hwnd", "WindowFromPoint", "struct", $tPoint) + If @error Then Return SetError(@error, @extended, 0) + + Return $aResult[0] +EndFunc ;==>_WinAPI_WindowFromPoint + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: +; =============================================================================================================================== +Func _WinAPI_WriteConsole($hConsole, $sText) + Local $aResult = DllCall("kernel32.dll", "bool", "WriteConsoleW", "handle", $hConsole, "wstr", $sText, _ + "dword", StringLen($sText), "dword*", 0, "ptr", 0) + If @error Then Return SetError(@error, @extended, False) + + Return $aResult[0] +EndFunc ;==>_WinAPI_WriteConsole + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_WriteFile($hFile, $pBuffer, $iToWrite, ByRef $iWritten, $tOverlapped = 0) + Local $aResult = DllCall("kernel32.dll", "bool", "WriteFile", "handle", $hFile, "struct*", $pBuffer, "dword", $iToWrite, _ + "dword*", 0, "struct*", $tOverlapped) + If @error Then Return SetError(@error, @extended, False) + + $iWritten = $aResult[4] + Return $aResult[0] +EndFunc ;==>_WinAPI_WriteFile + +; #FUNCTION# ==================================================================================================================== +; Author ........: Paul Campbell (PaulIA) +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_WriteProcessMemory($hProcess, $pBaseAddress, $pBuffer, $iSize, ByRef $iWritten, $sBuffer = "ptr") + Local $aResult = DllCall("kernel32.dll", "bool", "WriteProcessMemory", "handle", $hProcess, "ptr", $pBaseAddress, _ + $sBuffer, $pBuffer, "ulong_ptr", $iSize, "ulong_ptr*", 0) + If @error Then Return SetError(@error, @extended, False) + + $iWritten = $aResult[5] + Return $aResult[0] +EndFunc ;==>_WinAPI_WriteProcessMemory diff --git a/src/include/WinAPIProc.au3 b/src/include/WinAPIProc.au3 new file mode 100644 index 0000000..ecbeb66 --- /dev/null +++ b/src/include/WinAPIProc.au3 @@ -0,0 +1,1231 @@ +#include-once + +#include "APIProcConstants.au3" +#include "WinAPICom.au3" +#include "WinAPIInternals.au3" +#include "WinAPIShPath.au3" + +; #INDEX# ======================================================================================================================= +; Title .........: WinAPI Extended UDF Library for AutoIt3 +; AutoIt Version : 3.3.14.2 +; Description ...: Additional variables, constants and functions for the WinAPIProc.au3 +; Author(s) .....: Yashied, jpm +; =============================================================================================================================== + +#Region Global Variables and Constants + +; #CONSTANTS# =================================================================================================================== +Global Const $tagIO_COUNTERS = 'struct;uint64 ReadOperationCount;uint64 WriteOperationCount;uint64 OtherOperationCount;uint64 ReadTransferCount;uint64 WriteTransferCount;uint64 OtherTransferCount;endstruct' +Global Const $tagJOBOBJECT_ASSOCIATE_COMPLETION_PORT = 'ulong_ptr CompletionKey;ptr CompletionPort' +Global Const $tagJOBOBJECT_BASIC_ACCOUNTING_INFORMATION = 'struct;int64 TotalUserTime;int64 TotalKernelTime;int64 ThisPeriodTotalUserTime;int64 ThisPeriodTotalKernelTime;dword TotalPageFaultCount;dword TotalProcesses;dword ActiveProcesses;dword TotalTerminatedProcesses;endstruct' +Global Const $tagJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION = $tagJOBOBJECT_BASIC_ACCOUNTING_INFORMATION & ';' & $tagIO_COUNTERS +Global Const $tagJOBOBJECT_BASIC_LIMIT_INFORMATION = 'struct;int64 PerProcessUserTimeLimit;int64 PerJobUserTimeLimit;dword LimitFlags;ulong_ptr MinimumWorkingSetSize;ulong_ptr MaximumWorkingSetSize;dword ActiveProcessLimit;ulong_ptr Affinity;dword PriorityClass;dword SchedulingClass;endstruct' +Global Const $tagJOBOBJECT_BASIC_PROCESS_ID_LIST = 'dword NumberOfAssignedProcesses;dword NumberOfProcessIdsInList' ; & ';ulong_ptr ProcessIdList[n]' +Global Const $tagJOBOBJECT_BASIC_UI_RESTRICTIONS = 'dword UIRestrictionsClass' +Global Const $tagJOBOBJECT_END_OF_JOB_TIME_INFORMATION = 'dword EndOfJobTimeAction' +Global Const $tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION = $tagJOBOBJECT_BASIC_LIMIT_INFORMATION & ';' & $tagIO_COUNTERS & ';ulong_ptr ProcessMemoryLimit;ulong_ptr JobMemoryLimit;ulong_ptr PeakProcessMemoryUsed;ulong_ptr PeakJobMemoryUsed' +Global Const $tagJOBOBJECT_GROUP_INFORMATION = '' ; & 'ushort ProcessorGroup[n]' +Global Const $tagJOBOBJECT_SECURITY_LIMIT_INFORMATION = 'dword SecurityLimitFlags;ptr JobToken;ptr SidsToDisable;ptr PrivilegesToDelete;ptr RestrictedSids' +Global Const $tagMODULEINFO = 'ptr BaseOfDll;dword SizeOfImage;ptr EntryPoint' +Global Const $tagPROCESSENTRY32 = 'dword Size;dword Usage;dword ProcessID;ulong_ptr DefaultHeapID;dword ModuleID;dword Threads;dword ParentProcessID;long PriClassBase;dword Flags;wchar ExeFile[260]' +; =============================================================================================================================== +#EndRegion Global Variables and Constants + +#Region Functions list + +; #CURRENT# ===================================================================================================================== +; _WinAPI_AdjustTokenPrivileges +; _WinAPI_AssignProcessToJobObject +; _WinAPI_CreateJobObject +; _WinAPI_CreateMutex +; _WinAPI_CreateProcessWithToken +; _WinAPI_CreateSemaphore +; _WinAPI_DuplicateTokenEx +; _WinAPI_EmptyWorkingSet +; _WinAPI_EnumChildProcess +; _WinAPI_EnumDeviceDrivers +; _WinAPI_EnumProcessHandles +; _WinAPI_EnumProcessModules +; _WinAPI_EnumProcessThreads +; _WinAPI_EnumProcessWindows +; _WinAPI_GetCurrentProcessExplicitAppUserModelID +; _WinAPI_GetDeviceDriverBaseName +; _WinAPI_GetDeviceDriverFileName +; _WinAPI_GetExitCodeProcess +; _WinAPI_GetModuleFileNameEx +; _WinAPI_GetModuleInformation +; _WinAPI_GetParentProcess +; _WinAPI_GetPriorityClass +; _WinAPI_GetProcessCommandLine +; _WinAPI_GetProcessFileName +; _WinAPI_GetProcessHandleCount +; _WinAPI_GetProcessID +; _WinAPI_GetProcessIoCounters +; _WinAPI_GetProcessMemoryInfo +; _WinAPI_GetProcessName +; _WinAPI_GetProcessTimes +; _WinAPI_GetProcessUser +; _WinAPI_GetProcessWorkingDirectory +; _WinAPI_GetThreadDesktop +; _WinAPI_GetThreadErrorMode +; _WinAPI_GetWindowFileName +; _WinAPI_IsElevated +; _WinAPI_IsProcessInJob +; _WinAPI_IsWow64Process +; _WinAPI_OpenJobObject +; _WinAPI_OpenMutex +; _WinAPI_OpenProcessToken +; _WinAPI_OpenSemaphore +; _WinAPI_QueryInformationJobObject +; _WinAPI_ReleaseMutex +; _WinAPI_ReleaseSemaphore +; _WinAPI_ResetEvent +; _WinAPI_SetInformationJobObject +; _WinAPI_SetPriorityClass +; _WinAPI_SetThreadDesktop +; _WinAPI_SetThreadErrorMode +; _WinAPI_SetThreadExecutionState +; _WinAPI_TerminateJobObject +; _WinAPI_TerminateProcess +; _WinAPI_UserHandleGrantAccess +; =============================================================================================================================== +#EndRegion Functions list + +#Region Public Functions + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_AdjustTokenPrivileges($hToken, $aPrivileges, $iAttributes, ByRef $aAdjust) + $aAdjust = 0 + If Not $aPrivileges And IsNumber($aPrivileges) Then Return 0 + + Local $tTP1 = 0, $tTP2, $iCount, $aRet, $bDisable = False + If $aPrivileges = -1 Then + $tTP2 = DllStructCreate('dword') + $aRet = DllCall('advapi32.dll', 'bool', 'AdjustTokenPrivileges', 'handle', $hToken, 'bool', 1, 'ptr', 0, _ + 'dword', 0, 'struct*', $tTP2, 'dword*', 0) + If @error Then Return SetError(@error, @extended, 0) + Local $iLastError = _WinAPI_GetLastError() + Switch $iLastError + Case 122 ; ERROR_INSUFFICIENT_BUFFER + $tTP2 = DllStructCreate('dword;dword[' & ($aRet[6] / 4 - 1) & ']') + If @error Then + ContinueCase + EndIf + Case Else + Return SetError(10, $iLastError, 0) + EndSwitch + $bDisable = True + Else + Local $aPrev = 0 + If Not IsArray($aPrivileges) Then + Dim $aPrev[1][2] + $aPrev[0][0] = $aPrivileges + $aPrev[0][1] = $iAttributes + Else + If Not UBound($aPrivileges, $UBOUND_COLUMNS) Then + $iCount = UBound($aPrivileges) + Dim $aPrev[$iCount][2] + For $i = 0 To $iCount - 1 + $aPrev[$i][0] = $aPrivileges[$i] + $aPrev[$i][1] = $iAttributes + Next + EndIf + EndIf + If IsArray($aPrev) Then + $aPrivileges = $aPrev + EndIf + Local $tagStruct = 'dword;dword[' & (3 * UBound($aPrivileges)) & ']' + $tTP1 = DllStructCreate($tagStruct) + $tTP2 = DllStructCreate($tagStruct) + If @error Then Return SetError(@error + 20, 0, 0) + + DllStructSetData($tTP1, 1, UBound($aPrivileges)) + For $i = 0 To UBound($aPrivileges) - 1 + DllStructSetData($tTP1, 2, $aPrivileges[$i][1], 3 * $i + 3) + $aRet = DllCall('advapi32.dll', 'bool', 'LookupPrivilegeValueW', 'ptr', 0, 'wstr', $aPrivileges[$i][0], _ + 'ptr', DllStructGetPtr($tTP1, 2) + 12 * $i) + If @error Or Not $aRet[0] Then Return SetError(@error + 100, @extended, 0) + Next + EndIf + $aRet = DllCall('advapi32.dll', 'bool', 'AdjustTokenPrivileges', 'handle', $hToken, 'bool', $bDisable, _ + 'struct*', $tTP1, 'dword', DllStructGetSize($tTP2), 'struct*', $tTP2, 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error + 200, @extended, 0) + + Local $iResult + Switch _WinAPI_GetLastError() + Case 1300 ; ERROR_NOT_ALL_ASSIGNED + $iResult = 1 + Case Else + $iResult = 0 + EndSwitch + $iCount = DllStructGetData($tTP2, 1) + If $iCount Then + Local $tData = DllStructCreate('wchar[128]') + Dim $aPrivileges[$iCount][2] + For $i = 0 To $iCount - 1 + $aRet = DllCall('advapi32.dll', 'bool', 'LookupPrivilegeNameW', 'ptr', 0, _ + 'ptr', DllStructGetPtr($tTP2, 2) + 12 * $i, 'struct*', $tData, 'dword*', 128) + If @error Or Not $aRet[0] Then Return SetError(@error + 300, @extended, 0) + + $aPrivileges[$i][1] = DllStructGetData($tTP2, 2, 3 * $i + 3) + $aPrivileges[$i][0] = DllStructGetData($tData, 1) + Next + $aAdjust = $aPrivileges + EndIf + + Return SetExtended($iResult, 1) +EndFunc ;==>_WinAPI_AdjustTokenPrivileges + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_AssignProcessToJobObject($hJob, $hProcess) + Local $aRet = DllCall('kernel32.dll', 'bool', 'AssignProcessToJobObject', 'handle', $hJob, 'handle', $hProcess) + If @error Then Return SetError(@error, @extended, False) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_AssignProcessToJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_CreateJobObject($sName = '', $tSecurity = 0) + Local $sTypeOfName = 'wstr' + If Not StringStripWS($sName, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then + $sTypeOfName = 'ptr' + $sName = 0 + EndIf + + Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateJobObjectW', 'struct*', $tSecurity, $sTypeOfName, $sName) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_CreateJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_CreateMutex($sMutex, $bInitial = True, $tSecurity = 0) + Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateMutexW', 'struct*', $tSecurity, 'bool', $bInitial, 'wstr', $sMutex) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_CreateMutex + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_CreateProcessWithToken($sApp, $sCmd, $iFlags, $tStartupInfo, $tProcessInfo, $hToken, $iLogon = 0, $pEnvironment = 0, $sDir = '') + Local $sTypeOfApp = 'wstr', $sTypeOfCmd = 'wstr', $sTypeOfDir = 'wstr' + If Not StringStripWS($sApp, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then + $sTypeOfApp = 'ptr' + $sApp = 0 + EndIf + If Not StringStripWS($sCmd, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then + $sTypeOfCmd = 'ptr' + $sCmd = 0 + EndIf + If Not StringStripWS($sDir, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then + $sTypeOfDir = 'ptr' + $sDir = 0 + EndIf + + Local $aRet = DllCall('advapi32.dll', 'bool', 'CreateProcessWithTokenW', 'handle', $hToken, 'dword', $iLogon, _ + $sTypeOfApp, $sApp, $sTypeOfCmd, $sCmd, 'dword', $iFlags, 'struct*', $pEnvironment, _ + $sTypeOfDir, $sDir, 'struct*', $tStartupInfo, 'struct*', $tProcessInfo) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_CreateProcessWithToken + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_CreateSemaphore($sSemaphore, $iInitial, $iMaximum, $tSecurity = 0) + Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateSemaphoreW', 'struct*', $tSecurity, 'long', $iInitial, _ + 'long', $iMaximum, 'wstr', $sSemaphore) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_CreateSemaphore + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_DuplicateTokenEx($hToken, $iAccess, $iLevel, $iType = 1, $tSecurity = 0) + Local $aRet = DllCall('advapi32.dll', 'bool', 'DuplicateTokenEx', 'handle', $hToken, 'dword', $iAccess, _ + 'struct*', $tSecurity, 'int', $iLevel, 'int', $iType, 'handle*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[6] +EndFunc ;==>_WinAPI_DuplicateTokenEx + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EmptyWorkingSet($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000500, 0x00001100), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EmptyWorkingSet', 'handle', $hProcess[0]) + If __CheckErrorCloseHandle($aRet, $hProcess[0]) Then Return SetError(@error, @extended, 0) + + Return 1 +EndFunc ;==>_WinAPI_EmptyWorkingSet + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumChildProcess($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hSnapshot = DllCall('kernel32.dll', 'handle', 'CreateToolhelp32Snapshot', 'dword', 0x00000002, 'dword', 0) + If @error Or ($hSnapshot[0] = Ptr(-1)) Then Return SetError(@error + 10, @extended, 0) ; $INVALID_HANDLE_VALUE + + Local $tPROCESSENTRY32 = DllStructCreate($tagPROCESSENTRY32) + Local $aResult[101][2] = [[0]] + + $hSnapshot = $hSnapshot[0] + DllStructSetData($tPROCESSENTRY32, 'Size', DllStructGetSize($tPROCESSENTRY32)) + Local $aRet = DllCall('kernel32.dll', 'bool', 'Process32FirstW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + Local $iError = @error + While (Not @error) And ($aRet[0]) + If DllStructGetData($tPROCESSENTRY32, 'ParentProcessID') = $iPID Then + __Inc($aResult) + $aResult[$aResult[0][0]][0] = DllStructGetData($tPROCESSENTRY32, 'ProcessID') + $aResult[$aResult[0][0]][1] = DllStructGetData($tPROCESSENTRY32, 'ExeFile') + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'Process32NextW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + $iError = @error + WEnd + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hSnapshot) + If Not $aResult[0][0] Then Return SetError($iError + 20, 0, 0) + + __Inc($aResult, -1) + Return $aResult +EndFunc ;==>_WinAPI_EnumChildProcess + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumDeviceDrivers() + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumDeviceDrivers', 'ptr', 0, 'dword', 0, 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Local $iSize + If @AutoItX64 Then + $iSize = $aRet[3] / 8 + Else + $iSize = $aRet[3] / 4 + EndIf + Local $tData = DllStructCreate('ptr[' & $iSize & ']') + $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumDeviceDrivers', 'struct*', $tData, _ + 'dword', DllStructGetSize($tData), 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error + 20, @extended, 0) + + Local $aResult[$iSize + 1] = [$iSize] + For $i = 1 To $iSize + $aResult[$i] = DllStructGetData($tData, 1, $i) + Next + Return $aResult +EndFunc ;==>_WinAPI_EnumDeviceDrivers + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumProcessHandles($iPID = 0, $iType = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $aResult[101][4] = [[0]] + + Local $tSHI = DllStructCreate('ulong;byte[4194304]') + Local $aRet = DllCall('ntdll.dll', 'long', 'ZwQuerySystemInformation', 'uint', 16, 'struct*', $tSHI, _ + 'ulong', DllStructGetSize($tSHI), 'ulong*', 0) + If @error Then Return SetError(@error, @extended, 0) + If $aRet[0] Then Return SetError(10, $aRet[0], 0) + + Local $pData = DllStructGetPtr($tSHI, 2) + Local $tHandle + For $i = 1 To DllStructGetData($tSHI, 1) + $tHandle = DllStructCreate('align 4;ulong;byte;byte;ushort;ptr;ulong', $pData + __Iif(@AutoItX64, 4 + ($i - 1) * 24, ($i - 1) * 16)) + If (DllStructGetData($tHandle, 1) = $iPID) And ((Not $iType) Or ($iType = DllStructGetData($tHandle, 2))) Then + __Inc($aResult) + $aResult[$aResult[0][0]][0] = Ptr(DllStructGetData($tHandle, 4)) + $aResult[$aResult[0][0]][1] = DllStructGetData($tHandle, 2) + $aResult[$aResult[0][0]][2] = DllStructGetData($tHandle, 3) + $aResult[$aResult[0][0]][3] = DllStructGetData($tHandle, 6) + EndIf + Next + If Not $aResult[0][0] Then Return SetError(11, 0, 0) + + __Inc($aResult, -1) + Return $aResult +EndFunc ;==>_WinAPI_EnumProcessHandles + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumProcessModules($iPID = 0, $iFlag = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000410, 0x00001010), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $iCount, $aRet, $iError = 0 + Do + If $__WINVER >= 0x0600 Then + $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumProcessModulesEx', 'handle', $hProcess[0], 'ptr', 0, _ + 'dword', 0, 'dword*', 0, 'dword', $iFlag) + Else + $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumProcessModules', 'handle', $hProcess[0], 'ptr', 0, _ + 'dword', 0, 'dword*', 0) + EndIf + If @error Or Not $aRet[0] Then + $iError = @error + 10 + ExitLoop + EndIf + If @AutoItX64 Then + $iCount = $aRet[4] / 8 + Else + $iCount = $aRet[4] / 4 + EndIf + Local $tPtr = DllStructCreate('ptr[' & $iCount & ']') + If @error Then + $iError = @error + 30 + ExitLoop + EndIf + If $__WINVER >= 0x0600 Then + $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumProcessModulesEx', 'handle', $hProcess[0], 'struct*', $tPtr, _ + 'dword', DllStructGetSize($tPtr), 'dword*', 0, 'dword', $iFlag) + Else + $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'EnumProcessModules', 'handle', $hProcess[0], 'struct*', $tPtr, _ + 'dword', DllStructGetSize($tPtr), 'dword*', 0) + EndIf + If @error Or Not $aRet[0] Then + $iError = @error + 40 + ExitLoop + EndIf + Local $aResult[$iCount + 1][2] = [[$iCount]] + For $i = 1 To $iCount + $aResult[$i][0] = DllStructGetData($tPtr, 1, $i) + $aResult[$i][1] = _WinAPI_GetModuleFileNameEx($hProcess[0], $aResult[$i][0]) + Next + Until 1 + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess[0]) + If $iError Then Return SetError($iError, 0, 0) + + Return $aResult +EndFunc ;==>_WinAPI_EnumProcessModules + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumProcessThreads($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hSnapshot = DllCall('kernel32.dll', 'handle', 'CreateToolhelp32Snapshot', 'dword', 0x00000004, 'dword', 0) + If @error Or Not $hSnapshot[0] Then Return SetError(@error + 10, @extended, 0) + + Local Const $tagTHREADENTRY32 = 'dword Size;dword Usage;dword ThreadID;dword OwnerProcessID;long BasePri;long DeltaPri;dword Flags' + Local $tTHREADENTRY32 = DllStructCreate($tagTHREADENTRY32) + Local $aResult[101] = [0] + + $hSnapshot = $hSnapshot[0] + DllStructSetData($tTHREADENTRY32, 'Size', DllStructGetSize($tTHREADENTRY32)) + Local $aRet = DllCall('kernel32.dll', 'bool', 'Thread32First', 'handle', $hSnapshot, 'struct*', $tTHREADENTRY32) + While Not @error And $aRet[0] + If DllStructGetData($tTHREADENTRY32, 'OwnerProcessID') = $iPID Then + __Inc($aResult) + $aResult[$aResult[0]] = DllStructGetData($tTHREADENTRY32, 'ThreadID') + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'Thread32Next', 'handle', $hSnapshot, 'struct*', $tTHREADENTRY32) + WEnd + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hSnapshot) + If Not $aResult[0] Then Return SetError(1, 0, 0) + + __Inc($aResult, -1) + Return $aResult +EndFunc ;==>_WinAPI_EnumProcessThreads + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_EnumProcessWindows($iPID = 0, $bVisible = True) + Local $aThreads = _WinAPI_EnumProcessThreads($iPID) + If @error Then Return SetError(@error, @extended, 0) + + Local $hEnumProc = DllCallbackRegister('__EnumWindowsProc', 'bool', 'hwnd;lparam') + + Dim $__g_vEnum[101][2] = [[0]] + For $i = 1 To $aThreads[0] + DllCall('user32.dll', 'bool', 'EnumThreadWindows', 'dword', $aThreads[$i], 'ptr', DllCallbackGetPtr($hEnumProc), _ + 'lparam', $bVisible) + If @error Then + ExitLoop + EndIf + Next + DllCallbackFree($hEnumProc) + If Not $__g_vEnum[0][0] Then Return SetError(11, 0, 0) + + __Inc($__g_vEnum, -1) + Return $__g_vEnum +EndFunc ;==>_WinAPI_EnumProcessWindows + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetCurrentProcessExplicitAppUserModelID() + Local $aRet = DllCall('shell32.dll', 'long', 'GetCurrentProcessExplicitAppUserModelID', 'ptr*', 0) + If @error Then Return SetError(@error, @extended, '') + If $aRet[0] Then Return SetError(10, $aRet[0], '') + + Local $sID = _WinAPI_GetString($aRet[1]) + _WinAPI_CoTaskMemFree($aRet[1]) + Return $sID +EndFunc ;==>_WinAPI_GetCurrentProcessExplicitAppUserModelID + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetDeviceDriverBaseName($pDriver) + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'dword', 'GetDeviceDriverBaseNameW', 'ptr', $pDriver, 'wstr', '', _ + 'dword', 4096) + If @error Then Return SetError(@error, @extended, '') + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[2] +EndFunc ;==>_WinAPI_GetDeviceDriverBaseName + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetDeviceDriverFileName($pDriver) + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'dword', 'GetDeviceDriverFileNameW', 'ptr', $pDriver, 'wstr', '', _ + 'dword', 4096) + If @error Then Return SetError(@error, @extended, '') + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[2] +EndFunc ;==>_WinAPI_GetDeviceDriverFileName + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetExitCodeProcess($hProcess) + Local $aRet = DllCall('kernel32.dll', 'bool', 'GetExitCodeProcess', 'handle', $hProcess, 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[2] +EndFunc ;==>_WinAPI_GetExitCodeProcess + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetModuleFileNameEx($hProcess, $hModule = 0) + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'dword', 'GetModuleFileNameExW', 'handle', $hProcess, 'handle', $hModule, _ + 'wstr', '', 'int', 4096) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '') + + Return $aRet[3] +EndFunc ;==>_WinAPI_GetModuleFileNameEx + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetModuleInformation($hProcess, $hModule = 0) + Local $tMODULEINFO = DllStructCreate($tagMODULEINFO) + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'GetModuleInformation', 'handle', $hProcess, 'handle', $hModule, _ + 'struct*', $tMODULEINFO, 'dword', DllStructGetSize($tMODULEINFO)) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $tMODULEINFO +EndFunc ;==>_WinAPI_GetModuleInformation + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetParentProcess($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hSnapshot = DllCall('kernel32.dll', 'handle', 'CreateToolhelp32Snapshot', 'dword', 0x00000002, 'dword', 0) + If @error Or Not $hSnapshot[0] Then Return SetError(@error + 10, @extended, 0) + + Local $tPROCESSENTRY32 = DllStructCreate($tagPROCESSENTRY32) + Local $iResult = 0 + + $hSnapshot = $hSnapshot[0] + DllStructSetData($tPROCESSENTRY32, 'Size', DllStructGetSize($tPROCESSENTRY32)) + Local $aRet = DllCall('kernel32.dll', 'bool', 'Process32FirstW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + Local $iError = @error + While (Not @error) And ($aRet[0]) + If DllStructGetData($tPROCESSENTRY32, 'ProcessID') = $iPID Then + $iResult = DllStructGetData($tPROCESSENTRY32, 'ParentProcessID') + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'Process32NextW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + $iError = @error + WEnd + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hSnapshot) + If Not $iResult Then Return SetError($iError, 0, 0) + + Return $iResult +EndFunc ;==>_WinAPI_GetParentProcess + +; #FUNCTION# ==================================================================================================================== +; Author.........: KaFu +; Modified.......: Yashied, Jpm +; =============================================================================================================================== +Func _WinAPI_GetPriorityClass($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + ; If Not $hProcess[0] Then Return SetError(1000, 0, 0) + + Local $iError = 0 + Local $aRet = DllCall('kernel32.dll', 'dword', 'GetPriorityClass', 'handle', $hProcess[0]) + If @error Then $iError = @error + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess[0]) + If $iError Then Return SetError($iError, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_GetPriorityClass + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessCommandLine($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000410, 0x00001010), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, '') + + $hProcess = $hProcess[0] + + Local $tPBI = DllStructCreate('ulong_ptr ExitStatus;ptr PebBaseAddress;ulong_ptr AffinityMask;ulong_ptr BasePriority;ulong_ptr UniqueProcessId;ulong_ptr InheritedFromUniqueProcessId') + Local $tPEB = DllStructCreate('byte InheritedAddressSpace;byte ReadImageFileExecOptions;byte BeingDebugged;byte Spare;ptr Mutant;ptr ImageBaseAddress;ptr LoaderData;ptr ProcessParameters;ptr SubSystemData;ptr ProcessHeap;ptr FastPebLock;ptr FastPebLockRoutine;ptr FastPebUnlockRoutine;ulong EnvironmentUpdateCount;ptr KernelCallbackTable;ptr EventLogSection;ptr EventLog;ptr FreeList;ulong TlsExpansionCounter;ptr TlsBitmap;ulong TlsBitmapBits[2];ptr ReadOnlySharedMemoryBase;ptr ReadOnlySharedMemoryHeap;ptr ReadOnlyStaticServerData;ptr AnsiCodePageData;ptr OemCodePageData;ptr UnicodeCaseTableData;ulong NumberOfProcessors;ulong NtGlobalFlag;byte Spare2[4];int64 CriticalSectionTimeout;ulong HeapSegmentReserve;ulong HeapSegmentCommit;ulong HeapDeCommitTotalFreeThreshold;ulong HeapDeCommitFreeBlockThreshold;ulong NumberOfHeaps;ulong MaximumNumberOfHeaps;ptr ProcessHeaps;ptr GdiSharedHandleTable;ptr ProcessStarterHelper;ptr GdiDCAttributeList;ptr LoaderLock;ulong OSMajorVersion;ulong OSMinorVersion;ulong OSBuildNumber;ulong OSPlatformId;ulong ImageSubSystem;ulong ImageSubSystemMajorVersion;ulong ImageSubSystemMinorVersion;ulong GdiHandleBuffer[34];ulong PostProcessInitRoutine;ulong TlsExpansionBitmap;byte TlsExpansionBitmapBits[128];ulong SessionId') + Local $tUPP = DllStructCreate('ulong AllocationSize;ulong ActualSize;ulong Flags;ulong Unknown1;ushort LengthUnknown2;ushort MaxLengthUnknown2;ptr Unknown2;ptr InputHandle;ptr OutputHandle;ptr ErrorHandle;ushort LengthCurrentDirectory;ushort MaxLengthCurrentDirectory;ptr CurrentDirectory;ptr CurrentDirectoryHandle;ushort LengthSearchPaths;ushort MaxLengthSearchPaths;ptr SearchPaths;ushort LengthApplicationName;ushort MaxLengthApplicationName;ptr ApplicationName;ushort LengthCommandLine;ushort MaxLengthCommandLine;ptr CommandLine;ptr EnvironmentBlock;ulong Unknown[9];ushort LengthUnknown3;ushort MaxLengthUnknown3;ptr Unknown3;ushort LengthUnknown4;ushort MaxLengthUnknown4;ptr Unknown4;ushort LengthUnknown5;ushort MaxLengthUnknown5;ptr Unknown5') + Local $tCMD + + Local $aRet, $iError = 0 + Do + $aRet = DllCall('ntdll.dll', 'long', 'NtQueryInformationProcess', 'handle', $hProcess, 'ulong', 0, 'struct*', $tPBI, _ + 'ulong', DllStructGetSize($tPBI), 'ulong*', 0) + If @error Or $aRet[0] Then + $iError = @error + 30 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tPBI, 'PebBaseAddress'), 'struct*', $tPEB, _ + 'ulong_ptr', DllStructGetSize($tPEB), 'ulong_ptr*', 0) + If @error Or Not $aRet[0] Or (Not $aRet[5]) Then + $iError = @error + 40 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tPEB, 'ProcessParameters'), 'struct*', $tUPP, _ + 'ulong_ptr', DllStructGetSize($tUPP), 'ulong_ptr*', 0) + If @error Or Not $aRet[0] Or (Not $aRet[5]) Then + $iError = @error + 50 + ExitLoop + EndIf + $tCMD = DllStructCreate('byte[' & DllStructGetData($tUPP, 'MaxLengthCommandLine') & ']') + If @error Then + $iError = @error + 60 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tUPP, 'CommandLine'), 'struct*', $tCMD, _ + 'ulong_ptr', DllStructGetSize($tCMD), 'ulong_ptr*', 0) + If @error Or Not $aRet[0] Or (Not $aRet[5]) Then + $iError = @error + 70 + ExitLoop + EndIf + Until 1 + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) + If $iError Then Return SetError($iError, 0, '') + + Return StringStripWS(_WinAPI_PathGetArgs(_WinAPI_GetString(DllStructGetPtr($tCMD, 1))), $STR_STRIPLEADING + $STR_STRIPTRAILING) +EndFunc ;==>_WinAPI_GetProcessCommandLine + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessFileName($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000410, 0x00001010), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, '') + + Local $sPath = _WinAPI_GetModuleFileNameEx($hProcess[0]) + Local $iError = @error + + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess[0]) + If $iError Then Return SetError(@error, 0, '') + + Return $sPath +EndFunc ;==>_WinAPI_GetProcessFileName + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessHandleCount($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $aRet = DllCall('kernel32.dll', 'bool', 'GetProcessHandleCount', 'handle', $hProcess[0], 'dword*', 0) + If __CheckErrorCloseHandle($aRet, $hProcess[0]) Then Return SetError(@error, @extended, 0) + + Return $aRet[2] +EndFunc ;==>_WinAPI_GetProcessHandleCount + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessID($hProcess) + Local $aRet = DllCall('kernel32.dll', 'dword', 'GetProcessId', 'handle', $hProcess) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_GetProcessID + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessIoCounters($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $tIO_COUNTERS = DllStructCreate('uint64[6]') + Local $aRet = DllCall('kernel32.dll', 'bool', 'GetProcessIoCounters', 'handle', $hProcess[0], 'struct*', $tIO_COUNTERS) + If __CheckErrorCloseHandle($aRet, $hProcess[0]) Then Return SetError(@error, @extended, 0) + + Local $aResult[6] + For $i = 0 To 5 + $aResult[$i] = DllStructGetData($tIO_COUNTERS, 1, $i + 1) + Next + Return $aResult +EndFunc ;==>_WinAPI_GetProcessIoCounters + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessMemoryInfo($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000410, 0x00001010), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $tPMC_EX = DllStructCreate('dword;dword;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr;ulong_ptr') + Local $aRet = DllCall(@SystemDir & '\psapi.dll', 'bool', 'GetProcessMemoryInfo', 'handle', $hProcess[0], 'struct*', $tPMC_EX, _ + 'int', DllStructGetSize($tPMC_EX)) + If __CheckErrorCloseHandle($aRet, $hProcess[0]) Then Return SetError(@error, @extended, 0) + + Local $aResult[10] + For $i = 0 To 9 + $aResult[$i] = DllStructGetData($tPMC_EX, $i + 2) + Next + Return $aResult +EndFunc ;==>_WinAPI_GetProcessMemoryInfo + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessName($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hSnapshot = DllCall('kernel32.dll', 'handle', 'CreateToolhelp32Snapshot', 'dword', 0x00000002, 'dword', 0) + If @error Or Not $hSnapshot[0] Then Return SetError(@error + 20, @extended, '') + + $hSnapshot = $hSnapshot[0] + Local $tPROCESSENTRY32 = DllStructCreate($tagPROCESSENTRY32) + DllStructSetData($tPROCESSENTRY32, 'Size', DllStructGetSize($tPROCESSENTRY32)) + Local $aRet = DllCall('kernel32.dll', 'bool', 'Process32FirstW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + Local $iError = @error + While (Not @error) And ($aRet[0]) + If DllStructGetData($tPROCESSENTRY32, 'ProcessID') = $iPID Then + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'Process32NextW', 'handle', $hSnapshot, 'struct*', $tPROCESSENTRY32) + $iError = @error + WEnd + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hSnapshot) + If $iError Then Return SetError($iError, 0, '') + If Not $aRet[0] Then SetError(10, 0, '') + + Return DllStructGetData($tPROCESSENTRY32, 'ExeFile') +EndFunc ;==>_WinAPI_GetProcessName + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessTimes($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Local $tFILETIME = DllStructCreate($tagFILETIME) + Local $aRet = DllCall('kernel32.dll', 'bool', 'GetProcessTimes', 'handle', $hProcess[0], 'struct*', $tFILETIME, 'uint64*', 0, _ + 'uint64*', 0, 'uint64*', 0) + If __CheckErrorCloseHandle($aRet, $hProcess[0]) Then Return SetError(@error, @extended, 0) + + Local $aResult[3] + $aResult[0] = $tFILETIME + $aResult[1] = $aRet[4] + $aResult[2] = $aRet[5] + Return $aResult +EndFunc ;==>_WinAPI_GetProcessTimes + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessUser($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $tSID, $hToken, $aRet + Local $iError = 0 + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, 0) + + Do + $hToken = _WinAPI_OpenProcessToken(0x00000008, $hProcess[0]) + If Not $hToken Then + $iError = @error + 10 + ExitLoop + EndIf + $tSID = DllStructCreate('ptr;byte[1024]') + $aRet = DllCall('advapi32.dll', 'bool', 'GetTokenInformation', 'handle', $hToken, 'uint', 1, 'struct*', $tSID, _ + 'dword', DllStructGetSize($tSID), 'dword*', 0) + If @error Or Not $aRet[0] Then + $iError = @error + 30 + ExitLoop + EndIf + $aRet = DllCall('advapi32.dll', 'bool', 'LookupAccountSidW', 'ptr', 0, 'ptr', DllStructGetData($tSID, 1), 'wstr', '', _ + 'dword*', 2048, 'wstr', '', 'dword*', 2048, 'uint*', 0) + If @error Or Not $aRet[0] Then + $iError = @error + 40 + ExitLoop + EndIf + Until 1 + If $hToken Then + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hToken) + EndIf + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess[0]) + If $iError Then Return SetError($iError, 0, 0) + + Local $aResult[2] + $aResult[0] = $aRet[3] + $aResult[1] = $aRet[5] + Return $aResult +EndFunc ;==>_WinAPI_GetProcessUser + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetProcessWorkingDirectory($iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $aRet, $iError = 0 + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000410, 0x00001010), 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, '') + + $hProcess = $hProcess[0] + + Local $tPBI = DllStructCreate('ulong_ptr ExitStatus;ptr PebBaseAddress;ulong_ptr AffinityMask;ulong_ptr BasePriority;ulong_ptr UniqueProcessId;ulong_ptr InheritedFromUniqueProcessId') + Local $tPEB = DllStructCreate('byte InheritedAddressSpace;byte ReadImageFileExecOptions;byte BeingDebugged;byte Spare;ptr Mutant;ptr ImageBaseAddress;ptr LoaderData;ptr ProcessParameters;ptr SubSystemData;ptr ProcessHeap;ptr FastPebLock;ptr FastPebLockRoutine;ptr FastPebUnlockRoutine;ulong EnvironmentUpdateCount;ptr KernelCallbackTable;ptr EventLogSection;ptr EventLog;ptr FreeList;ulong TlsExpansionCounter;ptr TlsBitmap;ulong TlsBitmapBits[2];ptr ReadOnlySharedMemoryBase;ptr ReadOnlySharedMemoryHeap;ptr ReadOnlyStaticServerData;ptr AnsiCodePageData;ptr OemCodePageData;ptr UnicodeCaseTableData;ulong NumberOfProcessors;ulong NtGlobalFlag;byte Spare2[4];int64 CriticalSectionTimeout;ulong HeapSegmentReserve;ulong HeapSegmentCommit;ulong HeapDeCommitTotalFreeThreshold;ulong HeapDeCommitFreeBlockThreshold;ulong NumberOfHeaps;ulong MaximumNumberOfHeaps;ptr ProcessHeaps;ptr GdiSharedHandleTable;ptr ProcessStarterHelper;ptr GdiDCAttributeList;ptr LoaderLock;ulong OSMajorVersion;ulong OSMinorVersion;ulong OSBuildNumber;ulong OSPlatformId;ulong ImageSubSystem;ulong ImageSubSystemMajorVersion;ulong ImageSubSystemMinorVersion;ulong GdiHandleBuffer[34];ulong PostProcessInitRoutine;ulong TlsExpansionBitmap;byte TlsExpansionBitmapBits[128];ulong SessionId') + Local $tUPP = DllStructCreate('ulong AllocationSize;ulong ActualSize;ulong Flags;ulong Unknown1;ushort LengthUnknown2;ushort MaxLengthUnknown2;ptr Unknown2;ptr InputHandle;ptr OutputHandle;ptr ErrorHandle;ushort LengthCurrentDirectory;ushort MaxLengthCurrentDirectory;ptr CurrentDirectory;ptr CurrentDirectoryHandle;ushort LengthSearchPaths;ushort MaxLengthSearchPaths;ptr SearchPaths;ushort LengthApplicationName;ushort MaxLengthApplicationName;ptr ApplicationName;ushort LengthCommandLine;ushort MaxLengthCommandLine;ptr CommandLine;ptr EnvironmentBlock;ulong Unknown[9];ushort LengthUnknown3;ushort MaxLengthUnknown3;ptr Unknown3;ushort LengthUnknown4;ushort MaxLengthUnknown4;ptr Unknown4;ushort LengthUnknown5;ushort MaxLengthUnknown5;ptr Unknown5') + Local $tDIR + + Do + $aRet = DllCall('ntdll.dll', 'long', 'NtQueryInformationProcess', 'handle', $hProcess, 'ulong', 0, 'struct*', $tPBI, _ + 'ulong', DllStructGetSize($tPBI), 'ulong*', 0) + If @error Or ($aRet[0]) Then + $iError = @error + 10 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tPBI, 'PebBaseAddress'), 'struct*', $tPEB, _ + 'ulong_ptr', DllStructGetSize($tPEB), 'ulong_ptr*', 0) + If @error Or (Not $aRet[0]) Or (Not $aRet[5]) Then + $iError = @error + 30 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tPEB, 'ProcessParameters'), 'struct*', $tUPP, _ + 'ulong_ptr', DllStructGetSize($tUPP), 'ulong_ptr*', 0) + If @error Or (Not $aRet[0]) Or (Not $aRet[5]) Then + $iError = @error + 40 + ExitLoop + EndIf + $tDIR = DllStructCreate('byte[' & DllStructGetData($tUPP, 'MaxLengthCurrentDirectory') & ']') + If @error Then + $iError = @error + 50 + ExitLoop + EndIf + $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _ + 'ptr', DllStructGetData($tUPP, 'CurrentDirectory'), 'struct*', $tDIR, _ + 'ulong_ptr', DllStructGetSize($tDIR), 'ulong_ptr*', 0) + If @error Or (Not $aRet[0]) Or (Not $aRet[5]) Then + $iError = @error + 60 + ExitLoop + EndIf + $iError = 0 + Until 1 + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) + If $iError Then Return SetError($iError, 0, '') + + Return _WinAPI_PathRemoveBackslash(_WinAPI_GetString(DllStructGetPtr($tDIR))) +EndFunc ;==>_WinAPI_GetProcessWorkingDirectory + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_GetThreadDesktop($iThreadId) + Local $aRet = DllCall('user32.dll', 'handle', 'GetThreadDesktop', 'dword', $iThreadId) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_GetThreadDesktop + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetThreadErrorMode() + Local $aRet = DllCall('kernel32.dll', 'dword', 'GetThreadErrorMode') + If @error Then Return SetError(@error, @extended, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_GetThreadErrorMode + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_GetWindowFileName($hWnd) + Local $iPID = 0 + + Local $aResult = DllCall("user32.dll", "bool", "IsWindow", "hwnd", $hWnd) + If $aResult[0] Then + $aResult = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0) + $iPID = $aResult[2] + EndIf + If Not $iPID Then Return SetError(1, 0, '') + + Local $sResult = _WinAPI_GetProcessFileName($iPID) + If @error Then Return SetError(@error, @extended, '') + + Return $sResult +EndFunc ;==>_WinAPI_GetWindowFileName + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_IsElevated() + Local $iElev, $aRet, $iError = 0 + + Local $hToken = _WinAPI_OpenProcessToken(0x0008) + If Not $hToken Then Return SetError(@error + 10, @extended, False) + + Do + $aRet = DllCall('advapi32.dll', 'bool', 'GetTokenInformation', 'handle', $hToken, 'uint', 20, 'uint*', 0, 'dword', 4, _ + 'dword*', 0) ; TOKEN_ELEVATION + If @error Or Not $aRet[0] Then + $iError = @error + 10 + ExitLoop + EndIf + $iElev = $aRet[3] + $aRet = DllCall('advapi32.dll', 'bool', 'GetTokenInformation', 'handle', $hToken, 'uint', 18, 'uint*', 0, 'dword', 4, _ + 'dword*', 0) ; TOKEN_ELEVATION_TYPE + If @error Or Not $aRet[0] Then + $iError = @error + 20 + ExitLoop + EndIf + Until 1 + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hToken) + If $iError Then Return SetError($iError, 0, False) + + Return SetExtended($aRet[0] - 1, $iElev) +EndFunc ;==>_WinAPI_IsElevated + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_IsProcessInJob($hProcess, $hJob = 0) + Local $aRet = DllCall('kernel32.dll', 'bool', 'IsProcessInJob', 'handle', $hProcess, 'handle', $hJob, 'bool*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error, @extended, False) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[3] +EndFunc ;==>_WinAPI_IsProcessInJob + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_OpenJobObject($sName, $iAccess = $JOB_OBJECT_ALL_ACCESS, $bInherit = False) + Local $aRet = DllCall('kernel32.dll', 'handle', 'OpenJobObjectW', 'dword', $iAccess, 'bool', $bInherit, 'wstr', $sName) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_OpenJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_OpenMutex($sMutex, $iAccess = $MUTEX_ALL_ACCESS, $bInherit = False) + Local $aRet = DllCall('kernel32.dll', 'handle', 'OpenMutexW', 'dword', $iAccess, 'bool', $bInherit, 'wstr', $sMutex) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_OpenMutex + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_OpenProcessToken($iAccess, $hProcess = 0) + If Not $hProcess Then + $hProcess = DllCall("kernel32.dll", "handle", "GetCurrentProcess") + $hProcess = $hProcess[0] + EndIf + + Local $aRet = DllCall('advapi32.dll', 'bool', 'OpenProcessToken', 'handle', $hProcess, 'dword', $iAccess, 'handle*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[3] +EndFunc ;==>_WinAPI_OpenProcessToken + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_OpenSemaphore($sSemaphore, $iAccess = 0x001F0003, $bInherit = False) + Local $aRet = DllCall('kernel32.dll', 'handle', 'OpenSemaphoreW', 'dword', $iAccess, 'bool', $bInherit, 'wstr', $sSemaphore) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_OpenSemaphore + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_QueryInformationJobObject($hJob, $iJobObjectInfoClass, ByRef $tJobObjectInfo) + Local $aRet = DllCall('kernel32.dll', 'bool', 'QueryInformationJobObject', 'handle', $hJob, 'int', $iJobObjectInfoClass, _ + 'struct*', $tJobObjectInfo, 'dword', DllStructGetSize($tJobObjectInfo), 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[5] +EndFunc ;==>_WinAPI_QueryInformationJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_ReleaseMutex($hMutex) + Local $aRet = DllCall('kernel32.dll', 'bool', 'ReleaseMutex', 'handle', $hMutex) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_ReleaseMutex + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_ReleaseSemaphore($hSemaphore, $iIncrease = 1) + Local $aRet = DllCall('kernel32.dll', 'bool', 'ReleaseSemaphore', 'handle', $hSemaphore, 'long', $iIncrease, 'long*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $aRet[3] +EndFunc ;==>_WinAPI_ReleaseSemaphore + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_ResetEvent($hEvent) + Local $aRet = DllCall('kernel32.dll', 'bool', 'ResetEvent', 'handle', $hEvent) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_ResetEvent + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_SetInformationJobObject($hJob, $iJobObjectInfoClass, $tJobObjectInfo) + Local $aRet = DllCall('kernel32.dll', 'bool', 'SetInformationJobObject', 'handle', $hJob, 'int', $iJobObjectInfoClass, _ + 'struct*', $tJobObjectInfo, 'dword', DllStructGetSize($tJobObjectInfo)) + If @error Then Return SetError(@error, @extended, False) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_SetInformationJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: KaFu +; Modified.......: Yashied, Jpm +; =============================================================================================================================== +Func _WinAPI_SetPriorityClass($iPriority, $iPID = 0) + If Not $iPID Then $iPID = @AutoItPID + + Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000600, 0x00001200), _ + 'bool', 0, 'dword', $iPID) + If @error Or Not $hProcess[0] Then Return SetError(@error + 10, @extended, 0) + ; If Not $hProcess[0] Then Return SetError(1000, 0, 0) + + Local $iError = 0 + Local $aRet = DllCall('kernel32.dll', 'bool', 'SetPriorityClass', 'handle', $hProcess[0], 'dword', $iPriority) + If @error Then $iError = @error + DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess[0]) + If $iError Then Return SetError($iError, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_SetPriorityClass + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_SetThreadDesktop($hDesktop) + Local $aRet = DllCall('user32.dll', 'bool', 'SetThreadDesktop', 'handle', $hDesktop) + If @error Then Return SetError(@error, @extended, False) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_SetThreadDesktop + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: jpm +; =============================================================================================================================== +Func _WinAPI_SetThreadErrorMode($iMode) + Local $aRet = DllCall('kernel32.dll', 'bool', 'SetThreadErrorMode', 'dword', $iMode, 'dword*', 0) + If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) + + Return $aRet[2] +EndFunc ;==>_WinAPI_SetThreadErrorMode + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_SetThreadExecutionState($iFlags) + Local $aRet = DllCall('kernel32.dll', 'dword', 'SetThreadExecutionState', 'dword', $iFlags) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_SetThreadExecutionState + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_TerminateJobObject($hJob, $iExitCode = 0) + Local $aRet = DllCall('kernel32.dll', 'bool', 'TerminateJobObject', 'handle', $hJob, 'uint', $iExitCode) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_TerminateJobObject + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_TerminateProcess($hProcess, $iExitCode = 0) + Local $aRet = DllCall('kernel32.dll', 'bool', 'TerminateProcess', 'handle', $hProcess, 'uint', $iExitCode) + If @error Then Return SetError(@error, @extended, 0) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_TerminateProcess + +; #FUNCTION# ==================================================================================================================== +; Author.........: Yashied +; Modified.......: Jpm +; =============================================================================================================================== +Func _WinAPI_UserHandleGrantAccess($hObject, $hJob, $bGrant) + Local $aRet = DllCall('kernel32.dll', 'bool', 'UserHandleGrantAccess', 'handle', $hObject, 'handle', $hJob, 'bool', $bGrant) + If @error Then Return SetError(@error, @extended, False) + ; If Not $aRet[0] Then Return SetError(1000, 0, 0) + + Return $aRet[0] +EndFunc ;==>_WinAPI_UserHandleGrantAccess + +#EndRegion Public Functions diff --git a/src/include/WindowsConstants.au3 b/src/include/WindowsConstants.au3 new file mode 100644 index 0000000..f78ee04 --- /dev/null +++ b/src/include/WindowsConstants.au3 @@ -0,0 +1,819 @@ +#include-once + +; #INDEX# ======================================================================================================================= +; Title .........: Windows_Constants +; AutoIt Version : 3.3.14.2 +; Language ......: English +; Description ...: GUI control Windows styles and much more constants. +; Author(s) .....: Valik, Gary Frost, ... +; =============================================================================================================================== + +; #CONSTANTS# =================================================================================================================== + +; Window Classes +Global Const $WC_ANIMATE = 'SysAnimate32' +Global Const $WC_BUTTON = 'Button' +Global Const $WC_COMBOBOX = 'ComboBox' +Global Const $WC_COMBOBOXEX = 'ComboBoxEx32' +Global Const $WC_DATETIMEPICK = 'SysDateTimePick32' +Global Const $WC_EDIT = 'Edit' +Global Const $WC_HEADER = 'SysHeader32' +Global Const $WC_HOTKEY = 'msctls_hotkey32' +Global Const $WC_IPADDRESS = 'SysIPAddress32' +Global Const $WC_LINK = 'SysLink' +Global Const $WC_LISTBOX = 'ListBox' +Global Const $WC_LISTVIEW = 'SysListView32' +Global Const $WC_MONTHCAL = 'SysMonthCal32' +Global Const $WC_NATIVEFONTCTL = 'NativeFontCtl' +Global Const $WC_PAGESCROLLER = 'SysPager' +Global Const $WC_PROGRESS = 'msctls_progress32' +Global Const $WC_REBAR = 'ReBarWindow32' +Global Const $WC_SCROLLBAR = 'ScrollBar' +Global Const $WC_STATIC = 'Static' +Global Const $WC_STATUSBAR = 'msctls_statusbar32' +Global Const $WC_TABCONTROL = 'SysTabControl32' +Global Const $WC_TOOLBAR = 'ToolbarWindow32' +Global Const $WC_TOOLTIPS = 'tooltips_class32' +Global Const $WC_TRACKBAR = 'msctls_trackbar32' +Global Const $WC_TREEVIEW = 'SysTreeView32' +Global Const $WC_UPDOWN = 'msctls_updown32' + +; Window Styles +Global Const $WS_OVERLAPPED = 0 +Global Const $WS_TILED = $WS_OVERLAPPED +Global Const $WS_MAXIMIZEBOX = 0x00010000 +Global Const $WS_MINIMIZEBOX = 0x00020000 +Global Const $WS_TABSTOP = 0x00010000 +Global Const $WS_GROUP = 0x00020000 +Global Const $WS_SIZEBOX = 0x00040000 +Global Const $WS_THICKFRAME = $WS_SIZEBOX +Global Const $WS_SYSMENU = 0x00080000 +Global Const $WS_HSCROLL = 0x00100000 +Global Const $WS_VSCROLL = 0x00200000 +Global Const $WS_DLGFRAME = 0x00400000 +Global Const $WS_BORDER = 0x00800000 +Global Const $WS_CAPTION = 0x00C00000 +Global Const $WS_OVERLAPPEDWINDOW = BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_OVERLAPPED, $WS_SYSMENU, $WS_THICKFRAME) +Global Const $WS_TILEDWINDOW = $WS_OVERLAPPEDWINDOW +Global Const $WS_MAXIMIZE = 0x01000000 +Global Const $WS_CLIPCHILDREN = 0x02000000 +Global Const $WS_CLIPSIBLINGS = 0x04000000 +Global Const $WS_DISABLED = 0x08000000 +Global Const $WS_VISIBLE = 0x10000000 +Global Const $WS_MINIMIZE = 0x20000000 +Global Const $WS_ICONIC = $WS_MINIMIZE +Global Const $WS_CHILD = 0x40000000 +Global Const $WS_CHILDWINDOW = $WS_CHILD +Global Const $WS_POPUP = 0x80000000 +Global Const $WS_POPUPWINDOW = 0x80880000 + +; Dialog Styles +Global Const $DS_3DLOOK = 0x0004 +Global Const $DS_ABSALIGN = 0x0001 +Global Const $DS_CENTER = 0x0800 +Global Const $DS_CENTERMOUSE = 0x1000 +Global Const $DS_CONTEXTHELP = 0x2000 +Global Const $DS_CONTROL = 0x0400 +Global Const $DS_FIXEDSYS = 0x0008 +Global Const $DS_LOCALEDIT = 0x0020 +Global Const $DS_MODALFRAME = 0x0080 +Global Const $DS_NOFAILCREATE = 0x0010 +Global Const $DS_NOIDLEMSG = 0x0100 +Global Const $DS_SETFONT = 0x0040 +Global Const $DS_SETFOREGROUND = 0x0200 +Global Const $DS_SHELLFONT = BitOR($DS_FIXEDSYS, $DS_SETFONT) +Global Const $DS_SYSMODAL = 0x0002 + +; Window Extended Styles +Global Const $WS_EX_ACCEPTFILES = 0x00000010 +Global Const $WS_EX_APPWINDOW = 0x00040000 +Global Const $WS_EX_COMPOSITED = 0x02000000 +Global Const $WS_EX_CONTROLPARENT = 0x10000 +Global Const $WS_EX_CLIENTEDGE = 0x00000200 +Global Const $WS_EX_CONTEXTHELP = 0x00000400 +Global Const $WS_EX_DLGMODALFRAME = 0x00000001 +Global Const $WS_EX_LAYERED = 0x00080000 +Global Const $WS_EX_LAYOUTRTL = 0x400000 +Global Const $WS_EX_LEFT = 0x00000000 +Global Const $WS_EX_LEFTSCROLLBAR = 0x00004000 +Global Const $WS_EX_LTRREADING = 0x00000000 +Global Const $WS_EX_MDICHILD = 0x00000040 +Global Const $WS_EX_NOACTIVATE = 0x08000000 +Global Const $WS_EX_NOINHERITLAYOUT = 0x00100000 +Global Const $WS_EX_NOPARENTNOTIFY = 0x00000004 +Global Const $WS_EX_RIGHT = 0x00001000 +Global Const $WS_EX_RIGHTSCROLLBAR = 0x00000000 +Global Const $WS_EX_RTLREADING = 0x2000 +Global Const $WS_EX_STATICEDGE = 0x00020000 +Global Const $WS_EX_TOOLWINDOW = 0x00000080 +Global Const $WS_EX_TOPMOST = 0x00000008 +Global Const $WS_EX_TRANSPARENT = 0x00000020 +Global Const $WS_EX_WINDOWEDGE = 0x00000100 + +Global Const $WS_EX_OVERLAPPEDWINDOW = BitOR($WS_EX_CLIENTEDGE, $WS_EX_WINDOWEDGE) +Global Const $WS_EX_PALETTEWINDOW = BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE) + +; Messages +Global Const $WM_NULL = 0x0000 +Global Const $WM_CREATE = 0x0001 +Global Const $WM_DESTROY = 0x0002 +Global Const $WM_MOVE = 0x0003 +Global Const $WM_SIZEWAIT = 0x0004 +Global Const $WM_SIZE = 0x0005 +Global Const $WM_ACTIVATE = 0x0006 +Global Const $WM_SETFOCUS = 0x0007 +Global Const $WM_KILLFOCUS = 0x0008 +Global Const $WM_SETVISIBLE = 0x0009 +Global Const $WM_ENABLE = 0x000A +Global Const $WM_SETREDRAW = 0x000B +Global Const $WM_SETTEXT = 0x000C +Global Const $WM_GETTEXT = 0x000D +Global Const $WM_GETTEXTLENGTH = 0x000E +Global Const $WM_PAINT = 0x000F +Global Const $WM_CLOSE = 0x0010 +Global Const $WM_QUERYENDSESSION = 0x0011 +Global Const $WM_QUIT = 0x0012 +Global Const $WM_ERASEBKGND = 0x0014 +Global Const $WM_QUERYOPEN = 0x0013 +Global Const $WM_SYSCOLORCHANGE = 0x0015 +Global Const $WM_ENDSESSION = 0x0016 +Global Const $WM_SYSTEMERROR = 0x0017 +Global Const $WM_SHOWWINDOW = 0x0018 +Global Const $WM_CTLCOLOR = 0x0019 +Global Const $WM_SETTINGCHANGE = 0x001A +Global Const $WM_WININICHANGE = 0x001A +Global Const $WM_DEVMODECHANGE = 0x001B +Global Const $WM_ACTIVATEAPP = 0x001C +Global Const $WM_FONTCHANGE = 0x001D +Global Const $WM_TIMECHANGE = 0x001E +Global Const $WM_CANCELMODE = 0x001F +Global Const $WM_SETCURSOR = 0x0020 +Global Const $WM_MOUSEACTIVATE = 0x0021 +Global Const $WM_CHILDACTIVATE = 0x0022 +Global Const $WM_QUEUESYNC = 0x0023 +Global Const $WM_GETMINMAXINFO = 0x0024 +Global Const $WM_LOGOFF = 0x0025 +Global Const $WM_PAINTICON = 0x0026 +Global Const $WM_ICONERASEBKGND = 0x0027 +Global Const $WM_NEXTDLGCTL = 0x0028 +Global Const $WM_ALTTABACTIVE = 0x0029 +Global Const $WM_SPOOLERSTATUS = 0x002A +Global Const $WM_DRAWITEM = 0x002B +Global Const $WM_MEASUREITEM = 0x002C +Global Const $WM_DELETEITEM = 0x002D +Global Const $WM_VKEYTOITEM = 0x002E +Global Const $WM_CHARTOITEM = 0x002F +Global Const $WM_SETFONT = 0x0030 +Global Const $WM_GETFONT = 0x0031 +Global Const $WM_SETHOTKEY = 0x0032 +Global Const $WM_GETHOTKEY = 0x0033 +Global Const $WM_FILESYSCHANGE = 0x0034 +Global Const $WM_ISACTIVEICON = 0x0035 +Global Const $WM_QUERYPARKICON = 0x0036 +Global Const $WM_QUERYDRAGICON = 0x0037 +Global Const $WM_WINHELP = 0x0038 +Global Const $WM_COMPAREITEM = 0x0039 +Global Const $WM_FULLSCREEN = 0x003A +Global Const $WM_CLIENTSHUTDOWN = 0x003B +Global Const $WM_DDEMLEVENT = 0x003C +Global Const $WM_GETOBJECT = 0x003D +Global Const $WM_CALCSCROLL = 0x003F +Global Const $WM_TESTING = 0x0040 +Global Const $WM_COMPACTING = 0x0041 +Global Const $WM_OTHERWINDOWCREATED = 0x0042 +Global Const $WM_OTHERWINDOWDESTROYED = 0x0043 +Global Const $WM_COMMNOTIFY = 0x0044 +Global Const $WM_MEDIASTATUSCHANGE = 0x0045 +Global Const $WM_WINDOWPOSCHANGING = 0x0046 +Global Const $WM_WINDOWPOSCHANGED = 0x0047 +Global Const $WM_POWER = 0x0048 +Global Const $WM_COPYGLOBALDATA = 0x0049 +Global Const $WM_COPYDATA = 0x004A +Global Const $WM_CANCELJOURNAL = 0x004B +Global Const $WM_LOGONNOTIFY = 0x004C +Global Const $WM_KEYF1 = 0x004D +Global Const $WM_NOTIFY = 0x004E +Global Const $WM_ACCESS_WINDOW = 0x004F +Global Const $WM_INPUTLANGCHANGEREQUEST = 0x0050 +Global Const $WM_INPUTLANGCHANGE = 0x0051 +Global Const $WM_TCARD = 0x0052 +Global Const $WM_HELP = 0x0053 +Global Const $WM_USERCHANGED = 0x0054 +Global Const $WM_NOTIFYFORMAT = 0x0055 + +Global Const $WM_QM_ACTIVATE = 0x0060 +Global Const $WM_HOOK_DO_CALLBACK = 0x0061 +Global Const $WM_SYSCOPYDATA = 0x0062 + +Global Const $WM_FINALDESTROY = 0x0070 +Global Const $WM_MEASUREITEM_CLIENTDATA = 0x0071 + +Global Const $WM_CONTEXTMENU = 0x007B +Global Const $WM_STYLECHANGING = 0x007C +Global Const $WM_STYLECHANGED = 0x007D +Global Const $WM_DISPLAYCHANGE = 0x007E +Global Const $WM_GETICON = 0x007F +Global Const $WM_SETICON = 0x0080 +Global Const $WM_NCCREATE = 0x0081 +Global Const $WM_NCDESTROY = 0x0082 +Global Const $WM_NCCALCSIZE = 0x0083 +Global Const $WM_NCHITTEST = 0x0084 +Global Const $WM_NCPAINT = 0x0085 +Global Const $WM_NCACTIVATE = 0x0086 +Global Const $WM_GETDLGCODE = 0x0087 +Global Const $WM_SYNCPAINT = 0x0088 +Global Const $WM_SYNCTASK = 0x0089 +Global Const $WM_KLUDGEMINRECT = 0x008B +Global Const $WM_LPKDRAWSWITCHWND = 0x008C +Global Const $WM_UAHDESTROYWINDOW = 0x0090 +Global Const $WM_UAHDRAWMENU = 0x0091 +Global Const $WM_UAHDRAWMENUITEM = 0x0092 +Global Const $WM_UAHINITMENU = 0x0093 +Global Const $WM_UAHMEASUREMENUITEM = 0x0094 +Global Const $WM_UAHNCPAINTMENUPOPUP = 0x0095 + +Global Const $WM_NCMOUSEMOVE = 0x00A0 +Global Const $WM_NCLBUTTONDOWN = 0x00A1 +Global Const $WM_NCLBUTTONUP = 0x00A2 +Global Const $WM_NCLBUTTONDBLCLK = 0x00A3 +Global Const $WM_NCRBUTTONDOWN = 0x00A4 +Global Const $WM_NCRBUTTONUP = 0x00A5 +Global Const $WM_NCRBUTTONDBLCLK = 0x00A6 +Global Const $WM_NCMBUTTONDOWN = 0x00A7 +Global Const $WM_NCMBUTTONUP = 0x00A8 +Global Const $WM_NCMBUTTONDBLCLK = 0x00A9 +Global Const $WM_NCXBUTTONDOWN = 0x00AB +Global Const $WM_NCXBUTTONUP = 0x00AC +Global Const $WM_NCXBUTTONDBLCLK = 0x00AD +Global Const $WM_NCUAHDRAWCAPTION = 0x00AE +Global Const $WM_NCUAHDRAWFRAME = 0x00AF +Global Const $WM_INPUT_DEVICE_CHANGE = 0x00FE +Global Const $WM_INPUT = 0x00FF + +Global Const $WM_KEYDOWN = 0x0100 +Global Const $WM_KEYFIRST = 0x0100 +Global Const $WM_KEYUP = 0x0101 +Global Const $WM_CHAR = 0x0102 +Global Const $WM_DEADCHAR = 0x0103 +Global Const $WM_SYSKEYDOWN = 0x0104 +Global Const $WM_SYSKEYUP = 0x0105 +Global Const $WM_SYSCHAR = 0x0106 +Global Const $WM_SYSDEADCHAR = 0x0107 +Global Const $WM_YOMICHAR = 0x0108 +Global Const $WM_KEYLAST = 0x0109 +Global Const $WM_UNICHAR = 0x0109 +Global Const $WM_CONVERTREQUEST = 0x010A +Global Const $WM_CONVERTRESULT = 0x010B +Global Const $WM_IM_INFO = 0x010C +Global Const $WM_IME_STARTCOMPOSITION = 0x010D +Global Const $WM_IME_ENDCOMPOSITION = 0x010E +Global Const $WM_IME_COMPOSITION = 0x010F +Global Const $WM_IME_KEYLAST = 0x010F +Global Const $WM_INITDIALOG = 0x0110 +Global Const $WM_COMMAND = 0x0111 +Global Const $WM_SYSCOMMAND = 0x0112 +Global Const $WM_TIMER = 0x0113 +Global Const $WM_HSCROLL = 0x0114 +Global Const $WM_VSCROLL = 0x0115 +Global Const $WM_INITMENU = 0x0116 +Global Const $WM_INITMENUPOPUP = 0x0117 +Global Const $WM_SYSTIMER = 0x0118 +Global Const $WM_GESTURE = 0x0119 +Global Const $WM_GESTURENOTIFY = 0x011A +Global Const $WM_GESTUREINPUT = 0x011B +Global Const $WM_GESTURENOTIFIED = 0x011C +Global Const $WM_MENUSELECT = 0x011F +Global Const $WM_MENUCHAR = 0x0120 +Global Const $WM_ENTERIDLE = 0x0121 +Global Const $WM_MENURBUTTONUP = 0x0122 +Global Const $WM_MENUDRAG = 0x0123 +Global Const $WM_MENUGETOBJECT = 0x0124 +Global Const $WM_UNINITMENUPOPUP = 0x0125 +Global Const $WM_MENUCOMMAND = 0x0126 +Global Const $WM_CHANGEUISTATE = 0x0127 +Global Const $WM_UPDATEUISTATE = 0x0128 +Global Const $WM_QUERYUISTATE = 0x0129 +Global Const $WM_LBTRACKPOINT = 0x0131 +Global Const $WM_CTLCOLORMSGBOX = 0x0132 +Global Const $WM_CTLCOLOREDIT = 0x0133 +Global Const $WM_CTLCOLORLISTBOX = 0x0134 +Global Const $WM_CTLCOLORBTN = 0x0135 +Global Const $WM_CTLCOLORDLG = 0x0136 +Global Const $WM_CTLCOLORSCROLLBAR = 0x0137 +Global Const $WM_CTLCOLORSTATIC = 0x0138 + +Global Const $MN_GETHMENU = 0x01E1 + +Global Const $WM_PARENTNOTIFY = 0x0210 +Global Const $WM_ENTERMENULOOP = 0x0211 +Global Const $WM_EXITMENULOOP = 0x0212 +Global Const $WM_NEXTMENU = 0x0213 +Global Const $WM_SIZING = 0x0214 +Global Const $WM_CAPTURECHANGED = 0x0215 +Global Const $WM_MOVING = 0x0216 +Global Const $WM_POWERBROADCAST = 0x0218 +Global Const $WM_DEVICECHANGE = 0x0219 +Global Const $WM_MDICREATE = 0x0220 +Global Const $WM_MDIDESTROY = 0x0221 +Global Const $WM_MDIACTIVATE = 0x0222 +Global Const $WM_MDIRESTORE = 0x0223 +Global Const $WM_MDINEXT = 0x0224 +Global Const $WM_MDIMAXIMIZE = 0x0225 +Global Const $WM_MDITILE = 0x0226 +Global Const $WM_MDICASCADE = 0x0227 +Global Const $WM_MDIICONARRANGE = 0x0228 +Global Const $WM_MDIGETACTIVE = 0x0229 +Global Const $WM_DROPOBJECT = 0x022A +Global Const $WM_QUERYDROPOBJECT = 0x022B +Global Const $WM_BEGINDRAG = 0x022C +Global Const $WM_DRAGLOOP = 0x022D +Global Const $WM_DRAGSELECT = 0x022E +Global Const $WM_DRAGMOVE = 0x022F +Global Const $WM_MDISETMENU = 0x0230 +Global Const $WM_ENTERSIZEMOVE = 0x0231 +Global Const $WM_EXITSIZEMOVE = 0x0232 +Global Const $WM_DROPFILES = 0x0233 +Global Const $WM_MDIREFRESHMENU = 0x0234 +Global Const $WM_TOUCH = 0x0240 + +Global Const $WM_IME_SETCONTEXT = 0x0281 +Global Const $WM_IME_NOTIFY = 0x0282 +Global Const $WM_IME_CONTROL = 0x0283 +Global Const $WM_IME_COMPOSITIONFULL = 0x0284 +Global Const $WM_IME_SELECT = 0x0285 +Global Const $WM_IME_CHAR = 0x0286 +Global Const $WM_IME_SYSTEM = 0x0287 +Global Const $WM_IME_REQUEST = 0x0288 +Global Const $WM_IME_KEYDOWN = 0x0290 +Global Const $WM_IME_KEYUP = 0x0291 +Global Const $WM_NCMOUSEHOVER = 0x02A0 +Global Const $WM_MOUSEHOVER = 0x02A1 +Global Const $WM_NCMOUSELEAVE = 0x02A2 +Global Const $WM_MOUSELEAVE = 0x02A3 +Global Const $WM_WTSSESSION_CHANGE = 0x02B1 +Global Const $WM_TABLET_FIRST = 0x02C0 +Global Const $WM_TABLET_LAST = 0x02DF + +Global Const $WM_CUT = 0x0300 +Global Const $WM_COPY = 0x0301 +Global Const $WM_PASTE = 0x0302 +Global Const $WM_CLEAR = 0x0303 +Global Const $WM_UNDO = 0x0304 +Global Const $WM_PALETTEISCHANGING = 0x0310 +Global Const $WM_HOTKEY = 0x0312 +Global Const $WM_PALETTECHANGED = 0x0311 +Global Const $WM_SYSMENU = 0x0313 +Global Const $WM_HOOKMSG = 0x0314 +Global Const $WM_EXITPROCESS = 0x0315 +Global Const $WM_WAKETHREAD = 0x0316 +Global Const $WM_PRINT = 0x0317 +Global Const $WM_PRINTCLIENT = 0x0318 +Global Const $WM_APPCOMMAND = 0x0319 +Global Const $WM_QUERYNEWPALETTE = 0x030F +Global Const $WM_THEMECHANGED = 0x031A +Global Const $WM_UAHINIT = 0x031B +Global Const $WM_DESKTOPNOTIFY = 0x031C +Global Const $WM_CLIPBOARDUPDATE = 0x031D +Global Const $WM_DWMCOMPOSITIONCHANGED = 0x031E +Global Const $WM_DWMNCRENDERINGCHANGED = 0x031F +Global Const $WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320 +Global Const $WM_DWMWINDOWMAXIMIZEDCHANGE = 0x0321 +Global Const $WM_DWMEXILEFRAME = 0x0322 +Global Const $WM_DWMSENDICONICTHUMBNAIL = 0x0323 +Global Const $WM_MAGNIFICATION_STARTED = 0x0324 +Global Const $WM_MAGNIFICATION_ENDED = 0x0325 +Global Const $WM_DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326 +Global Const $WM_DWMTHUMBNAILSIZECHANGED = 0x0327 +Global Const $WM_MAGNIFICATION_OUTPUT = 0x0328 +Global Const $WM_MEASURECONTROL = 0x0330 +Global Const $WM_GETACTIONTEXT = 0x0331 +Global Const $WM_FORWARDKEYDOWN = 0x0333 +Global Const $WM_FORWARDKEYUP = 0x0334 +Global Const $WM_GETTITLEBARINFOEX = 0x033F +Global Const $WM_NOTIFYWOW = 0x0340 +Global Const $WM_HANDHELDFIRST = 0x0358 +Global Const $WM_HANDHELDLAST = 0x035F +Global Const $WM_AFXFIRST = 0x0360 +Global Const $WM_AFXLAST = 0x037F +Global Const $WM_PENWINFIRST = 0x0380 +Global Const $WM_PENWINLAST = 0x038F +Global Const $WM_DDE_INITIATE = 0x03E0 +Global Const $WM_DDE_TERMINATE = 0x03E1 +Global Const $WM_DDE_ADVISE = 0x03E2 +Global Const $WM_DDE_UNADVISE = 0x03E3 +Global Const $WM_DDE_ACK = 0x03E4 +Global Const $WM_DDE_DATA = 0x03E5 +Global Const $WM_DDE_REQUEST = 0x03E6 +Global Const $WM_DDE_POKE = 0x03E7 +Global Const $WM_DDE_EXECUTE = 0x03E8 +Global Const $WM_DBNOTIFICATION = 0x03FD +Global Const $WM_NETCONNECT = 0x03FE +Global Const $WM_HIBERNATE = 0x03FF + +Global Const $WM_USER = 0x0400 + +Global Const $WM_APP = 0x8000 + +; Windows Notification Message Constants +Global Const $NM_FIRST = 0 + +Global Const $NM_OUTOFMEMORY = $NM_FIRST - 1 +Global Const $NM_CLICK = $NM_FIRST - 2 +Global Const $NM_DBLCLK = $NM_FIRST - 3 +Global Const $NM_RETURN = $NM_FIRST - 4 +Global Const $NM_RCLICK = $NM_FIRST - 5 +Global Const $NM_RDBLCLK = $NM_FIRST - 6 +Global Const $NM_SETFOCUS = $NM_FIRST - 7 +Global Const $NM_KILLFOCUS = $NM_FIRST - 8 +Global Const $NM_CUSTOMDRAW = $NM_FIRST - 12 +Global Const $NM_HOVER = $NM_FIRST - 13 +Global Const $NM_NCHITTEST = $NM_FIRST - 14 +Global Const $NM_KEYDOWN = $NM_FIRST - 15 +Global Const $NM_RELEASEDCAPTURE = $NM_FIRST - 16 +Global Const $NM_SETCURSOR = $NM_FIRST - 17 +Global Const $NM_CHAR = $NM_FIRST - 18 +Global Const $NM_TOOLTIPSCREATED = $NM_FIRST - 19 +Global Const $NM_LDOWN = $NM_FIRST - 20 +Global Const $NM_RDOWN = $NM_FIRST - 21 +Global Const $NM_THEMECHANGED = $NM_FIRST - 22 + +Global Const $WM_MOUSEFIRST = 0x0200 +Global Const $WM_MOUSEMOVE = 0x0200 +Global Const $WM_LBUTTONDOWN = 0x0201 +Global Const $WM_LBUTTONUP = 0x0202 +Global Const $WM_LBUTTONDBLCLK = 0x0203 +Global Const $WM_RBUTTONDOWN = 0x0204 +Global Const $WM_RBUTTONUP = 0x0205 +Global Const $WM_RBUTTONDBLCLK = 0x0206 +Global Const $WM_MBUTTONDOWN = 0x0207 +Global Const $WM_MBUTTONUP = 0x0208 +Global Const $WM_MBUTTONDBLCLK = 0x0209 +Global Const $WM_MOUSEWHEEL = 0x020A +Global Const $WM_XBUTTONDOWN = 0x020B +Global Const $WM_XBUTTONUP = 0x020C +Global Const $WM_XBUTTONDBLCLK = 0x020D +Global Const $WM_MOUSEHWHEEL = 0x020E + +; Pen styles +Global Const $PS_SOLID = 0 +Global Const $PS_DASH = 1 +Global Const $PS_DOT = 2 +Global Const $PS_DASHDOT = 3 +Global Const $PS_DASHDOTDOT = 4 +Global Const $PS_NULL = 5 +Global Const $PS_INSIDEFRAME = 6 +Global Const $PS_USERSTYLE = 7 +Global Const $PS_ALTERNATE = 8 + +Global Const $PS_ENDCAP_ROUND = 0x00000000 +Global Const $PS_ENDCAP_SQUARE = 0x00000100 +Global Const $PS_ENDCAP_FLAT = 0x00000200 + +Global Const $PS_JOIN_BEVEL = 0x00001000 +Global Const $PS_JOIN_MITER = 0x00002000 +Global Const $PS_JOIN_ROUND = 0x00000000 + +Global Const $PS_GEOMETRIC = 0x00010000 +Global Const $PS_COSMETIC = 0x00000000 + +; Layered attributes Constants +Global Const $LWA_ALPHA = 0x2 +Global Const $LWA_COLORKEY = 0x1 + +; Region's combine modes Constants +Global Const $RGN_AND = 1 +Global Const $RGN_OR = 2 +Global Const $RGN_XOR = 3 +Global Const $RGN_DIFF = 4 +Global Const $RGN_COPY = 5 + +; Type of the resulting region from region's combine +Global Const $ERRORREGION = 0 +Global Const $NULLREGION = 1 +Global Const $SIMPLEREGION = 2 +Global Const $COMPLEXREGION = 3 + +; Background mix modes +Global Const $TRANSPARENT = 1 +Global Const $OPAQUE = 2 + +; Common Control Messages + +; Messages to send to controls +Global Const $CCM_FIRST = 0x2000 +Global Const $CCM_GETUNICODEFORMAT = ($CCM_FIRST + 6) +Global Const $CCM_SETUNICODEFORMAT = ($CCM_FIRST + 5) +Global Const $CCM_SETBKCOLOR = $CCM_FIRST + 1 +Global Const $CCM_SETCOLORSCHEME = $CCM_FIRST + 2 +Global Const $CCM_GETCOLORSCHEME = $CCM_FIRST + 3 +Global Const $CCM_GETDROPTARGET = $CCM_FIRST + 4 +Global Const $CCM_SETWINDOWTHEME = $CCM_FIRST + 11 + +; GetAncestor Constants +Global Const $GA_PARENT = 1 +Global Const $GA_ROOT = 2 +Global Const $GA_ROOTOWNER = 3 + +; GetSystemMetrics Constants +Global Const $SM_CXSCREEN = 0 +Global Const $SM_CYSCREEN = 1 +Global Const $SM_CXVSCROLL = 2 +Global Const $SM_CYHSCROLL = 3 +Global Const $SM_CYCAPTION = 4 +Global Const $SM_CXBORDER = 5 +Global Const $SM_CYBORDER = 6 +Global Const $SM_CXDLGFRAME = 7 +Global Const $SM_CYDLGFRAME = 8 +Global Const $SM_CYVTHUMB = 9 +Global Const $SM_CXHTHUMB = 10 +Global Const $SM_CXICON = 11 +Global Const $SM_CYICON = 12 +Global Const $SM_CXCURSOR = 13 +Global Const $SM_CYCURSOR = 14 +Global Const $SM_CYMENU = 15 +Global Const $SM_CXFULLSCREEN = 16 +Global Const $SM_CYFULLSCREEN = 17 +Global Const $SM_CYKANJIWINDOW = 18 +Global Const $SM_MOUSEPRESENT = 19 +Global Const $SM_CYVSCROLL = 20 +Global Const $SM_CXHSCROLL = 21 +Global Const $SM_DEBUG = 22 +Global Const $SM_SWAPBUTTON = 23 +Global Const $SM_RESERVED1 = 24 +Global Const $SM_RESERVED2 = 25 +Global Const $SM_RESERVED3 = 26 +Global Const $SM_RESERVED4 = 27 +Global Const $SM_CXMIN = 28 +Global Const $SM_CYMIN = 29 +Global Const $SM_CXSIZE = 30 +Global Const $SM_CYSIZE = 31 +Global Const $SM_CXFRAME = 32 +Global Const $SM_CYFRAME = 33 +Global Const $SM_CXMINTRACK = 34 +Global Const $SM_CYMINTRACK = 35 +Global Const $SM_CXDOUBLECLK = 36 +Global Const $SM_CYDOUBLECLK = 37 +Global Const $SM_CXICONSPACING = 38 +Global Const $SM_CYICONSPACING = 39 +Global Const $SM_MENUDROPALIGNMENT = 40 +Global Const $SM_PENWINDOWS = 41 +Global Const $SM_DBCSENABLED = 42 +Global Const $SM_CMOUSEBUTTONS = 43 +Global Const $SM_SECURE = 44 +Global Const $SM_CXEDGE = 45 +Global Const $SM_CYEDGE = 46 +Global Const $SM_CXMINSPACING = 47 +Global Const $SM_CYMINSPACING = 48 +Global Const $SM_CXSMICON = 49 +Global Const $SM_CYSMICON = 50 +Global Const $SM_CYSMCAPTION = 51 +Global Const $SM_CXSMSIZE = 52 +Global Const $SM_CYSMSIZE = 53 +Global Const $SM_CXMENUSIZE = 54 +Global Const $SM_CYMENUSIZE = 55 +Global Const $SM_ARRANGE = 56 +Global Const $SM_CXMINIMIZED = 57 +Global Const $SM_CYMINIMIZED = 58 +Global Const $SM_CXMAXTRACK = 59 +Global Const $SM_CYMAXTRACK = 60 +Global Const $SM_CXMAXIMIZED = 61 +Global Const $SM_CYMAXIMIZED = 62 +Global Const $SM_NETWORK = 63 +Global Const $SM_CLEANBOOT = 67 +Global Const $SM_CXDRAG = 68 +Global Const $SM_CYDRAG = 69 +Global Const $SM_SHOWSOUNDS = 70 +Global Const $SM_CXMENUCHECK = 71 +Global Const $SM_CYMENUCHECK = 72 +Global Const $SM_SLOWMACHINE = 73 +Global Const $SM_MIDEASTENABLED = 74 +Global Const $SM_MOUSEWHEELPRESENT = 75 +Global Const $SM_XVIRTUALSCREEN = 76 +Global Const $SM_YVIRTUALSCREEN = 77 +Global Const $SM_CXVIRTUALSCREEN = 78 +Global Const $SM_CYVIRTUALSCREEN = 79 +Global Const $SM_CMONITORS = 80 +Global Const $SM_SAMEDISPLAYFORMAT = 81 +Global Const $SM_IMMENABLED = 82 +Global Const $SM_CXFOCUSBORDER = 83 +Global Const $SM_CYFOCUSBORDER = 84 +Global Const $SM_TABLETPC = 86 +Global Const $SM_MEDIACENTER = 87 +Global Const $SM_STARTER = 88 +Global Const $SM_SERVERR2 = 89 +Global Const $SM_CMETRICS = 90 + +Global Const $SM_REMOTESESSION = 0x1000 +Global Const $SM_SHUTTINGDOWN = 0x2000 +Global Const $SM_REMOTECONTROL = 0x2001 +Global Const $SM_CARETBLINKINGENABLED = 0x2002 + +; Ternary raster operations +Global Const $BLACKNESS = 0x00000042 ; Fills the destination rectangle using the color associated with index 0 in the physical palette +Global Const $CAPTUREBLT = 0X40000000 ; Includes any window that are layered on top of your window in the resulting image +Global Const $DSTINVERT = 0x00550009 ; Inverts the destination rectangle +Global Const $MERGECOPY = 0x00C000CA ; Copies the inverted source rectangle to the destination +Global Const $MERGEPAINT = 0x00BB0226 ; Merges the color of the inverted source rectangle with the colors of the destination rectangle by using the OR operator +Global Const $NOMIRRORBITMAP = 0X80000000 ; Prevents the bitmap from being mirrored +Global Const $NOTSRCCOPY = 0x00330008 ; Copies the inverted source rectangle to the destination +Global Const $NOTSRCERASE = 0x001100A6 ; Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color +Global Const $PATCOPY = 0x00F00021 ; Copies the brush selected in hdcDest, into the destination bitmap +Global Const $PATINVERT = 0x005A0049 ; Combines the colors of the brush currently selected in hDest, with the colors of the destination rectangle by using the XOR operator +Global Const $PATPAINT = 0x00FB0A09 ; Combines the colors of the brush currently selected in hDest, with the colors of the inverted source rectangle by using the OR operator +Global Const $SRCAND = 0x008800C6 ; Combines the colors of the source and destination rectangles by using the Boolean AND operator +Global Const $SRCCOPY = 0x00CC0020 ; Copies the source rectangle directly to the destination rectangle +Global Const $SRCERASE = 0x00440328 ; Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator +Global Const $SRCINVERT = 0x00660046 ; Combines the colors of the source and destination rectangles by using the Boolean XOR operator +Global Const $SRCPAINT = 0x00EE0086 ; Combines the colors of the source and destination rectangles by using the Boolean OR operator +Global Const $WHITENESS = 0x00FF0062 ; Fills the destination rectangle using the color associated with index 1 in the physical palette + +; DrawText Constants +Global Const $DT_BOTTOM = 0x8 +Global Const $DT_CALCRECT = 0x400 +Global Const $DT_CENTER = 0x1 +Global Const $DT_EDITCONTROL = 0x2000 +Global Const $DT_END_ELLIPSIS = 0x8000 +Global Const $DT_EXPANDTABS = 0x40 +Global Const $DT_EXTERNALLEADING = 0x200 +Global Const $DT_HIDEPREFIX = 0x100000 +Global Const $DT_INTERNAL = 0x1000 +Global Const $DT_LEFT = 0x0 +Global Const $DT_MODIFYSTRING = 0x10000 +Global Const $DT_NOCLIP = 0x100 +Global Const $DT_NOFULLWIDTHCHARBREAK = 0x80000 +Global Const $DT_NOPREFIX = 0x800 +Global Const $DT_PATH_ELLIPSIS = 0x4000 +Global Const $DT_PREFIXONLY = 0x200000 +Global Const $DT_RIGHT = 0x2 +Global Const $DT_RTLREADING = 0x20000 +Global Const $DT_SINGLELINE = 0x20 +Global Const $DT_TABSTOP = 0x80 +Global Const $DT_TOP = 0x0 +Global Const $DT_VCENTER = 0x4 +Global Const $DT_WORDBREAK = 0x10 +Global Const $DT_WORD_ELLIPSIS = 0x40000 + +; RedrawWindow Constants +Global Const $RDW_ERASE = 0x0004 ; Causes the window to receive a WM_ERASEBKGND message when the window is repainted +Global Const $RDW_FRAME = 0x0400 ; Causes any part of the nonclient area of the window that intersects the update region to receive a WM_NCPAINT message +Global Const $RDW_INTERNALPAINT = 0x0002 ; Causes a WM_PAINT message to be posted to the window regardless of whether any portion of the window is invalid +Global Const $RDW_INVALIDATE = 0x0001 ; Invalidates DllStructGetData($tRECT or $hRegion, "") If both are 0, the entire window is invalidated +Global Const $RDW_NOERASE = 0x0020 ; Suppresses any pending WM_ERASEBKGND messages +Global Const $RDW_NOFRAME = 0x0800 ; Suppresses any pending WM_NCPAINT messages +Global Const $RDW_NOINTERNALPAINT = 0x0010 ; Suppresses any pending internal WM_PAINT messages +Global Const $RDW_VALIDATE = 0x0008 ; Validates Rect or hRegion +Global Const $RDW_ERASENOW = 0x0200 ; Causes the affected windows to receive WM_NCPAINT and WM_ERASEBKGND messages +Global Const $RDW_UPDATENOW = 0x0100 ; Causes the affected windows to receive WM_NCPAINT, WM_ERASEBKGND, and WM_PAINT messages +Global Const $RDW_ALLCHILDREN = 0x0080 ; Includes child windows in the repainting operation +Global Const $RDW_NOCHILDREN = 0x0040 ; Excludes child windows from the repainting operation + +; Clipboard Constants +Global Const $WM_RENDERFORMAT = 0x0305 ; Sent if the owner has delayed rendering a specific clipboard format +Global Const $WM_RENDERALLFORMATS = 0x0306 ; Sent if the owner has delayed rendering clipboard formats +Global Const $WM_DESTROYCLIPBOARD = 0x0307 ; Sent when a call to EmptyClipboard empties the clipboard +Global Const $WM_DRAWCLIPBOARD = 0x0308 ; Sent when the content of the clipboard changes +Global Const $WM_PAINTCLIPBOARD = 0x0309 ; Sent when the clipboard viewer's client area needs repainting +Global Const $WM_VSCROLLCLIPBOARD = 0x030A ; Sent when an event occurs in the viewer's vertical scroll bar +Global Const $WM_SIZECLIPBOARD = 0x030B ; Sent when the clipboard viewer's client area has changed size +Global Const $WM_ASKCBFORMATNAME = 0x030C ; Sent to request the name of a $CF_OWNERDISPLAY clipboard format +Global Const $WM_CHANGECBCHAIN = 0x030D ; Sent when a window is being removed from the chain +Global Const $WM_HSCROLLCLIPBOARD = 0x030E ; Sent when an event occurs in the viewer's horizontal scroll bar + +; WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes +Global Const $HTERROR = -2 +Global Const $HTTRANSPARENT = -1 +Global Const $HTNOWHERE = 0 +Global Const $HTCLIENT = 1 +Global Const $HTCAPTION = 2 +Global Const $HTSYSMENU = 3 +Global Const $HTGROWBOX = 4 +Global Const $HTSIZE = $HTGROWBOX +Global Const $HTMENU = 5 +Global Const $HTHSCROLL = 6 +Global Const $HTVSCROLL = 7 +Global Const $HTMINBUTTON = 8 +Global Const $HTMAXBUTTON = 9 +Global Const $HTLEFT = 10 +Global Const $HTRIGHT = 11 +Global Const $HTTOP = 12 +Global Const $HTTOPLEFT = 13 +Global Const $HTTOPRIGHT = 14 +Global Const $HTBOTTOM = 15 +Global Const $HTBOTTOMLEFT = 16 +Global Const $HTBOTTOMRIGHT = 17 +Global Const $HTBORDER = 18 +Global Const $HTREDUCE = $HTMINBUTTON +Global Const $HTZOOM = $HTMAXBUTTON +Global Const $HTSIZEFIRST = $HTLEFT +Global Const $HTSIZELAST = $HTBOTTOMRIGHT +Global Const $HTOBJECT = 19 +Global Const $HTCLOSE = 20 +Global Const $HTHELP = 21 + +; Windows Color Constants +Global Const $COLOR_SCROLLBAR = 0 +Global Const $COLOR_BACKGROUND = 1 +Global Const $COLOR_ACTIVECAPTION = 2 +Global Const $COLOR_INACTIVECAPTION = 3 +Global Const $COLOR_MENU = 4 +Global Const $COLOR_WINDOW = 5 +Global Const $COLOR_WINDOWFRAME = 6 +Global Const $COLOR_MENUTEXT = 7 +Global Const $COLOR_WINDOWTEXT = 8 +Global Const $COLOR_CAPTIONTEXT = 9 +Global Const $COLOR_ACTIVEBORDER = 10 +Global Const $COLOR_INACTIVEBORDER = 11 +Global Const $COLOR_APPWORKSPACE = 12 +Global Const $COLOR_HIGHLIGHT = 13 +Global Const $COLOR_HIGHLIGHTTEXT = 14 +Global Const $COLOR_BTNFACE = 15 +Global Const $COLOR_BTNSHADOW = 16 +Global Const $COLOR_GRAYTEXT = 17 +Global Const $COLOR_BTNTEXT = 18 +Global Const $COLOR_INACTIVECAPTIONTEXT = 19 +Global Const $COLOR_BTNHIGHLIGHT = 20 +Global Const $COLOR_3DDKSHADOW = 21 +Global Const $COLOR_3DLIGHT = 22 +Global Const $COLOR_INFOTEXT = 23 +Global Const $COLOR_INFOBK = 24 +Global Const $COLOR_HOTLIGHT = 26 +Global Const $COLOR_GRADIENTACTIVECAPTION = 27 +Global Const $COLOR_GRADIENTINACTIVECAPTION = 28 +Global Const $COLOR_MENUHILIGHT = 29 +Global Const $COLOR_MENUBAR = 30 + +Global Const $COLOR_DESKTOP = 1 +Global Const $COLOR_3DFACE = 15 +Global Const $COLOR_3DSHADOW = 16 +Global Const $COLOR_3DHIGHLIGHT = 20 +Global Const $COLOR_3DHILIGHT = 20 +Global Const $COLOR_BTNHILIGHT = 20 + +; Standard Resource Identifier Constants +Global Const $HINST_COMMCTRL = -1 + +Global Const $IDB_STD_SMALL_COLOR = 0 +Global Const $IDB_STD_LARGE_COLOR = 1 +Global Const $IDB_VIEW_SMALL_COLOR = 4 +Global Const $IDB_VIEW_LARGE_COLOR = 5 +Global Const $IDB_HIST_SMALL_COLOR = 8 +Global Const $IDB_HIST_LARGE_COLOR = 9 + +; Flags for $tagSTARTUPINFO structure (Process and Thread structures) +Global Const $STARTF_FORCEOFFFEEDBACK = 0x80 +Global Const $STARTF_FORCEONFEEDBACK = 0x40 +Global Const $STARTF_PREVENTPINNING = 0x00002000 +Global Const $STARTF_RUNFULLSCREEN = 0x20 +Global Const $STARTF_TITLEISAPPID = 0x00001000 +Global Const $STARTF_TITLEISLINKNAME = 0x00000800 +Global Const $STARTF_USECOUNTCHARS = 0x8 +Global Const $STARTF_USEFILLATTRIBUTE = 0x10 +Global Const $STARTF_USEHOTKEY = 0x200 +Global Const $STARTF_USEPOSITION = 0x4 +Global Const $STARTF_USESHOWWINDOW = 0x1 +Global Const $STARTF_USESIZE = 0x2 +Global Const $STARTF_USESTDHANDLES = 0x100 + +; Drawstate Constants +Global Const $CDDS_PREPAINT = 0x00000001 +Global Const $CDDS_POSTPAINT = 0x00000002 +Global Const $CDDS_PREERASE = 0x00000003 +Global Const $CDDS_POSTERASE = 0x00000004 +Global Const $CDDS_ITEM = 0x00010000 +Global Const $CDDS_ITEMPREPAINT = 0x00010001 +Global Const $CDDS_ITEMPOSTPAINT = 0x00010002 +Global Const $CDDS_ITEMPREERASE = 0x00010003 +Global Const $CDDS_ITEMPOSTERASE = 0x00010004 +Global Const $CDDS_SUBITEM = 0x00020000 + +; Itemstate Constants +Global Const $CDIS_SELECTED = 0x0001 +Global Const $CDIS_GRAYED = 0x0002 +Global Const $CDIS_DISABLED = 0x0004 +Global Const $CDIS_CHECKED = 0x0008 +Global Const $CDIS_FOCUS = 0x0010 +Global Const $CDIS_DEFAULT = 0x0020 +Global Const $CDIS_HOT = 0x0040 +Global Const $CDIS_MARKED = 0x0080 +Global Const $CDIS_INDETERMINATE = 0x0100 +Global Const $CDIS_SHOWKEYBOARDCUES = 0x0200 +; The current item state For Vista and above +Global Const $CDIS_NEARHOT = 0x0400 +Global Const $CDIS_OTHERSIDEHOT = 0x0800 +Global Const $CDIS_DROPHILITED = 0x1000 + +; Custom Draw Return Constants +Global Const $CDRF_DODEFAULT = 0x00000000 +Global Const $CDRF_NEWFONT = 0x00000002 +Global Const $CDRF_SKIPDEFAULT = 0x00000004 +Global Const $CDRF_NOTIFYPOSTPAINT = 0x00000010 +Global Const $CDRF_NOTIFYITEMDRAW = 0x00000020 +Global Const $CDRF_NOTIFYSUBITEMDRAW = 0x00000020 +Global Const $CDRF_NOTIFYPOSTERASE = 0x00000040 +; Return Values For Vista and above +Global Const $CDRF_DOERASE = 0x00000008 +Global Const $CDRF_SKIPPOSTPAINT = 0x00000100 + +; Control default styles +Global Const $GUI_SS_DEFAULT_GUI = BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU) +; ===============================================================================================================================