JonBMN Posted April 19, 2013 Posted April 19, 2013 (edited) I'm trying to make it so that when I double click an item in my $List1 listbox, it will bring up a GUI window that reads all the .log values into the variable and then displays it in another list inside that child window. It should open a .log file that starts with the computer name ($compName) & ".log". Then read all the lines into a variable called $fread which then after its done reading into the variable it would then put that variable's value inside the list. Then close the file. Do I have the logic correct for doing this. Would my $List1 that I double click have to be able to edit, because that list is $ES_READONLY. ::Here is the GUIRegisterMsg and WM_COMMAND function that I'd like some help with:: GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $Child, $lb, $fopen, $fclose, $fread, $count, $i $iIDFrom = BitAND($wParam, 0xFFFF) ; low word $iCode = BitShift($lParam, 16) ; high word Switch $iCode Case $LBN_DBLCLK ;sent when user double-clicks a string in the list box Switch $iIDFrom Case $List1 $index = _GUICtrlListBox_GetCaretIndex($List1) $sText = _GUICtrlListBox_GetText($List1, $index) $Child = GUICreate($compName, 600, 500, -1, -1, -1, -1, $GUIhandle) $fopen = FileOpen($compName & ".log", 0) $count = _FileCountLines($fopen) for $i = 0 To $count Step 1 $fread &= FileReadLine($fopen, $i) & @CRLF Next $lb = GUICtrlCreateList("", 10, 10, 580, 480, BitOr($WS_BORDER, $WS_VSCROLL), $ES_READONLY) GUICtrlSetData($lb, $fread) $fclose = FileClose($fopen) EndSelect EndSelect EndFunc Edited April 22, 2013 by JonBMN
Moderators Melba23 Posted April 19, 2013 Moderators Posted April 19, 2013 JonBMN, Pretty close - take a look at this to see how I would do it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> #include <EditConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 300, 300, BitOr($WS_BORDER, $WS_VSCROLL)) ConsoleWrite($cList & @CRLF) $sData = "" For $i = 1 To 20 $sData &= "|" & "Line " & $i Next GUICtrlSetData($cList, $sData) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $iCode Case $LBN_DBLCLK Switch $iIDFrom Case $cList $sData = GUICtrlRead($cList) ; Use the native function $sFile = FileRead(@ScriptFullPath) ; Read the file $hChild_1 = GUICreate($sData & " - List", 500, 500, 0, 0, Default, Default, $hGUI) $sLines = StringReplace($sFile, @CRLF, "|") ; Replace the EOL with "|" $cList_1 = GUICtrlCreateList("", 10, 10, 480, 480, BitOr($WS_BORDER, $WS_VSCROLL)) GUICtrlSetData($cList_1, $sLines) ; Add to list GUISetState() ; But why not use an edit - it is much simpler $hChild_1 = GUICreate($sData & " - Edit", 500, 500, 600, 0, Default, Default, $hGUI) $cEdit_2 = GUICtrlCreateEdit("", 10, 10, 480, 480, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) GUICtrlSetData($cEdit_2, $sFile) GUISetState() ControlSend($hChild_1, "", $cEdit_2, "^{HOME}") ; This unselects the text EndSwitch EndSwitch EndFunc Obviously I am reading a different file, but the principles are the same. And lists are by definition "ReadOnly" - but you have to specify the style for an edit. All clear? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
JonBMN Posted April 19, 2013 Author Posted April 19, 2013 Thank you very much Melba, also I have to agree the edit control would be the best practice for what I'm trying to do. Once I get it implemented I will post code and post errors if I have any.
JonBMN Posted April 22, 2013 Author Posted April 22, 2013 (edited) How would you get it to open a specific Item on double click? I have a list of 3 values yet when I double click it all it brings up is nothing and not the name & ".log" $sFile = FileRead($compName & ".log") ; Read the file Edited April 22, 2013 by JonBMN
Moderators Melba23 Posted April 22, 2013 Moderators Posted April 22, 2013 JonBMN,Rather difficult to say from just that small snippet, but I would hazard a guess that you need to add a path in there so that the FileRead function knows where to look - at the moment you are most likely assuming that the file is in the same folder as the script. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
JonBMN Posted April 22, 2013 Author Posted April 22, 2013 (edited) The file is absolutely in the same folder, I'm just having trouble getting the correct name from my double click. Is there anyway to take that double click on the certain value that I selected and include that into the FileRead? P.S these list values can change so I cannot hardcode a path Edited April 22, 2013 by JonBMN
JonBMN Posted April 22, 2013 Author Posted April 22, 2013 I actually just solved the problem $sData = GUICtrlRead($List1) ; Use the native function $sFile = FileRead($sData & ".log") ; Read the file
Moderators Melba23 Posted April 22, 2013 Moderators Posted April 22, 2013 JonBMN, It does help if you actually read the value selected in the list. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
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