Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/19/2019 in all areas

  1. water

    Task Scheduler

    Version 1.6.0.1

    2,270 downloads

    Extensive library to control and manipulate Microsoft Task Scheduler Service. Please check this site for the implementation status! Please check the History.txt file in the archive for the changelog. Please check the WIKI for details about how to use the UDF. BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort KNOWN BUGS (last changed: 2021-02-03) None Things to come (last changed: 2021-02-03) None
    1 point
  2. Exit

    Challenges for a beginner

    so here is your first challenge: click here
    1 point
  3. Hi mucitbey, 1 line of code could do that, but it will color the whole line (which shouldn't be a big problem ?) Coloring only the time column seems a bit harder, though doable (I've been told) Depending on the script you will choose, add one of these lines, just after the GUICtrlCreateListViewItem() line : If $aInFile[$i][4] > "08:10:00" And $aInFile[$i][4] < "16:50:00" Then _ GUICtrlSetBkColor(-1, 0xDDFFE0) ; light green ; or If $aTemp[4] > "08:10:00" And $aTemp[4] < "16:50:00" Then _ GUICtrlSetBkColor(-1, 0xC0FFFF) ; light blue is great too ! Good luck
    1 point
  4. The custom draw technique is the great, right, flexible and fast way to apply colors in a listview. Read about DllStruct in the help file and just ask more questions if you have any doubts.
    1 point
  5. TheXman

    Font Chooser gui

    What's wrong with the _ChooseFont() function? It is, literally, right below the _ChooseColor() function in the Help FIle.
    1 point
  6. @Zedna : you're right, especially if Users.txt file is unsorted and _ArrayBinarySearch() can't be used. When Users.txt file is sorted by ID's and _ArrayBinarySearch() can be used, then I find a difference of 100ms (1/10s) on my antique computer, based on a Users.txt file containing 500 rows (500 different users, sorted ID's) and a "20191015.txt" file containing 1000 rows (500 employees check-in + 500 check-out the same day, users ID's totally unsorted in "20191015.txt" based on a double shuffle) In case someone likes to test it, here are the 2 scripts I wrote to generate both text files, 1st script will create "Users.txt" (500 rows, ID's sorted) #include <Array.au3> #include <File.au3> Local $aUser[500] ; 500 employees ID from 00000001 To 00000500 For $i = 0 To 499 $aUser[$i] = StringFormat("%08s", $i) & "=" & "Employee #" & $i Next _ArrayDisplay($aUser, "$aUser") ; _ArrayShuffle($aUser) ; If shuffled, then don't use _ArrayBinarySearch() in scripts above +++ ; _ArrayDisplay($aUser, "$aUser - Shuffled") $sFilePath = @ScriptDir & "\Users.txt" _FileWriteFromArray($sFilePath, $aUser) ShellExecute($sFilePath) 2nd script will create "20191015.txt" (1000 rows : 500 check-in + 500 check-out) #include <Array.au3> #include <Date.au3> #include <File.au3> Global $sDate_New Local $aUser ; 500 rows (500 users) Local $aCheckFile[2*500] ; 1000 rows (500 check-in, 500 check-out) _FileReadToArray(@ScriptDir & "\Users.txt", $aUser, $FRTA_NOCOUNT, "=") _ArrayDisplay($aUser, "$aUser") _ArrayShuffle($aUser) ; _ArrayDisplay($aUser, "$aUser shuffled #1") Local $sDate_Start = "2019/10/01 06:59:45" ; start check-in time For $i = 0 To 499 $sDate_Write = Date_Calc($sDate_Start) $aCheckFile[$i] = "001," & $aUser[$i][0] & ",0," & $sDate_Write $sDate_Start = $sDate_New Next _ArrayDisplay($aCheckFile, "$aCheckFile - check-in") _ArrayShuffle($aUser) ; _ArrayDisplay($aUser, "$aUser shuffled #2") $sDate_Start = "2019/10/01 15:59:45" ; start check-out time For $i = 500 To 999 $sDate_Write = Date_Calc($sDate_Start) $aCheckFile[$i] = "001," & $aUser[$i - 500][0] & ",0," & $sDate_Write $sDate_Start = $sDate_New Next _ArrayDisplay($aCheckFile, "$aCheckFile - full day") $sFilePath = @ScriptDir & "\20191015.txt" _FileWriteFromArray($sFilePath, $aCheckFile) ShellExecute($sFilePath) ;==================================================== Func Date_Calc($sDate) $sDate_New = _DateAdd("s", 15 , $sDate) ; add 15s between each user check ; MsgBox($MB_TOPMOST, $sDate, $sDate_New) ; ex. "2019/10/01 07:00:00" Local $sDate_Ret = _ Int(StringMid($sDate_New, 9, 2)) & "." & _ ; day Int(StringMid($sDate_New, 6, 2)) & "." & _ ; month StringLeft($sDate_New, 4) & _ ; year StringRight($sDate_New, 9) ; time ; MsgBox($MB_TOPMOST, $sDate_New, $sDate_Ret) ; ex. "1.10.2019 07:00:00" Return $sDate_Ret EndFunc I added 2 parts in the scripts of the precedent messages : * A timer to know exactly how much time the loop takes (I did it on Zedna's script too, saved on my computer) : $nBegin = TimerInit() For $i = 0 To $iLines - 1 ... Next ConsoleWrite(TimerDiff($nBegin) & @CRLF) * A line _ArrayBinarySearch() has been added too, but it will work only if Users.txt is sorted. Only then, times will be similar to Zedna's (based on 500 users & 1000 checks) though he still beats _ArrayBinarySearch() by... 100 ms $iIndex = _ArraySearch(...) ; $iIndex = _ArrayBinarySearch(...) ; use only if "Users.txt" is sorted on ID's +++ Edit : I just did an interesting test, multiplying everything by 10 ! Which means 5.000 users in "Users.txt" and 10.000 checks (rows) in the 2nd text file "20191015.txt" Now _ArrayBinarySearch() beats everybody, with times of reply < 5s (Zedna is about 9s) Let's forget _ArraySearch() in this case because the reply times are much too long. Personally, I always liked _ArrayBinarySearch() and use it as much as I can with great results. So mucitbey, now it's up to you and you have a choice to make, depending on : * the number of rows in both text files. * the fact that "Users.txt" is sorted or not : if it's sorted and you are 100% sure that it will always be sorted (because of the way it is generated), then you can use _ArrayBinarySearch() with fastest results in case your text files are very big. But if it may happen that "Users.txt" isn't always sorted, then don't hesitate and choose Zedna's way. Good luck
    1 point
  7. This topic shows three ways to do it without the dll; why use an external file if you do not need to:
    1 point
  8. Another way to do it, working directly on 2D Array $aInFile (no more need for Array $aTemp or StringSplit) #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Global $aInFile _FileReadToArray("20191015.txt", $aInFile, $FRTA_NOCOUNT, ", ") Global $iLines = UBound($aInFile) ; _ArrayDisplay($aInFile, "$aInFile") Global $bFile _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=") ; _ArrayDisplay($bFile, "$bFile") GUICreate("_mucitbey_", 430, 500, -1, -1) $lv = GUICtrlCreateListView("#|Card ID|[]|Date|Clock|User", 10, 60, 400, 400) ;Global $hImport = GUICtrlCreateButton("TXT IMPORT", 10, 10, 75, 20) ;Global $hExport = GUICtrlCreateButton("PDF EXPORT", 330, 10, 75, 20) $nBegin = TimerInit() For $i = 0 To $iLines - 1 $iIndex = _ArraySearch($bFile, $aInFile[$i][1], 0, 0, 0, 0, 1, 0) ; search only col. 0 ; $iIndex = _ArrayBinarySearch($bFile, $aInFile[$i][1], 0, 0, 0) ; use only if "Users.txt" is sorted $user = (($iIndex <> -1) ? ($bFile[$iIndex][1]) : ("Unknown ID")) GUICtrlCreateListViewItem($aInFile[$i][0] & "|" & $aInFile[$i][1] & "|" & _ $aInFile[$i][2] & "|" & $aInFile[$i][3] & "|" & $aInFile[$i][4] & "|" & $user, $lv) Next ConsoleWrite(TimerDiff($nBegin) & @CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
    1 point
  9. tz45

    Ballot Paper Analyzer

    EDITED Content of ExtractDots.au3 #include <Array.au3> #include <CustomMsgBox.au3> #include <FastFind.au3> #include <File.au3> #include <GuiConstants.au3> #include <GUIConstantsEx.au3> #Include <GDIPlus.au3> #Include <WinAPI.au3> Global $hGui, $hgraphic Global $w = 800 Global $h = 600 Global $pos[0] Global $grid[12][2] Global $dotValues[0] Global $colorThreshold = [20000, 25000] Func ExtractDots($imgFile) Do Global $dotValues[0] $tmpFile = PrepareImg($imgFile) Gui($tmpFile) for $i = 0 to 11 FindDot(1, $i) Next for $i = 1 to 6 SetBallot($i) Local $dots[0][2] While 1 $result = FindDot() if $result == false then _ ExitLoop _ArrayAdd($dots, $result[0] & "|" & $result[1]) WEnd DotsToValue($i, $dots) Next $isDone = AdaptColors() Until $isDone _GDIPlus_Shutdown() GUIDelete() DirRemove("tmp", 1) return $dotValues EndFunc Func AdaptColors() $colorReturn = xMsgBox(16+0x200, _ "Adapt Color?", "", _ "Black <", "Done", "> Red", _ Default, $pos[1] + $pos[3] + 5) if $colorReturn = 7 then _ return true $colorIndex = ($colorReturn == 6) _ ? 0 _ : 1 $fuzzReturn = xMsgBox(16+0x200, _ "Adapt Fuzz?", "", _ "Less <", "Done", "> More", _ Default, $pos[1] + $pos[3] + 5) $factor = ($fuzzReturn == 6) _ ? -1 _ : 1 $colorThreshold[$colorIndex] += $factor * 2500 return false EndFunc Func PrepareImg($imgFile) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($imgFile, $sDrive, $sDir, $sFileName, $sExtension) $tmpFile = @ScriptDir & "\tmp\" & $sFileName & $sExtension Local $magickCmds = [ _ "magick convert """ & $imgFile & """ -fuzz " & $colorThreshold[1] & " -fill red -opaque red """ & $tmpFile & """", _ "magick convert """ & $tmpFile & """ -fuzz " & $colorThreshold[0] &" -fill black -opaque black """ & $tmpFile & """" ] DirCreate("tmp") for $cmd in $magickCmds RunWait($cmd, @ScriptDir, @SW_HIDE) Next return $tmpFile EndFunc Func Gui($tmpFile) _GDIPlus_Startup() Global $hGui $hBitmap = _GDIPlus_BitmapCreateFromFile($tmpFile) $hGui = GUICreate("ExtractDots", $w, $h, -1, -1, $WS_POPUP) GUISetState() $pos = WinGetPos("ExtractDots") $hgraphic = _GDIPlus_GraphicsCreateFromHWND($hGui) _GDIPlus_GraphicsDrawImageRect($hgraphic, $hBitmap, 0, 0, $w, $h) _GDIPlus_BitmapDispose($hBitmap) FFSetWnd($hGui) FFSnapShot() EndFunc Func DrawPoint($coords, $colorIndex = 0) Local $colors = [ _ 0xFF0ca2f0, _ 0xFFFFFF00, _ 0xFFFF0000, _ 0xFFFF00cc, _ 0xFF66FF00 _ ] $colorIndex = Mod($colorIndex, UBound($colors)) $color = $colors[$colorIndex] $hBrush = _GDIPlus_BrushCreateSolid($color) _GDIPlus_GraphicsFillEllipse($hgraphic, _ $coords[0] - 5, _ $coords[1] - 5, _ 10, 10, $hBrush) EndFunc Func DotsToValue($ballotIndex, $dots) $corners = GetCorners($ballotIndex) $first = SingleCorner($corners, 0) $second = SingleCorner($corners, 1) $third = SingleCorner($corners, 2) $fourth = SingleCorner($corners, 3) DrawPoint($first) DrawPoint($second) DrawPoint($third) DrawPoint($fourth) Local $values[0] for $i = 0 to UBound($dots) - 1 Local $dot[0] _ArrayAdd($dot, $dots[$i][0] & "|" & $dots[$i][1]) DrawPoint($dot, 1) $xVanishingPoint = GetPOI($first, $third, $second, $fourth) if Not $xVanishingPoint then $vector = VectorCalc($first, '-', $third) $xVanishingPoint = VectorCalc($dot, '+', $vector) EndIf $yVanishingPoint = GetPOI($first, $second, $third, $fourth) if Not $yVanishingPoint then $vector = VectorCalc($first, '-', $second) $yVanishingPoint = VectorCalc($dot, '+', $vector) EndIf $xPOI = GetPOI($first, $second, $dot, $xVanishingPoint) $yPOI = GetPOI($first, $third, $dot, $yVanishingPoint) ;DrawPoint($xPOI, 4) ;DrawPoint($yPOI, 4) $xVector = VectorCalc($xPOI, '-', $first) $yVector = VectorCalc($yPOI, '-', $first) $xLength = VectorCalc($xVector, '|') $top = VectorCalc($second, '-', $first) $topLength = VectorCalc($top, '|') $xPercentage = $xLength / $topLength $xDigit = Round($xPercentage * 11) $yLength = VectorCalc($yVector, '|') $left = VectorCalc($third, '-', $first) $leftLength = VectorCalc($left, '|') $yPercentage = $yLength / $leftLength $yDigit = Round($yPercentage * 11) $value = ($yDigit - 1)*10 + $xDigit _ArrayAdd($values, $value) Next _ArraySort($values) _ArrayAdd($dotValues, _ArrayToString($values, ",")) EndFunc Func GetPOI($startPoint1, $endPoint1, $startPoint2, $endPoint2) $a = $startPoint1[0] $b = $startPoint1[1] $vector1 = VectorCalc($endPoint1, '-', $startPoint1) $c = $vector1[0] $d = $vector1[1] $e = $startPoint2[0] $f = $startPoint2[1] $vector2 = VectorCalc($endPoint2, '-', $startPoint2) $m = $vector2[0] $n = $vector2[1] if $d*$m - $c*$n == 0 then _ return false $s = (-$n*($e - $a) + $m*($f - $b)) / ($d*$m - $c*$n) $x = $a + $s*$c $y = $b + $s*$d Local $result[2] = [$x, $y] return $result EndFunc Func SingleCorner($array, $index) Local $result[2] for $i = 0 to 1 $result[$i] = $array[$index][$i] Next return $result EndFunc Func SetBallot($index) $corners = GetCorners($index) SetArea( _ $corners[0][0], $corners[0][1], _ $corners[3][0], $corners[3][1]) EndFunc Func GetCorners($index) Local $corners[4] $missedSquare = Floor(($index - 1) / 3) $corners[0] = $index - 1 + $missedSquare $corners[1] = $corners[0] + 1 $corners[2] = $index + 3 + $missedSquare $corners[3] = $corners[2] + 1 Local $result[4][2] for $i = 0 to 3 $entryIndex = $corners[$i] $cornerCoordinates = GetGridEntry($entryIndex) for $j = 0 to 1 $result[$i][$j] = $cornerCoordinates[$j] Next Next return $result EndFunc Func SetGridEntry($array, $index) for $i = 0 to 1 $grid[$index][$i] = $array[$i] Next EndFunc Func GetGridEntry($index) Local $array[2] For $i = 0 to 1 $array[$i] = $grid[$index][$i] Next return $array EndFunc Func VectorCalc($par1, $operation, $par2 = 0) switch $operation case '+' Local $result[2] for $i = 0 to 1 $result[$i] = $par1[$i] + $par2[$i] Next case '-' Local $result[2] for $i = 0 to 1 $result[$i] = $par1[$i] - $par2[$i] Next case '*' Local $result[2] for $i = 0 to 1 $result[$i] = $par1 * $par2[$i] Next case '|' Local $result = Sqrt($par1[0]^2 + $par1[1]^2) EndSwitch return $result EndFunc Func SetArea($a = -1, $b = -1, $c = -1, $d = -1) FFResetExcludedAreas() if $a + $b + $c + $c == -4 then _ return ;top FFAddExcludedArea( _ 0, _ 0, _ $w, _ $b) ;left FFAddExcludedArea( _ 0, _ $b, _ $a, _ $d) ;right FFAddExcludedArea( _ $c, _ $b, _ $w, _ $d) ;bottom FFAddExcludedArea( _ 0, _ $d, _ $w, _ $h) EndFunc Func FindDot($isRed = 0, $gridIndex = -1) local $shadeVariation=0 Local $shadeVariationMax = ($isRed) _ ? 250 _ : 60 local $result Local $color = ($isRed) _ ? 0xFFFF0000 _ : 0xFF000000 if $isRed then $horizontalFactor = Mod($gridIndex, 4) $firstX = $horizontalFactor * $w/4 $secondX = $firstX + $w/4 $verticalFactor = Floor($gridIndex/4) $firstY = $verticalFactor * $h/3 $secondY = $firstY + $h/3 SetArea($firstX, $firstY, $secondX, $secondY) EndIf do $result = FFNearestSpot(20, 50, 0, 0, $color, $shadeVariation, 0) if (Not IsArray($result)) Then _ $shadeVariation += 5 until (IsArray($result) OR $shadeVariation > $shadeVariationMax) if Not IsArray($result) then _ return false if $isRed then SetGridEntry($result, $gridIndex) Else FFAddExcludedArea( _ $result[0] - 20, _ $result[1] - 20, _ $result[0] + 20, _ $result[1] + 20) EndIf return _ArrayExtract($result, 0, 1) EndFunc Can be called from another project like this: #include <ExtractDots.au3> Local $files = [ _ "example3.jpg", _ "example5.jpg", _ "example9.jpg" ] Local $votes[0] for $file in $files $values = ExtractDots($file) _ArrayAdd($votes, $values) Next _ArrayDisplay($votes) Depending on the brightness, saturation, and illumination of the image, individual points may not or too many may be detected. Therefore, using ImageMagick (must be installed), each image is edited to highlight red and black. Each image is followed by a query that allows you to adjust the two colors. Here are some files to try out. ExtractDots.zip
    1 point
  10. Unknow ID 14 on purpose : #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Global $aInFile _FileReadToArray("20191015.txt", $aInFile, $FRTA_NOCOUNT) Global $iLines = UBound($aInFile) ; _ArrayDisplay($aInFile, "$aInFile") Global $bFile _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=") ; _ArrayDisplay($bFile, "$bFile") GUICreate("_mucitbey_", 430, 500, -1, -1) $lv = GUICtrlCreateListView("#|Card ID|[]|Date|Clock|User", 10, 60, 400, 400) ;Global $hImport = GUICtrlCreateButton("TXT IMPORT", 10, 10, 75, 20) ;Global $hExport = GUICtrlCreateButton("PDF EXPORT", 330, 10, 75, 20) $nBegin = TimerInit() For $i = 0 To $iLines - 1 $aTemp = StringSplit($aInFile[$i], ", ", $STR_NOCOUNT) $iIndex = _ArraySearch($bFile, $aTemp[1], 0, 0, 0, 0, 1, 0) ; search only col. 0 ; $iIndex = _ArrayBinarySearch($bFile, $aTemp[1], 0, 0, 0) ; use only if "Users.txt" is sorted $user = (($iIndex <> -1) ? ($bFile[$iIndex][1]) : ("Unknown ID")) GUICtrlCreateListViewItem($aTemp[0] & "|" & $aTemp[1] & "|" & $aTemp[2] & "|" & _ $aTemp[3] & "|" & $aTemp[4] & "|" & $user, $lv) Next ConsoleWrite(TimerDiff($nBegin) & @CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
    1 point
  11. #include <GUIConstantsEx.au3> #include <File.au3> Global $aInFile _FileReadToArray("20191015.txt", $aInFile, $FRTA_NOCOUNT) Global $iLines = UBound($aInFile) Global $bFile = @CRLF & FileRead("Users.txt") & @CRLF GUICreate("_mucitbey_", 430, 500, -1, -1) $lv = GUICtrlCreateListView("#|Card ID|[]|Date|Clock|User", 10, 60, 400, 400) ;~ Global $hImport = GUICtrlCreateButton("TXT IMPORT", 10, 10, 75, 20) ;~ Global $hExport = GUICtrlCreateButton("PDF EXPORT", 330, 10, 75, 20) For $i = 0 To $iLines - 1 $aTemp = StringSplit($aInFile[$i], ", ", $STR_NOCOUNT) $user = GetUser($aTemp[1]) GUICtrlCreateListViewItem($aTemp[0] & "|" & $aTemp[1] & "|" & $aTemp[2] & "|" & $aTemp[3] & "|" & $aTemp[4] & "|" & $user, $lv) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GetUser($ID) Local $i, $j, $len $i = StringInStr($bFile, @CRLF & $ID & '=', 1, 1) If $i = 0 Then Return '' $j = StringInStr($bFile, @CRLF, 1, 1, $i+1) If $j = 0 Then Return '' $len = StringLen(@CRLF & $ID & '=') Return StringMid($bFile, $i+$len, $j-$i-$len) EndFunc
    1 point
  12. #include "CUIAutomation2.au3" ; https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/ Global $pElement, $pCondition, $pElementArray, $iElements, $vValue ; Get taskbar handle $hCtrl = ControlGetHandle("[Class:Shell_TrayWnd]", "", "MSTaskListWClass1") ; Get UIAutomation object $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) ; Get taskbar element $oUIAutomation.ElementFromHandle($hCtrl, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ; Get condition (ControlType = Button) $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) ; Find all buttons $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray) $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oElementArray.Length($iElements) ; Get array of buttons Global $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $vValue) ConsoleWrite("Name:" & $vValue) $aElements[$i].CurrentBoundingRectangle($tRect) ConsoleWrite(" L:" & $tRect.Left & " T:" & $tRect.Top & " R:" & $tRect.Right & " B:" & $tRect.Bottom & @CRLF) Next
    1 point
  13. jguinch

    Check status of a service

    Object way : Local $sServiceName = "RemoteRegistry" Local $oShell = ObjCreate("shell.application") Do Sleep(100) Until $oShell.IsServiceRunning($sServiceName) MsgBox(0, "", "Service " & $sServiceName & " is running now")
    1 point
  14. Here you go (3.3.10 or later) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <Array.au3> Global $aFirstArray[10][5] = [["Type1", "Subtype1", 10, 1, 0.1],["Type1", "Subtype2", 20, 2, 0.2], _ ["Type1", "Subtype3", 30, 3, 0.3],["Type2", "Subtype4", 40, 4, 0.4], _ ["Type2", "Subtype5", 50, 5, 0.5],["Type3", "Subtype5", 60, 6, 0.6], _ ["Type4", "Subtype6", 70, 7, 0.7],["Type4", "Subtype7", 80, 8, 0.8], _ ["Type5", "Subtype8", 90, 9, 0.9],["Type5", "Subtype9", 100, 10, 0.0]] ;_ArrayDisplay($aFirstArray, "First") Local $iCols = UBound($aFirstArray, 2) - 1 Local $aResult[UBound($aFirstArray) * 2][$iCols], $sLast, $n = 0 For $x = 2 To $iCols $sLast = "" $n = 0 For $i = 0 To UBound($aFirstArray) - 1 If $aFirstArray[$i][0] <> $sLast Or $n = 0 Then $sLast = $aFirstArray[$i][0] $aResult[$n][0] = $sLast ; Add Type to array $n += 1 $aResult[$n][0] = $aFirstArray[$i][1] ; Add Subtype to array $aResult[$n][$x - 1] = $aFirstArray[$i][$x] ; Add Value to array Else $aResult[$n][0] = $aFirstArray[$i][1] ; Add Subtype to array $aResult[$n][$x - 1] = $aFirstArray[$i][$x] ; Add Value to array EndIf $n += 1 Next Next ReDim $aResult[$n][$iCols] ;_ArrayDisplay($aResult, "Second") ; Adding The values of subtypes $iTotalIndex = 0 $iTotalValue = 0 $iCols = UBound($aResult, 2) - 1 For $x = 1 To $iCols $iTotalIndex = 0 $iTotalValue = 0 For $i = 1 To UBound($aResult) - 1 If $aResult[$i][$x] <> "" Then $iTotalValue += $aResult[$i][$x] ; Add value of Subtype Else $aResult[$iTotalIndex][$x] = $iTotalValue ; Insert total of subtype values into parent type $iTotalValue = 0 ; Reset Total $iTotalIndex = $i ; Remember index of lat parent type EndIf Next $aResult[$iTotalIndex][$x] = $iTotalValue ; Insert last total of subtype values into parent type Next ;_ArrayDisplay($aResult, "Third") ; All colors in BGR ; Colors for types/subtypes in col 0 Global $aColTypes = [ 0xADDEFF, 0xFFFFE0, 0xC1B6FF, 0xFFFF00, 0xFF0000, 0xFFFF00 ], $iColTypes = 0 Global $iWhite = 0xFFFFFF, $iRed = 0xCCCCFF, $iGreen = 0xCCFFCC ; Color array $iRows = UBound($aResult) $iCols = UBound($aResult, 2) Global $aColors[$iRows][$iCols] ; Fill color array For $i = 0 To $iRows - 1 If StringLeft( $aResult[$i][0], 4 ) = "Type" Then $iColorCol0 = $aColTypes[$iColTypes] $iColTypes += 1 EndIf $aColors[$i][0] = $iColorCol0 $aColors[$i][1] = $iWhite For $j = 2 To $iCols - 1 $aColors[$i][$j] = $aResult[$i][$j-1] > $aResult[$i][$j] ? $iRed : $iGreen Next Next ;_ArrayDisplay($aColors, "Colors") ; Listview GUICreate("Listview", 400, 300) $idLV = GUICtrlCreateListView("col0 |col1|col2|col3", 10, 10, 380, 280) $hLV = GUICtrlGetHandle( $idLV ) For $i = 0 To $iRows - 1 $s = $aResult[$i][0] For $j = 1 To $iCols - 1 $s &= "|" & $aResult[$i][$j] Next GUICtrlCreateListViewItem($s, $idLV) Next GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hLV Switch $iCode Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem ;Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index ;Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[$iItem][$iSubItem] ) ; Backcolor of item/subitem DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")][DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")] ) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc
    1 point
×
×
  • Create New...