Leaderboard
Popular Content
Showing content with the highest reputation on 12/01/2019 in all areas
-
MailSlot
Professor_Bernd reacted to trancexx for a topic
This way of communication between processes very much resemble to the communication we do with our mail accounts. I would guess (smartly, no doubt) that was the key factor used for naming the functions when they were created. Information about mailslots can be found on microsoft's site, link. Summary could be that datagrams are used for communication and it's one-way and asynchronous. Attached zip file contains MailSlot.au3, AutoIt's implementation of these functions. Also there would be two scripts in there MailSlot_Sender.au3 and MailSlot_Reciever.au3. Both scripts are demos of the mailslot mechanism. Start both and use former to send mails to latter. Examples are basic and should show what's this about. MailSlot.zip Available functions are alphabetically: _MailSlotCheckForNextMessage_MailSlotClose_MailSlotCreate_MailSlotGetMessageCount_MailSlotGetTimeout_MailSlotSetTimeout_MailSlotRead_MailSlotWriteedit: New attachment. _MailSlotGetTimeout() function added to MailSlot.au3.1 point -
[New Release] - 06 April 2019 Added: Error-checking for sensible column numbers in the $aSortData array, with an additional error status. ------------------------------------------------------------------------------------------------------------------------ While answering a recent question about sorting a ListView on several columns, I developed this function to sort a 2D array on several columns and I though I might give it a wider audience. Here is the function: #include-once ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include <Array.au3> ; =============================================================================================================================== ; #INDEX# ======================================================================================================================= ; Title .........: ArrayMultiColSort ; AutoIt Version : v3.3.8.1 or higher ; Language ......: English ; Description ...: Sorts 2D arrays on several columns ; Note ..........: ; Author(s) .....: Melba23 ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _ArrayMultiColSort : Sort 2D arrays on several columns ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; __AMCS_SortChunk : Sorts array section ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiColSort ; Description ...: Sort 2D arrays on several columns ; Syntax.........: _ArrayMultiColSort(ByRef $aArray, $aSortData[, $iStart = 0[, $iEnd = 0]]) ; Parameters ....: $aArray - The 2D array to be sorted ; $aSortData - 2D array holding details of the sort format ; Format: [Column to be sorted, Sort order] ; Sort order can be either numeric (0/1 = ascending/descending) or a ordered string of items ; Any elements not matched in string are left unsorted after all sorted elements ; $iStart - Element of array at which sort starts (default = 0) ; $iEnd - Element of array at which sort endd (default = 0 - converted to end of array) ; Requirement(s).: v3.3.8.1 or higher ; Return values .: Success: No error ; Failure: @error set as follows ; @error = 1 with @extended set as follows (all refer to $sIn_Date): ; 1 = Array to be sorted not 2D ; 2 = Sort data array not 2D ; 3 = More data rows in $aSortData than columns in $aArray ; 4 = Start beyond end of array ; 5 = Start beyond End ; @error = 2 with @extended set as follows: ; 1 = Invalid string parameter in $aSortData ; 2 = Invalid sort direction parameter in $aSortData ; 3 = Invalid column index in $aSortData ; Author ........: Melba23 ; Remarks .......: Columns can be sorted in any order ; Example .......; Yes ; =============================================================================================================================== Func _ArrayMultiColSort(ByRef $aArray, $aSortData, $iStart = 0, $iEnd = 0) ; Errorchecking ; 2D array to be sorted If UBound($aArray, 2) = 0 Then Return SetError(1, 1, "") EndIf ; 2D sort data If UBound($aSortData, 2) <> 2 Then Return SetError(1, 2, "") EndIf If UBound($aSortData) > UBound($aArray) Then Return SetError(1, 3) EndIf For $i = 0 To UBound($aSortData) - 1 If $aSortData[$i][0] < 0 Or $aSortData[$i][0] > UBound($aArray, 2) -1 Then Return SetError(2, 3, "") EndIf Next ; Start element If $iStart < 0 Then $iStart = 0 EndIf If $iStart >= UBound($aArray) - 1 Then Return SetError(1, 4, "") EndIf ; End element If $iEnd <= 0 Or $iEnd >= UBound($aArray) - 1 Then $iEnd = UBound($aArray) - 1 EndIf ; Sanity check If $iEnd <= $iStart Then Return SetError(1, 5, "") EndIf Local $iCurrCol, $iChunk_Start, $iMatchCol ; Sort first column __AMCS_SortChunk($aArray, $aSortData, 0, $aSortData[0][0], $iStart, $iEnd) If @error Then Return SetError(2, @extended, "") EndIf ; Now sort within other columns For $iSortData_Row = 1 To UBound($aSortData) - 1 ; Determine column to sort $iCurrCol = $aSortData[$iSortData_Row][0] ; Create arrays to hold data from previous columns Local $aBaseValue[$iSortData_Row] ; Set base values For $i = 0 To $iSortData_Row - 1 $aBaseValue[$i] = $aArray[$iStart][$aSortData[$i][0]] Next ; Set start of this chunk $iChunk_Start = $iStart ; Now work down through array For $iRow = $iStart + 1 To $iEnd ; Match each column For $k = 0 To $iSortData_Row - 1 $iMatchCol = $aSortData[$k][0] ; See if value in each has changed If $aArray[$iRow][$iMatchCol] <> $aBaseValue[$k] Then ; If so and row has advanced If $iChunk_Start < $iRow - 1 Then ; Sort this chunk __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf ; Set new base value $aBaseValue[$k] = $aArray[$iRow][$iMatchCol] ; Set new chunk start $iChunk_Start = $iRow EndIf Next Next ; Sort final section If $iChunk_Start < $iRow - 1 Then __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf Next EndFunc ;==>_ArrayMultiColSort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __AMCS_SortChunk ; Description ...: Sorts array section ; Author ........: Melba23 ; Remarks .......: ; =============================================================================================================================== Func __AMCS_SortChunk(ByRef $aArray, $aSortData, $iRow, $iColumn, $iChunkStart, $iChunkEnd) Local $aSortOrder ; Set default sort direction Local $iSortDirn = 1 ; Need to prefix elements? If IsString($aSortData[$iRow][1]) Then ; Split elements $aSortOrder = StringSplit($aSortData[$iRow][1], ",") If @error Then Return SetError(1, 1, "") EndIf ; Add prefix to each element For $i = $iChunkStart To $iChunkEnd For $j = 1 To $aSortOrder[0] If $aArray[$i][$iColumn] = $aSortOrder[$j] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] ExitLoop EndIf Next ; Deal with anything that does not match If $j > $aSortOrder[0] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] EndIf Next Else Switch $aSortData[$iRow][1] Case 0, 1 ; Set required sort direction if no list If $aSortData[$iRow][1] Then $iSortDirn = -1 Else $iSortDirn = 1 EndIf Case Else Return SetError(1, 2, "") EndSwitch EndIf ; Sort the chunk Local $iSubMax = UBound($aArray, 2) - 1 __ArrayQuickSort2D($aArray, $iSortDirn, $iChunkStart, $iChunkEnd, $iColumn, $iSubMax) ; Remove any prefixes If IsString($aSortData[$iRow][1]) Then For $i = $iChunkStart To $iChunkEnd $aArray[$i][$iColumn] = StringTrimLeft($aArray[$i][$iColumn], 3) Next EndIf EndFunc ;==>__AMCS_SortChunk And here is an example to show it working: #include "ArrayMultiColSort.au3" #include <String.au3> ; Only used to fill array ; Create and display array Global $aArray[100][4] For $i = 0 To 99 $aArray[$i][0] = _StringRepeat(Chr(Random(65, 68, 1)), 5) $aArray[$i][1] = _StringRepeat(Chr(Random(74, 77, 1)), 5) $aArray[$i][2] = _StringRepeat(Chr(Random(80, 83, 1)), 5) $aArray[$i][3] = _StringRepeat(Chr(Random(87, 90, 1)), 5) Next _ArrayDisplay($aArray, "Unsorted") ; Copy arrays for separate examples below $aArray_1 = $aArray $aArray_2 = $aArray ; This sorts columns in ascending order - probably the most common requirement ; Sort requirement: ; Col 0 = Decending ; Col 1 = Ascending ; Col 2 = Required order of elements (note not alphabetic PQRS nor reverse SRQP) ; Col 3 = Ascending Global $aSortData[][] = [ _ [0, 1], _ [1, 0], _ [2, "SSSSS,QQQQQ,PPPPP,RRRRR"], _ [3, 0]] ; Sort and display array _ArrayMultiColSort($aArray_1, $aSortData) ; Display any errors encountered If @error Then ConsoleWrite("Oops: " & @error & " - " & @extended & @CRLF) _ArrayDisplay($aArray_1, "Sorted in order 0-1-2-3") ; But the UDF can sort columns in any order ; Sort requirement: ; Col 2 = Decending ; Col 0 = Ascending Global $aSortData[][] = [ _ [2, 1], _ [0, 0]] ; Sort and display array _ArrayMultiColSort($aArray_2, $aSortData) ; Display any errors encountered If @error Then ConsoleWrite("Oops: " & @error & " - " & @extended & @CRLF) _ArrayDisplay($aArray_2, "Sorted in order 2-0") And here are both in zip form: ArrayMultiColSort.zip As usual all comments welcome. M231 point
-
FileCopy accepts Wildcards e.g. *.rar Maybe you mean something like this 🤔 : #include <FileConstants.au3> #include <WinAPIShPath.au3> Opt('MustDeclareVars', 1) Global $sSourceDir, $sDestDir, $iCopyResult Global $aExtensions[4] = ["*.jpg", "*.gif", "*.avi ", "*.rar"] $sSourceDir = _WinAPI_PathAddBackslash(@ScriptDir & "\TestCopySource") $sDestDir = _WinAPI_PathAddBackslash(@ScriptDir & "\TestCopyDest") For $i = 0 To UBound($aExtensions) - 1 ConsoleWrite("+ Copy Extension = " & $aExtensions[$i] & @CRLF) $iCopyResult = FileCopy($sSourceDir & $aExtensions[$i], $sDestDir, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite("> Result = " & $iCopyResult & " (1 = ok , 0 = not ok/no files)" & @CRLF) Next By the way: what is the purpose of the game graphic?1 point
-
Wouldn't that be better to use the more standardized approach of a TreeView ? If you look at the example of _GUICtrlTreeView_Create, you will see how they create "n" leaves. But if you insist on using your code, I would define an Array of elements that you could create in a loop and manage in a single function based on index of the array...1 point
-
Help whit array - (Moved)
JuanFelipe reacted to jchd for a topic
You can do like this: #include "..\include\ArrayMultiColSort.au3" ; description, size, quantity Local $aIn = [ _ ["BBB", "4l", 1], _ ["AAA", "8m", 10], _ ["CCC", "1m²", 37], _ ["BBB", "4l", 19], _ ["EEE", "10kg", 7], _ ["AAA", "12m", 17], _ ["BBB", "4l", 4], _ ["AAA", "8m", 11], _ ["CCC", "1m²", 3], _ ["BBB", "20l", 6], _ ["AAA", "8m", 7], _ ["DDD", '3"', 2] _ ] Local $bOut = _Limpiar($aIn) _ArrayDisplay($bOut) Func _Limpiar($b) Local $SortFmt = [[0, 0], [1, 0]] _ArrayMultiColSort($b, $SortFmt) Local $i = 0, $j = 0 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] For $i = 1 To UBound($b) - 1 If $b[$i][0] = $b[$i - 1][0] And $b[$i][1] = $b[$i - 1][1] Then $b[$j][2] += $b[$i][2] Else $j += 1 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] EndIf Next ReDim $b[$j + 1][UBound($b, 2)] Return $b EndFunc using this UDF by @Melba231 point -
Image not found
Polistotele reacted to Belini for a topic
In my tests ImageSearch() works fine #include <ImageSearch.au3> $x1 = 0 $y1 = 0 If FileExists("image2.bmp") = 0 Then MsgBox(0, "Error", "The sample image was not found!", 4) Exit EndIf AdlibRegister("image", 2000) While 1 $res = _ImageSearch("image2.bmp", 1, $x1, $y1, 0) If $res = 1 Then MouseMove($x1, $y1, 30) ExitLoop EndIf Sleep(200) WEnd MsgBox(0, "Sucess", "Image is found!", 4) Func image() ShellExecute(@ScriptDir & "\image.bmp") EndFunc ;==>image Test: https://mega.nz/#!YFcinSiQ!hovb6nC4WZCaD7muC9bJKid6n4Wi3dc44ywZA5keh8c1 point -
I would suggest AdlibRegister function. Look in help file...1 point
-
This description looks like klingon for me ... My previous try could be done more accurate anyway Local $s = "{[[Elton John, Bonnie & Clyde, Sally, 123],[one 1, 2&, 3, 4_#4]], abc, [7,{a,b,[c,d,3]}]}" $res = StringRegExpReplace($s, '\h*\d*\h*(?=[,\{\[\]])(*SKIP)(*F)|\h*([^\{\}\[\],]+)\h*', '"$1"') Msgbox(0,"", $res)1 point
-
OTOH if you want to match JSON definitions of its internal structure you can do so explicitely: Local $sIn = "{[[Elton John, Bonnie & Clyde, Sally, 123],[one 1, 2, 3, 4 four 4]], abc, [7,{a,b,[c,d,3]}]}" _String2Json($sIn) MsgBox(0, "Result", $sIn) Func _String2Json(ByRef $s) $s = StringRegExpReplace($s, _ '(?x)' & _ '(?(DEFINE) (?<table> \{ \h* (?: (?&element) (?: \h* , \h* (?&element) )* \h* \} ) ) )' & _ '(?(DEFINE) (?<array> \[ \h* (?: (?&element) (?: \h* , \h* (?&element) )* \h* \] ) ) )' & _ '(?(DEFINE) (?<element> (?&table) | (?&array) | (?&number) | (?&string) ) )' & _ '(?(DEFINE) (?<number> [-+]? \d+ (?: \.\d+ )? (?: [Ee] [-+]? \d+ )? ) )' & _ '(?(DEFINE) (?<string> \b \w* [^\[\],]*[[:alpha:]_]+ [\w\h]* ) )' & _ '( (?&string) )', _ '"$6"') EndFunc ;==>_Array2Json Of course, once that invalid input string is reformatted to correctly enclose strings inside double quotes, things are easier to handle.1 point
-
as far as i'm aware, you can only have one menu bar. Maybe you could create a child window with it's own menu and embed it within your main GUI?1 point
-
1 point
-
How to create 2 main menus
_Vlad reacted to mistersquirrle for a topic
Hello aspectulconteazz, welcome to the forums. I recommend that you check out: GUICtrlCreateMenuItem from the help file. I think that this is what you're looking for. If it's not, can you explain more on what you're looking for? Or a screenshot example of something else that's similar. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("2 MainMenus", 615, 137, 192, 124) $MenuItem1 = GUICtrlCreateMenu("MainMenu 1") $Menu1Sub1 = GUICtrlCreateMenuItem('SubMenu1', $MenuItem1) $Menu1Sub2 = GUICtrlCreateMenuItem('SubMenu2', $MenuItem1) $MenuItem2 = GUICtrlCreateMenu("MainMenu 2") $Menu2Sub1 = GUICtrlCreateMenuItem('SubMenu1', $MenuItem2) $Menu2Sub2 = GUICtrlCreateMenuItem('SubMenu2', $MenuItem2) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Menu1Sub1 ConsoleWrite(':' & @ScriptLineNumber & ': - Menu 1, Sub 1 clicked' & @CRLF) Case $Menu1Sub2 ConsoleWrite(':' & @ScriptLineNumber & ': - Menu 1, Sub 2 clicked' & @CRLF) Case $Menu2Sub1 ConsoleWrite(':' & @ScriptLineNumber & ': - Menu 2, Sub 1 clicked' & @CRLF) Case $Menu2Sub2 ConsoleWrite(':' & @ScriptLineNumber & ': - Menu 2, Sub 2 clicked' & @CRLF) EndSwitch WEnd I added a couple menu items to your example code, and cases for them into the main loop. It'll display in the SciTE console when you click on one of the MenuItems. You can replace the ConsoleWrite with whatever you want to have happen.1 point -
I don't know if there is some need, but I made a simple function to use only english button names in MsgBox. #include <WinAPI.au3> Opt("MustDeclareVars", 1) Global $hHookMsgBox _MsgBoxEnglish(0, "Title", "Text") _MsgBoxEnglish(1, "Title", "Text") _MsgBoxEnglish(2, "Title", "Text") _MsgBoxEnglish(3, "Title", "Text") _MsgBoxEnglish(4, "Title", "Text") _MsgBoxEnglish(5, "Title", "Text") _MsgBoxEnglish(6, "Title", "Text") _MsgBoxEnglish(7, "Title", "Text") #region English Button text for MsgBox!! ;########################################################## Func _MsgBoxEnglish($flag, $title, $text, $timeout = 0, $hwnd = 0) Local $hProcMsgBox = DllCallbackRegister("CbtHookProcMsgBox", "int", "int;int;int") Local $TIDMsgBox = _WinAPI_GetCurrentThreadId() $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox) Local $iRet = MsgBox($flag, $title, $text, $timeout, $hwnd) _WinAPI_UnhookWindowsHookEx($hHookMsgBox) DllCallbackFree($hProcMsgBox) Return $iRet EndFunc ;==>_MsgBoxEnglish Func CbtHookProcMsgBox($nCode, $wParam, $lParam, $hHookMsgBox) Local $RET = 0, $hBitmap = 0, $xWnd = 0 Local $sButtonText If $nCode < 0 Then $RET = _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam) Return $RET EndIf Switch $nCode Case 5 ;5=HCBT_ACTIVATE _WinAPI_SetDlgItemText($wParam, 1, "OK") _WinAPI_SetDlgItemText($wParam, 2, "Cancel") _WinAPI_SetDlgItemText($wParam, 3, "&Abort") _WinAPI_SetDlgItemText($wParam, 4, "&Retry") _WinAPI_SetDlgItemText($wParam, 5, "&Ignore") _WinAPI_SetDlgItemText($wParam, 6, "&Yes") _WinAPI_SetDlgItemText($wParam, 7, "&No") _WinAPI_SetDlgItemText($wParam, 8, "Help") _WinAPI_SetDlgItemText($wParam, 10, "&Try Again") _WinAPI_SetDlgItemText($wParam, 11, "&Continue") EndSwitch Return EndFunc ;==>CbtHookProcMsgBox Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _ "hwnd", $hDlg, _ "int", $nIDDlgItem, _ "str", $lpString) Return $aRet[0] EndFunc ;==>_WinAPI_SetDlgItemText ;########################################################## #endregion English Button text for MsgBox!!1 point
-
What about StringSplit(), _ArraySort(), _ArrayToString()? Have a look also to Natural Order String Comparison Br, UEZ1 point
-
I have it. I'm gonna give it a once over to see if I can make any improvements, then I'll repost it.1 point
-
He is talking about non autoit guis.. Check ControlCommand() in helpfile. You can use the "IsChecked" flag.1 point
-
_GUICtrlListView_AddItem() MUCH slower than GUICtrlCreateListViewItem()
pixelsearch reacted to Zedna for a topic
1) GUICtrlCreateListViewItem() - very quick 2) _GUICtrlListView_AddItem(ControlId) - MUCH slower 3) _GUICtrlListView_AddItem(ControlHwnd) - even MUCH more slower I think 1) and 2) should have similar time consume amount and not such big differences. I saw it's sources. Times in parenthesis are from another computer. All times are avg from several runs (all on 3.2.10 version) #include <GUIConstants.au3> #include <GUIListView.au3> $gui = GUICreate("listview items", 320, 250, 100, 200) $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $hListView = ControlGetHandle($gui, '', $listview) $button1 = GUICtrlCreateButton("Create std", 15, 170, 70, 20) $button2 = GUICtrlCreateButton("Create UDF", 125, 170, 70, 20) $button3 = GUICtrlCreateButton("Delete UDF", 200, 170, 70, 20) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUISetState() Do $msg = GUIGetMsg() Select Case $msg = $button1 $start = TimerInit() For $i = 1 To 4000 GUICtrlCreateListViewItem("item1|col2|col3", $listview) Next GUICtrlSetData($input1, 'Time: ' & TimerDiff($start)) ; 440 ms (650) Case $msg = $button2 $start = TimerInit() For $i = 1 To 4000 _GUICtrlListView_AddItem($ListView, "item1|col2|col3") ;~ _GUICtrlListView_AddItem($hListView, "item1|col2|col3") Next GUICtrlSetData($input1, 'Time: ' & TimerDiff($start)) ; 1250 ms with $ListView (2650) ; 1980 ms with $hListView (12000) Case $msg = $button3 _GUICtrlListView_DeleteAllItems($hListView) EndSelect Until $msg = $GUI_EVENT_CLOSE Is this only _GUICtrlListView_AddItem() speed limitation or some bug/not optimized code in UDF?1 point -
Compiled code is much faster than interpreted code, that's a given. I'm surprised that you are surprised. You can optimize it to perform better in such benchmark, for example, _GUICtrlListView_AddItem() in fact does nothing but call the _GUICtrlListView_InsertItem(), so simply by calling the latter yourself you'd make that 4000 iteration loop a tiny bit faster. Also, if you "saw it's sources", there's quite a few things that need to be done before actual sendmessage takes place, and that's repeated for each iteration - waste of precious time if you intend to add that many items in a row (as basically you only need to repeat 2 actions - setting new text in buffer and sending LVM_INSERTITEM message). You could write custom function moving the For loop inside of it, and that would reduce total time dramatically. But it will be slower still, as it should.1 point