Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/24/2021 in all areas

  1. I try very hard NOT to make assumptions as to what a person is asking or wants. Making assumtions usually ends up wasting time and gives that person a way to say that's not what they were looking or asking for. Therefore, I only work with what I've been given and the answers to any followup questions that are asked. So, if you provide overly-simplified examples and requests, don't be surprised when you receive overly-simplified replies. In other words, as it says in my signature, if you want better answers, learn how to ask better questions. You may benefit from reading one or both of those articles. The statement above, without accurate, detailed, examples, is almost useless. It's like telling a mechanic that you have a car with a V8 engine, and other assorted non-specific performance modifications, and asking the mechanic how to improve its performance or make further modifications without seeing the car itself or a detailed list of parts and specs. That would be a fool's errand. You already stated that you are "not familiar with JavaScript functions and syntax". So how do you know what you want or need or what is a "more common way"? There are numerous ways to do what you are asking but it depends on the specifics of any given web page. I discussed a couple of them above based on what you provided. I even provided an example of one of the ways. But without seeing what you are working with, how is anyone supposed to help you learn how to resolve your specific issue? If you are going to be playing around with web pages, maybe you should spend a little more time learning those technologies. That way you can ask more informed questions, better understand the replies that you receive, and then ask more intelligent followup questions in order to learn how to do what it is you need/want to do.
    2 points
  2. Hello , I am trying to use Websockets in AutoIt. It is to fetch live stock market prices , API is provided and documentation available for python language. The link for the code snippet is : https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post https://github.com/symphonyfintech/xts-pythonclient-api-sdk Second Link is to subscribe to a list of ExchangeInstruments. Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know. I am able to use the WinHttp object to perform actions using simple codes like below : I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID. Below code is just for example of how I am using WinHttp. Unrelated to socket part. Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status But am struggling to understand and use socket. Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt. To connect and listen to a socket. Thanks a lot
    1 point
  3. @Norm73 I'm glad the changes indicated by LarsJ fixed the issue. As I like challenges, then I just scripted the fix in another way (no more StringInStr, all searches are done using RegEx, even when user chooses "Normal Search") and without touching $NM_CUSTOMDRAW or $WM_DRAWITEM code. Below is the code found in amended script "2m" which has just been updated accordingly. Other older scripts should be amended soon. Old code : ; Find rows matching the search string $g_iSearch = 0 If $sSearchHow = "RegEx search" Then For $i = 0 To $g_iRows - 1 ; duplicated For... Next for speed For $j = 0 To $g_iCols - 1 If StringRegExp($g_aArray[$i][$j], "(?i)" & $g_sSearch) Then For $k = 0 To $g_iCols - 1 $g_aSubArray[$g_iSearch][$k] = $g_aArray[$i][$k] Next $g_iSearch += 1 ContinueLoop 2 EndIf Next Next Else ; "Normal search" For $i = 0 To $g_iRows - 1 ; duplicated For... Next for speed For $j = 0 To $g_iCols - 1 If StringInStr($g_aArray[$i][$j], $g_sSearch) Then For $k = 0 To $g_iCols - 1 $g_aSubArray[$g_iSearch][$k] = $g_aArray[$i][$k] Next $g_iSearch += 1 ContinueLoop 2 EndIf Next Next EndIf New code : ; Find rows matching the search string $g_iSearch = 0 If $sSearchHow = "Normal search" Then ; all searches use RegEx => escape 12 + 1 metacharacters $g_sSearch = StringRegExpReplace($g_sSearch, "(\\|\.|\^|\$|\||\[|\(|\{|\*|\+|\?|\#|\))" , "\\$1") EndIf ; ConsoleWrite("$sSearchHow = " & $sSearchHow & @TAB & "$g_sSearch = " & $g_sSearch & @lf) For $i = 0 To $g_iRows - 1 For $j = 0 To $g_iCols - 1 If StringRegExp($g_aArray[$i][$j], "(?i)" & $g_sSearch) Then For $k = 0 To $g_iCols - 1 $g_aSubArray[$g_iSearch][$k] = $g_aArray[$i][$k] Next $g_iSearch += 1 ContinueLoop 2 EndIf Next Next The fix is based, when user chooses Normal search, in escaping all (eventual) 12 metacharacters indicated in AutoIt help file (topic StringRegExp) which are : \.^$|[({*+?# But I notice a 13th metacharacter indicated on PCRE web site (Perl Compatible Regular Expressions) and AutoIt uses the PCRE engine. This 13th meta is ")" and it's really a metacharacter that you can check after uncommenting a ConsoleWrite line in "2m" and create the array using the alternate line (also found in "2m") : ; ConsoleWrite("$sSearchHow = " & $sSearchHow & @TAB & "$g_sSearch = " & $g_sSearch & @lf) ... $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz") ; $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz" & "\.^$|[({*+?#)") ; 12 + 1 RegEx metacharacters ... Now if you search for ")" , without quotes of course, then no matches are found with "RegEx Search", which indicates (at least for me) that we just faced a metacharacter, because if you switch to "Normal Search", then ")" will appear in the results. Here is what ConsoleWrite will show : $sSearchHow = RegEx search $g_sSearch = ) $sSearchHow = Normal search $g_sSearch = \) The "." search (that revealed the issue) now works normally in amended "2m" ConsoleWrite : $sSearchHow = RegEx search $g_sSearch = . $sSearchHow = Normal search $g_sSearch = \. Concerning your other questions, I'll see what's doable when I have some time. Dinner time
    1 point
  4. Kudos for actually doing the work and trying different approaches on your own. Rare. As for your initial attempt, I think you were pretty close; the main prob i saw was that the Child was not reading from the Console and the Parent was not reading all the time from the child, and that you had commented out the StdOutWrite. See if this works for you, my changes are noted in the margin: Parent ;~~~~ parent #include <GUIConstantsEx.au3> #include <constants.au3> #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $FName = 'Child.exe' Global $Exepath = @ScriptDir & '\' & $FName Global $pid __gui1() Func __gui1() Local $hGUI = GUICreate("Gui 1", 180, 150, 100, 100) Local $idButton1 = GUICtrlCreateButton("Start", 10, 10, 80, 30) Local $idButton2 = GUICtrlCreateButton("Stop", 10, 50, 80, 30) Local $idLabel = GUICtrlCreateLabel('', 10, 90, 80, 50 ) Local $o_String GUICtrlSetState($idButton2, $GUI_DISABLE) GUISetState(@SW_SHOW, $hGUI) Local $aMsg While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop Case $idButton1 GUICtrlSetState($idButton1, $GUI_DISABLE) GUICtrlSetState($idButton2, $GUI_ENABLE) GUICtrlSetData($idLabel, 'process start') $o_String = '' $pid = Run($Exepath, '', '', $STDIN_CHILD + $STDOUT_CHILD) GUICtrlSetData($idLabel, $pid) Case $idButton2 GUICtrlSetState($idButton1, $GUI_ENABLE) GUICtrlSetState($idButton2, $GUI_DISABLE) GUICtrlSetData($idLabel, 'process stop') ;Run($Exepath & ' True') ;Jocko Delete StdinWrite($pid, 'True') ;Jocko Add ;If ProcessExists($pid) Then ;ProcessClose($pid) ;Endif ;$o_String = StdoutRead($pid) ;Jocko Delete ;ConsoleWrite( $o_String & @CRLF ) ;Jocko Delete EndSwitch EndSwitch $o_String = StdoutRead($pid) ;Jocko Add If $o_String Then ConsoleWrite( $o_String & @CRLF ) ;Jocko Add WEnd GUIDelete($hGUI) EndFunc Child ;~~~~ Child ;~ Instead of using hotkey ;~ I want to pass parameter from parent program HotKeySet("{ESC}", "__Flag") Global $bflag = False __Example() ;If ($CmdLine[0] = 0) Then __Example() ;If StringInStr($CmdLine[1], 'True') Then __Flag() ;not closing the program properly Func __Example() Local $i = 0 While 1 If $bflag = True Then __Terminate() ConsoleWrite( $i & @CRLF ) $i = $i + 1 Sleep(250) If ConsoleRead()='True' Then __Flag() ;Jocko Add WEnd EndFunc ;==>__Example Func __Flag() ConsoleWrite( ' ' & $bflag & @CRLF ) $bflag = True ConsoleWrite( ' ' & $bflag & @CRLF ) EndFunc ;==> __Flag() Func __Terminate() ConsoleWrite( ' The End ' & @CRLF ) Exit EndFunc ;==> __Terminate()
    1 point
  5. Like your other post: What exactly do you want to ask? Be way more explicit than this and show the full source that demonstrates your issue. Jos PS: for clarity: Have a look at the appropriate helpfile (AutoItX.chm) for the available functions in AutoItX!
    1 point
  6. Hello. You can use power of C# byte[] functions. Like: static void Main(string[] args) { var str = "Hello World"; var bytes = Encoding.ASCII.GetBytes(str); string hexstr = BitConverter.ToString(bytes); Console.WriteLine(hexstr.Replace("-","") + " = " + Encoding.ASCII.GetString(bytes)); Console.WriteLine("BinaryLen: " + (bytes.Length)); Console.WriteLine(""); //BinaryMid($dBinary, 1, 5) byte[] bytesMid = new byte[5]; Array.Copy(bytes,0, bytesMid, 0, bytesMid.Length); hexstr = BitConverter.ToString(bytesMid); Console.WriteLine("BinaryMid(bytes, 1, 5)"); Console.WriteLine(hexstr.Replace("-", "") +" = " + Encoding.ASCII.GetString(bytesMid)); Console.WriteLine("BinaryLen: " + (bytesMid.Length)); Console.WriteLine(""); //BinaryMid($dBinary, 7, 5) bytesMid = new byte[5]; Array.Copy(bytes, 6, bytesMid, 0, bytesMid.Length); hexstr = BitConverter.ToString(bytesMid); Console.WriteLine("BinaryMid(bytes, 7, 5)"); Console.WriteLine(hexstr.Replace("-", "") + " = " + Encoding.ASCII.GetString(bytesMid)); Console.WriteLine("BinaryLen: " + (bytesMid.Length)); Console.ReadKey(); } Saludos
    1 point
  7. Turn $sSearchHow into a global variable. And replace these lines: ; Subitem text and matching text Local $sSubItemText = $g_iSortDir = 0x0400 ? $g_aSubArray[$g_tIndex.arr($iItem + 1)][$g_iSearchCol] _ ; 0x0400 = $HDF_SORTUP : $g_aSubArray[$g_tIndex.arr($g_iSearch - $iItem)][$g_iSearchCol] Local $sMatch = StringRegExp( $sSubItemText, "(?i)" & $g_sSearch, 1 ), $extended = @extended, $iLen = StringLen( $sMatch[0] ) with these lines: ; Subitem text and matching text Local $sSubItemText = $g_iSortDir = 0x0400 ? $g_aSubArray[$g_tIndex.arr($iItem + 1)][$g_iSearchCol] _ ; 0x0400 = $HDF_SORTUP : $g_aSubArray[$g_tIndex.arr($g_iSearch - $iItem)][$g_iSearchCol], $sMatch, $extended, $iLen If $g_sSearchHow = "RegEx search" Then Local $aMatch = StringRegExp( $sSubItemText, "(?i)" & $g_sSearch, 1 ) $extended = @extended $sMatch = $aMatch[0] Else $iLen = StringLen( $g_sSearch ) Local $iPos = StringInStr( $sSubItemText, $g_sSearch ) $sMatch = StringMid( $sSubItemText, $iPos, $iLen ) $extended = $iPos + $iLen EndIf $iLen = StringLen( $sMatch )
    1 point
  8. Here we go, version "2m" #include <ComboConstants.au3> #include <EditConstants.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "RandomArray.au3" ; LarsJ #include "DrawItem.au3" ; " Opt("MustDeclareVars", 1) Global $g_iRows = 1000, $g_iCols = 6, $g_iLeftLV = 10, $g_iTopLV = 40, $g_hGui, $g_hListView, $g_hHeader, $g_hEdit Global $g_aCols = ["Strings", "Integers", "Floats", "Dates", "Times", "R/C"], $g_aWidths = [230, 61, 124, 70, 60, 60] Global $g_idListView, $g_idMarker, $g_idComboCol, $g_idComboColDummy, $g_idEditDummy Global $g_sSearch, $g_iSearchCol, $g_iSortDir, $g_iSearch = $g_iRows Global $g_aArray, $g_aSubArray, $g_tDefaultIndex, $g_tIndex = DllStructCreate("uint arr[" & $g_iRows & "]") Global $g_aIndex[$g_iCols], $g_aIndexTemp[$g_iCols] ; VarGetType's : $g_aIndex => "Array", $g_aIndex[0] => "String" Global $fListViewHasFocus = 1 ; trying this for now, we'll see... Example() Func Example() ; Generate array & one index _Generate_All($g_aArray) $g_aSubArray = $g_aArray $g_tDefaultIndex = $g_tIndex ; Create GUI $g_hGui = GUICreate("Virtual ListView + match all columns (2m)", 630 + 20, 788 + 30 + 20) ; Create Edit control (search) + dummy control Local $idEdit = GUICtrlCreateEdit("", 120, 10, 305, 20, BitXOR($GUI_SS_DEFAULT_EDIT, $WS_HSCROLL, $WS_VSCROLL)) $g_hEdit = GUICtrlGetHandle($idEdit) $g_idEditDummy = GUICtrlCreateDummy() ; Create ComboBox control (how to search : RegEx or Normal ?) Local $idSearchHow = GUICtrlCreateCombo("RegEx search", 11, 9, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) Local $sSearchHow = "RegEx search", $sSearchHowPrev = $sSearchHow ; default way of searching (changeable) GUICtrlSetData($idSearchHow, "Normal search", $sSearchHow) ; Create ComboBox control (column where to search) + dummy control GUICtrlCreateLabel("Col", 429, 10, 20, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) $g_idComboCol = GUICtrlCreateCombo("0", 452, 9, 41, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) $g_iSearchCol = 0 ; default column where to search (changeable) Local $iSearchColPrev = $g_iSearchCol For $i = 1 To $g_iCols - 1 GUICtrlSetData($g_idComboCol, $i & "|", $g_iSearchCol) Next $g_idComboColDummy = GUICtrlCreateDummy() ; Create Label control (number of matching results) Local $idResult = GUICtrlCreateLabel(" " & $g_iRows & " rows (no pattern)", 501, 10, 135, 20, BitOR($SS_CENTERIMAGE, $SS_SUNKEN)) ; Create ListView $g_idListView = GUICtrlCreateListView("", $g_iLeftLV, $g_iTopLV, 630, 788, BitOr($LVS_OWNERDATA, $LVS_OWNERDRAWFIXED), $WS_EX_CLIENTEDGE) _GUICtrlListView_SetExtendedListViewStyle($g_idListView, BitOr($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) $g_hListView = GUICtrlGetHandle($g_idListView) $g_hHeader = _GUICtrlListView_GetHeader($g_idListView) For $i = 0 To $g_iCols - 1 _GUICtrlListView_AddColumn($g_idListView, $g_aCols[$i], $g_aWidths[$i]) Next ; Create Marker (an orange line placed above the header of the column being searched) $g_idMarker = GUICtrlCreateLabel("", 0, 0) GUICtrlSetBkColor(-1, 0xFFA060) ; orange _MoveMarker($g_iSearchCol) _GUICtrlListView_SetSelectedColumn($g_idListView, $g_iSearchCol) ; Sorting information $g_iSortDir = 0x0400 ; $HDF_SORTUP Local $iSortCol = -1, $iSortColPrev = -1 GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; for LV header only GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUICtrlSendMsg($g_idListView, $LVM_SETITEMCOUNT, $g_iRows, 0) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $g_idComboCol, $g_idComboColDummy, $idSearchHow $g_iSearchCol = GUICtrlRead($g_idComboCol) $sSearchHow = GUICtrlRead($idSearchHow) Select Case $g_iSearchCol <> $iSearchColPrev _MoveMarker($g_iSearchCol) ; Search column will be selected below, after ContinueCase $iSearchColPrev = $g_iSearchCol Case $sSearchHow <> $sSearchHowPrev $sSearchHowPrev = $sSearchHow Case Else ; no change in both Combo controls (same search column, same search way) ContinueLoop EndSelect ContinueCase Case $g_idEditDummy _GUICtrlHeader_SetItemFormat($g_hHeader, $iSortCol, $HDF_STRING) $g_sSearch = GUICtrlRead($idEdit) $g_tIndex = $g_tDefaultIndex If $g_sSearch = "" Then ; Empty search string, display all rows $g_aSubArray = $g_aArray $g_iSearch = $g_iRows Else ; Find rows matching the search string $g_iSearch = 0 If $sSearchHow = "Normal search" Then ; all searches use RegEx => escape 12 + 1 metacharacters $g_sSearch = StringRegExpReplace($g_sSearch, "(\\|\.|\^|\$|\||\[|\(|\{|\*|\+|\?|\#|\))" , "\\$1") EndIf ; ConsoleWrite("$sSearchHow = " & $sSearchHow & @TAB & "$g_sSearch = " & $g_sSearch & @lf) For $i = 0 To $g_iRows - 1 For $j = 0 To $g_iCols - 1 If StringRegExp($g_aArray[$i][$j], "(?i)" & $g_sSearch) Then For $k = 0 To $g_iCols - 1 $g_aSubArray[$g_iSearch][$k] = $g_aArray[$i][$k] Next $g_iSearch += 1 ContinueLoop 2 EndIf Next Next ; Delete eventual temporary subindexes For $i = 0 To $g_iCols - 1 If VarGetType($g_aIndexTemp[$i]) = "DLLStruct" Then $g_aIndexTemp[$i] = "" ; "String" Next EndIf GUICtrlSetData($idResult, " " & $g_iSearch & ($g_sSearch = "" ? " rows (no pattern)" : " matching rows")) GUICtrlSendMsg($g_idListView, $LVM_SETITEMCOUNT, $g_iSearch, 0) _GUICtrlListView_SetSelectedColumn($g_hListView, $g_iSearchCol) ; seems ok here (after $LVM_SETITEMCOUNT) Case $g_idListView ; Sort $iSortCol = GUICtrlGetState($g_idListView) If $iSortCol <> $iSortColPrev Then _GUICtrlHeader_SetItemFormat($g_hHeader, $iSortColPrev, $HDF_STRING) EndIf ; Set $g_tIndex + eventual update of $g_aIndexTemp[$iSortCol] OR $g_aIndex[$iSortCol] If GUICtrlRead($idEdit) Then _UpdateIndex($g_aIndexTemp, $iSortCol) Else _UpdateIndex($g_aIndex, $iSortCol) EndIf $g_iSortDir = (($iSortCol = $iSortColPrev) ? ($g_iSortDir = $HDF_SORTUP ? $HDF_SORTDOWN : $HDF_SORTUP) : ($HDF_SORTUP)) _GUICtrlHeader_SetItemFormat($g_hHeader, $iSortCol, $HDF_STRING + $g_iSortDir) GUICtrlSendMsg($g_idListView, $LVM_SETSELECTEDCOLUMN, $iSortCol, 0) GUICtrlSendMsg($g_idListView, $LVM_SETITEMCOUNT, $g_iSearch, 0) $iSortColPrev = $iSortCol Case $GUI_EVENT_RESTORE ; needed, or Marker goes back in 0, 0 after Restore (why ?) _MoveMarker($g_iSearchCol) EndSwitch WEnd ; Cleanup GUIDelete($g_hGui) EndFunc ;==>Example ;======================================================================== Func WM_DRAWITEM( $hWnd, $iMsg, $wParam, $lParam ) ; Display items in an owner drawn ListView Local Static $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ), $tSize = DllStructCreate( $tagSIZE ) Local Static $hBrushYellow = _WinAPI_CreateSolidBrush( 0xFFFF00 ), $hBrushCyan = _WinAPI_CreateSolidBrush( 0x00FFFF ) ; Yellow and cyan, BGR Local Static $hBrushHighLight = _WinAPI_GetSysColorBrush( $COLOR_HIGHLIGHT ), $hBrushButtonFace = _WinAPI_GetSysColorBrush( $COLOR_BTNFACE ) ; We can optimize code by removing Switch statements because the ListView is the only ownerdrawn control and only $ODA_DRAWENTIRE actions are present Local $tDrawItem = DllStructCreate( $tagDRAWITEM, $lParam ), $itemID = DllStructGetData( $tDrawItem, "itemID" ), $iState = DllStructGetData( $tDrawItem, "itemState" ), $hDC = DllStructGetData( $tDrawItem, "hDC" ), $sItemText ; Loop through columns ($i is the column index) For $i = 0 To $g_iCols - 1 ; Subitem rectangle DllStructSetData( $tRect, 2, $i ) ; Top DllStructSetData( $tRect, 1, $LVIR_BOUNDS ) ; Left GUICtrlSendMsg( $g_idListView, $LVM_GETSUBITEMRECT, $itemID, $pRect ) DllStructSetData( $tRect, 1, DllStructGetData( $tRect, 1 ) + 6 ) ; Left margin DllStructSetData( $tRect, 2, DllStructGetData( $tRect, 2 ) + 2 ) ; Top margin ; Subitem background and text color If BitAND( $iState, $ODS_SELECTED ) Then DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $fListViewHasFocus = 1 ? $hBrushHighLight : $hBrushButtonFace ) ; _WinAPI_FillRect DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int", BitAND( $iState, $ODS_SELECTED ) ? $fListViewHasFocus = 1 ? 0xFFFFFF : 0x000000 : 0x000000 ) ; _WinAPI_SetTextColor ; Draw subitem text If $g_iSortDir = 0x0400 Then ; 0x0400 = $HDF_SORTUP $sItemText = $g_aSubArray[$g_tIndex.arr($itemID + 1)][$i] Else $sItemText = $g_aSubArray[$g_tIndex.arr($g_iSearch - $itemID)][$i] EndIf DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tRect, "uint", 0 ) ; _WinAPI_DrawText ; Mark matching substring if found in ANY column If $g_sSearch Then Local $sMatch = StringRegExp( $sItemText, "(?i)" & $g_sSearch, 1 ) If Not @error Then ; match found Local $extended = @extended, $iLen = StringLen( $sMatch[0] ) ; Rectangle for matching substring DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sItemText, "int", $extended - $iLen - 1, "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + DllStructGetData( $tSize, "X" ) ) DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sMatch[0], "int", $iLen, "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 DllStructSetData( $tRect, "Right", DllStructGetData( $tRect, "Left" ) + DllStructGetData( $tSize, "X" ) ) ; Fill rectangle with yellow or cyan (selected) background color DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", BitAND( $iState, $ODS_SELECTED ) ? $hBrushCyan : $hBrushYellow ) ; _WinAPI_FillRect ; Draw matching substring in rectangle DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int", 0x000000 ) ; _WinAPI_SetTextColor DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sMatch[0], "int", $iLen, "struct*", $tRect, "uint", 0 ) ; _WinAPI_DrawText EndIf EndIf Next Return $GUI_RUNDEFMSG #forceref $hWnd, $iMsg, $wParam EndFunc ;======================================================================== Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) Switch HWnd(DllStructGetData($tNMHEADER, "hWndFrom")) Case $g_hHeader Local $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_ENDTRACKW _MoveMarker(GUICtrlRead($g_idComboCol)) Case $HDN_DIVIDERDBLCLICKW Local $iCol = DllStructGetData($tNMHEADER, "Item") _GUICtrlListView_SetColumnWidth($g_idListView, $iCol, $g_aWidths[$iCol]) ; initial size _MoveMarker(GUICtrlRead($g_idComboCol)) Case $NM_RCLICK Local $aHit = _GUICtrlListView_SubItemHitTest($g_hListView) ; $aHit[1] : 0-based index of the LV subitem... i.e. the column in our case (may be -1 if right click on empty part of header) If $aHit[1] > - 1 Then ; valid column GUICtrlSetData($g_idComboCol, $aHit[1]) GUICtrlSendToDummy($g_idComboColDummy) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;======================================================================== Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $hWndFrom = $lParam Local $iCode = BitShift($wParam, 16) ; High word Switch $hWndFrom Case $g_hEdit Switch $iCode Case $EN_CHANGE GUICtrlSendToDummy($g_idEditDummy) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND ;======================================================================== Func _Generate_All(ByRef $g_aArray) ConsoleWrite("$g_iRows = " & $g_iRows & " $g_iCols = " & $g_iCols & @CRLF) Local $hTimer = TimerInit() $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz") ; $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz" & "\.^$|[({*+?#)") ; 12 + 1 RegEx metacharacters For $i = 0 To $g_iRows - 1 $g_tIndex.arr($i + 1) = $i Next ConsoleWrite("Generating array & one index = " & TimerDiff($hTimer) & @CRLF & @CRLF) EndFunc ;==>_Generate_All ;======================================================================== Func _SortArrayStruct(Const ByRef $aArray, $iCol, $iRows) Local $tIndex = DllStructCreate("uint arr[" & $iRows & "]") Local $pIndex = DllStructGetPtr($tIndex) Local Static $hDll = DllOpen("kernel32.dll") Local Static $hDllComp = DllOpen("shlwapi.dll") Local $lo, $hi, $mi, $r ; Sorting by one column For $i = 1 To $iRows - 1 $lo = 0 $hi = $i - 1 Do $mi = Int(($lo + $hi) / 2) $r = DllCall($hDllComp, 'int', 'StrCmpLogicalW', 'wstr', $aArray[$i][$iCol], 'wstr', $aArray[DllStructGetData($tIndex, 1, $mi + 1)][$iCol])[0] Switch $r Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ExitLoop EndSwitch Until $lo > $hi DllCall($hDll, "none", "RtlMoveMemory", "struct*", $pIndex + ($mi + 1) * 4, "struct*", $pIndex + $mi * 4, "ulong_ptr", ($i - $mi) * 4) DllStructSetData($tIndex, 1, $i, $mi + 1 + ($lo = $mi + 1)) Next Return $tIndex EndFunc ;==>_SortArrayStruct ;======================================================================== Func _UpdateIndex(ByRef $aIndex, $iCol) If VarGetType($aIndex[$iCol]) = "DLLStruct" Then $g_tIndex = $aIndex[$iCol] Else $g_tIndex = _SortArrayStruct($g_aSubArray, $iCol, $g_iSearch) $aIndex[$iCol] = $g_tIndex ; "DLLStruct" (or "Int32" when no match found +++) EndIf EndFunc ;==>_UpdateIndex ;======================================================================== Func _MoveMarker($iCol) Local $aRect = _GUICtrlHeader_GetItemRect($g_hHeader, $iCol) ControlMove($g_hGui, "", $g_idMarker, $g_iLeftLV + $aRect[0], $g_iTopLV - 3, $aRect[2] - $aRect[0] + 1, 3) EndFunc ;==>_MoveMarker Many controls become irrelevant (combo to switch columns, orange marker, right click on headers etc...) because the number of matched rows is now the same, no matter the searched column. Anyway I'm keeping all controls untouched, better have more than less More important : something has to be improved in all these scripts (even LarsJ got the same problem, just tested). I'll prepare a new post to indicate the issue. Edit: update May 24th 2021 : fixed 'Normal Search' which includes RegEx metacharacters, for example a "." search in Normal search now returns correct matches (pic below)
    1 point
  9. Have you looked at @FireFox's example?
    1 point
  10. I have re-written this recently, it turns out that I made it MUCH harder than it should have been. Melba23 pointed out FileGetTime, and I am still not quite sure how I missed it while looking through the help file Switching isn't really "recommended" as the original worked well, but this one is definitely a lot simpler! Be warned though that the syntax has changed slightly due to the functions in Date.au3 having different values used for Create, Access, and Modify. Enjoy Ian Func _CompareFileTimeEx($hSource, $hDestination, $iMethod) ;Parameters ....: $hSource - Full path to the first file ; $hDestination - Full path to the second file ; $iMethod - 0 The date and time the file was modified ; 1 The date and time the file was created ; 2 The date and time the file was accessed ;Return values .: -1 The Source file time is earlier than the Destination file time ; 0 The Source file time is equal to the Destination file time ; 1 The Source file time is later than the Destination file time ;Author ........: Ian Maxwell (llewxam @ AutoIt forum) $aSource = FileGetTime($hSource, $iMethod, 0) $aDestination = FileGetTime($hDestination, $iMethod, 0) For $a = 0 To 5 If $aSource[$a] <> $aDestination[$a] Then If $aSource[$a] < $aDestination[$a] Then Return -1 Else Return 1 EndIf EndIf Next Return 0 EndFunc ;==>_CompareFileTimeEx edit: Oh, one nice improvement is that no other Includes are needed any more, so another plus for simplicity....
    1 point
×
×
  • Create New...