david1337 Posted October 21, 2015 Share Posted October 21, 2015 (edited) Hi guysI have this script, that searches for all txt files in a given Dir, and shows the content (names) in a row for each txt file.Would it be possible to add a search box at the bottom, where you can search for one of the names, and then it would highlight that name with a color in the rows.Same name can be present multiple times in different rows.Where do I begin? Thanks! :-) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $g_hListView Call("ListNames") Func ListNames() Local $hGUI, $hImage $hGUI = GUICreate("Listview", 500, 400) Local $sDirPath = "C:\Temp" $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 494, 368) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, $LVS_EX_GRIDLINES) GUISetState(@SW_SHOW) Local $aFiles = _FileListToArray($sDirPath, "*.txt") ;~ _ArrayDisplay($aFiles) Local $n For $i = 1 To $aFiles[0] $tmp = _FileCountLines($sDirPath & "\" & $aFiles[$i]) $n = ($n<$tmp) ? $tmp : $n Next For $i = 0 To $n _GUICtrlListView_AddItem($g_hListView, "") Next Local $aString = 0 For $i = 1 To $aFiles[0] _GUICtrlListView_AddColumn($g_hListView, StringTrimRight($aFiles[$i], 4), 100) $aString = FileReadToArray($sDirPath & "\" & $aFiles[$i]) If $i = 1 Then For $x = 0 To UBound($aString) - 1 _GUICtrlListView_SetItemText($g_hListView, $x, $aString[$x]) Next Else For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddSubItem($g_hListView, $x, $aString[$x], $i - 1) Next EndIf Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>ListNames Edited October 22, 2015 by david1337 Link to comment Share on other sites More sharing options...
JohnOne Posted October 21, 2015 Share Posted October 21, 2015 Where do I begin? $hcInput = GuiCtrlCreateInput(...) $sSearchFor = GuiCtrlRead($hcInput) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 (edited) Hi JohnOneThanks for your answer. That got me started.I now have the search bar at the bottom, as I wanted.How can I make it highlight the name I write, with a given color?Is it required that I have an "OK" button or something, to start the actual search? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $g_hListView Call("ListNames") Func ListNames() Local $hGUI, $hImage $hGUI = GUICreate("Listview", 500, 400) ;Places the search bar $hcInput = GUICtrlCreateInput("", 150, 375, 200, 20) $sSearchFor = GuiCtrlRead($hcInput) ;___________________________________________________ Local $sDirPath = "C:\temp" $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 494, 368) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, $LVS_EX_GRIDLINES) GUISetState(@SW_SHOW) Local $aFiles = _FileListToArray($sDirPath, "*.txt") GUISetState(@SW_SHOW) Local $n For $i = 1 To $aFiles[0] $tmp = _FileCountLines($sDirPath & "\" & $aFiles[$i]) $n = ($n<$tmp) ? $tmp : $n Next For $i = 0 To $n _GUICtrlListView_AddItem($g_hListView, "") Next Local $aString = 0 For $i = 1 To $aFiles[0] _GUICtrlListView_AddColumn($g_hListView, StringTrimRight($aFiles[$i], 4), 100) $aString = FileReadToArray($sDirPath & "\" & $aFiles[$i]) If $i = 1 Then For $x = 0 To UBound($aString) - 1 _GUICtrlListView_SetItemText($g_hListView, $x, $aString[$x]) Next Else For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddSubItem($g_hListView, $x, $aString[$x], $i - 1) Next EndIf Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>ListNames Edited October 22, 2015 by david1337 Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 Yes you will need a button, make it the default button so pressing enter on input will trigger the same function the button does.This is basic stuff, I'm surprised after 3 years here you don't know how.Changing the individual row colour of a listview control is a little more convoluted, but there are examples around the forum you can search. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 (edited) JohnOneDon't get me wrong, I do know how to make the button. My question was whether it was a MUST, or if the search could work while typing the name.Say I wrote "J", then it highlighted J with yellow. Then "Jo", and only Jo was highlighted etc.Thanks for your time, I will search the forum.Btw: I could have just created my account 3 years ago, to get help with some mouse movement, and then come back 3 years later and ask for help with more advanced stuff Edited October 22, 2015 by david1337 Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 I understand.I just gathered from your positioning of the functions I offered in your new code that did not now how to use a button and get the text of input box after pressing it. For the record you placed it incorrectly.You do not absolutely need a button, you are right about that, but once again I try to answer based on the level I deduce from the askee, a button is the simplest way you see. david1337 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 I was looking to colour listview cells myself not so long agao.Here is the thread which has some great answers toward the end of page 1. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 Thanks mate, I appreciate it! Link to comment Share on other sites More sharing options...
Danyfirex Posted October 22, 2015 Share Posted October 22, 2015 I wrote this example.expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $g_hListView, $hGUI, $g_SearchInput Call("ListNames") Func ListNames() Local $hImage, $btnSearch $hGUI = GUICreate("Listview", 500, 420) Local $sDirPath = "C:\Test" $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 494, 368, $LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, $LVS_EX_GRIDLINES) GUICtrlCreateLabel("Search For: ", 20, 385) $g_SearchInput = GUICtrlCreateInput("", 100, 380, 100, 22) $btnSearch = GUICtrlCreateButton("Highlight", 220, 380) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Local $aFiles = _FileListToArray($sDirPath, "*.txt") ;~ _ArrayDisplay($aFiles) Local $n For $i = 1 To $aFiles[0] $tmp = _FileCountLines($sDirPath & "\" & $aFiles[$i]) $n = ($n < $tmp) ? $tmp : $n Next For $i = 0 To $n _GUICtrlListView_AddItem($g_hListView, "") Next Local $aString = 0 For $i = 1 To $aFiles[0] _GUICtrlListView_AddColumn($g_hListView, StringTrimRight($aFiles[$i], 4), 100) $aString = FileReadToArray($sDirPath & "\" & $aFiles[$i]) If $i = 1 Then For $x = 0 To UBound($aString) - 1 _GUICtrlListView_SetItemText($g_hListView, $x, $aString[$x]) Next Else For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddSubItem($g_hListView, $x, $aString[$x], $i - 1) Next EndIf Next Local $idMsg = 0 While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE GUIDelete() Exit Case $idMsg = $btnSearch _GUICtrlListView_RedrawItems($g_hListView, 0, _GUICtrlListView_GetItemCount($g_hListView)) EndSelect WEnd EndFunc ;==>ListNames Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $g_hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iColor = RGB2BGR(0xffffff) If GUICtrlRead($g_SearchInput) <> "" Then If _GUICtrlListView_GetItemText($g_hListView, $iItem, $iSubItem) = GUICtrlRead($g_SearchInput) Then $iColor = RGB2BGR(0x00ff00) EndIf EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc ;==>RGB2BGR _WinAPI_SetWindowsHookExSaludos david1337 and JohnOne 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 Danyfirex,you sure did mate! and NO WAY.. you just created the search button..!How bad ass are you? So the GUIRegisterMsg refers to the new func, in which the highlight part, color code etc. is defined. The whole DllStruct part I have clue what does.Anyway, can't thank you enough!Saludos! Skysnake 1 Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 You could hit the like button on his post. Danyfirex 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 Ahh is it the like button that raises a users reputation? Link to comment Share on other sites More sharing options...
Danyfirex Posted October 22, 2015 Share Posted October 22, 2015 Danyfirex,you sure did mate! and NO WAY.. you just created the search button..!How bad ass are you? So the GUIRegisterMsg refers to the new func, in which the highlight part, color code etc. is defined. The whole DllStruct part I have clue what does.Anyway, can't thank you enough!Saludos!You're Wellcome.You could hit the like button on his post.hahaha nice comment. Ahh is it the like button that raises a users reputation?Probably. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 Ahh is it the like button that raises a users reputation?Not sure about reputation, but shows you like what someone wrote, especially if they helped you out. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 And there is nothing I'd like more than to show my appreciation I'm amazed about the Autoit Forum in general. Haven't seen such a dedicated and helpful community elsewhere. Danyfirex and JohnOne 2 Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 That's nice.Here, have your first AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 Oh my god, I have a +1 reputation! thanks John haha! Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 +2 ! Okay I'll stop now, before I get in trouble with Melba for going off topic :D Link to comment Share on other sites More sharing options...
JohnOne Posted October 22, 2015 Share Posted October 22, 2015 I pooped your cherry.Don't tell the missus that.She wouldn't understand. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
david1337 Posted October 22, 2015 Author Share Posted October 22, 2015 (edited) That's just... weird John Edited October 23, 2015 by david1337 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now