KickStarter15 Posted February 7, 2017 Share Posted February 7, 2017 (edited) Hi Experts, I need help in viewing the content of selected item in listbox and content must be viewed it in EditBox when user select on it. I tried searching in help but I only found the below: $path1 = "D:\Programs\Test\Items" Local Const $sFilePath = $path1&"\kickstart_Test" Local $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox("", "", "An error occurred when reading the file.") Return False EndIf Local $sFileRead = FileRead($hFileOpen) ; Close the handle returned by FileOpen. FileClose($hFileOpen) $Edit1 = GUICtrlCreateEdit($sFileRead, 19, 165, 800, 400) GUICtrlSetData($Edit1, $sFileRead) GUICtrlSetFont(-1, 9, 700) The help fileread() works perfectly but my problem is, when selecting item in listbox I can't get it viewed in edit box. Need help guys. I have attached a sample screenshot for reference. Thanks in advance guys. Edited February 21, 2017 by KickStarter15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
careca Posted February 7, 2017 Share Posted February 7, 2017 We'd like the full script, if possible, something we can test. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Subz Posted February 7, 2017 Share Posted February 7, 2017 Can you post all your code, will help to modify existing code rather than recreating. Link to comment Share on other sites More sharing options...
careca Posted February 7, 2017 Share Posted February 7, 2017 hahaha same time Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 7, 2017 Author Share Posted February 7, 2017 This is what I have so far, but only for this part. other functions are working as required. Apology with my scripting, quite new to autoit. expandcollapse popup#Include <file.au3> #include <Array.au3> #include <GuiConstants.au3> #include <FileConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $path = "D:\Programs\Test\Items" $search = FileFindFirstFile($path&"\*.*") Local $Count=0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Count+=1 WEnd FileClose($search) $Form1 = GUICreate("Instruction for " & @UserName, 500, 500, 50, 50) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore") $ListBox = GUICtrlCreateList("", 19, 50, 450, 110) Local $FileList = _FileListToArray($path, "*.*") For $i = 1 To $FileList[0] GUICtrlSetData($ListBox, $FileList[$i]) Next $Count1 = 0 $ViewItems = GUICtrlCreateLabel("View Items " &"["&$Count&"]", 20, 15, 110, 20) GUICtrlSetOnEvent(-1, "ViewItemsClick") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(1000) WEnd Func ViewItemsClick() $path1 = "D:\Programs\Test\Items" Local Const $sFilePath = $path1&"\kickstart_Test" Local $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox("", "", "An error occurred when reading the file.") Return False EndIf Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) $Edit1 = GUICtrlCreateEdit($sFileRead, 19, 165, 450, 300) GUICtrlSetData($Edit1, $sFileRead) EndFunc Func Form1Close() Exit EndFunc The script in ViewItemsClick() is the one that needs to be changed. It should be, when selecting item in listbox, it should view the content of that item in edit box, but not sure how. Thanks for helping guys. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 7, 2017 Author Share Posted February 7, 2017 Here are sample items that should be shown in listbox and the content must be viewed in edit box. kickstart_Test kickstart_Test 02,06,2017 20,55 Monday Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Subz Posted February 7, 2017 Share Posted February 7, 2017 (edited) Here is a ListView Script that does something similar, if you click on an item it will show in the editbox if you double click it will open with a text editor associated to .txt files. expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $idListview, $idEdit Global $sFilePath = 'D:\Programs\Test\Items' Example() Func Example() Local $aFileList = _FileListToArrayRec($sFilePath, '*', 1, 0, 0, 1) If @error Then Exit GUICreate("ListView Add Array", 400, 300) $idListview = GUICtrlCreateListView('Filename', 2, 2, 394, 168, $LVS_NOCOLUMNHEADER) For $i = 1 To $aFileList[0] GUICtrlCreateListViewItem($aFileList[$i], $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE) $idEdit = GUICtrlCreateEdit('', 2, 180, 394, 110) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $hFileRead, $sFileRead ; Local $tBuffer $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $idListview Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sFileRead = FileRead($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) GUICtrlSetData($idEdit, $sFileRead) Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ShellExecute($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited February 7, 2017 by Subz Updated Code KickStarter15 1 Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 7, 2017 Author Share Posted February 7, 2017 @Subz, Thank you for your suggestion but I tried it and it is not what I expected. I just need to read the content in the listbox and show the content of that item in edit box. Like showing the details when selecting a list. Thanks. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Subz Posted February 7, 2017 Share Posted February 7, 2017 So it didn't write the text file contents into the editbox? Link to comment Share on other sites More sharing options...
Subz Posted February 7, 2017 Share Posted February 7, 2017 Have updated the code above to work with the files you attached. Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 8, 2017 Author Share Posted February 8, 2017 @Subz, Greate work on this, it worked as desired. Thanks a lot subz for your help. Perfect.......! I know someone in this forum has skills in sharing ideas. Many thanks @Subz... Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 8, 2017 Author Share Posted February 8, 2017 @Subz, Sorry to loop back again in this thread but I've noticed that the code you gave will continue adding items when clicking view items. Try below tested code and click view items. expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <FileConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $path = "D:\Programs\Test\Items" $search = FileFindFirstFile($path&"\*.*") Local $Count=0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Count+=1 WEnd FileClose($search) $Form1 = GUICreate("Instruction for " & @UserName, 500, 500, 50, 50) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore") $ViewItems = GUICtrlCreateLabel("View Items " &"["&$Count&"]", 20, 15, 110, 20) GUICtrlSetOnEvent(-1, "ViewItemsClick") $idListview = GUICtrlCreateListView('Filename', 19, 50, 450, 110, $LVS_NOCOLUMNHEADER) $idEdit = GUICtrlCreateEdit('', 19, 165, 450, 300) $path1 = "D:\Programs\Test\Items" GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func ViewItemsClick() Local $aFileList = _FileListToArray($path1, '*', 1) If @error Then Exit For $i = 1 To $aFileList[0] GUICtrlCreateListViewItem($aFileList[$i], $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $hFileRead, $sFileRead ; Local $tBuffer $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $idListview Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sFileRead = FileRead($path1 & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) GUICtrlSetData($idEdit, $sFileRead) Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ShellExecute($path1 & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func Form1Close() Exit EndFunc Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Subz Posted February 8, 2017 Share Posted February 8, 2017 Just need to add _GUICtrlListView_DeleteAllItems at the top of the function for example: Func ViewItemsClick() _GUICtrlListView_DeleteAllItems($idListview) You really shouldn't mix GuiOnEventMode with GuiGetMsg, I would have just written it like this: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <FileConstants.au3> #Region ### START Koda GUI section ### Form= Global $sFilePath = "D:\Programs\Test\Items" $Form1 = GUICreate("Instruction for " & @UserName, 500, 500, 50, 50, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $ViewItems = GUICtrlCreateLabel("View Items " &"["&ViewItemsClick(True)&"]", 20, 15, 110, 20) $idListview = GUICtrlCreateListView('Filename', 19, 50, 450, 110, $LVS_NOCOLUMNHEADER) $idEdit = GUICtrlCreateEdit('', 19, 165, 450, 300) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $ViewItems ViewItemsClick() EndSwitch WEnd Func ViewItemsClick($bCount = False) Local $aFileList = _FileListToArray($sFilePath, '*', 1) If @error Then Exit If $bCount Then Return $aFileList[0] _GUICtrlListView_DeleteAllItems($idListview) For $i = 1 To $aFileList[0] GUICtrlCreateListViewItem($aFileList[$i], $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE) EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $hFileRead, $sFileRead ; Local $tBuffer $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $idListview Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sFileRead = FileRead($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) GUICtrlSetData($idEdit, $sFileRead) Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ShellExecute($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc KickStarter15 1 Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 8, 2017 Author Share Posted February 8, 2017 14 minutes ago, Subz said: You really shouldn't mix GuiOnEventMode with GuiGetMsg, I would have just written it like this: Thanks Subz, this adds me another learning from you on how to handle scripting in autoit. Now I'm beginning to learn more about autoit. Thanks a lot. 16 minutes ago, Subz said: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <FileConstants.au3> #Region ### START Koda GUI section ### Form= Global $sFilePath = "D:\Programs\Test\Items" $Form1 = GUICreate("Instruction for " & @UserName, 500, 500, 50, 50, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $ViewItems = GUICtrlCreateLabel("View Items " &"["&ViewItemsClick(True)&"]", 20, 15, 110, 20) $idListview = GUICtrlCreateListView('Filename', 19, 50, 450, 110, $LVS_NOCOLUMNHEADER) $idEdit = GUICtrlCreateEdit('', 19, 165, 450, 300) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $ViewItems ViewItemsClick() EndSwitch WEnd Func ViewItemsClick($bCount = False) Local $aFileList = _FileListToArray($sFilePath, '*', 1) If @error Then Exit If $bCount Then Return $aFileList[0] _GUICtrlListView_DeleteAllItems($idListview) For $i = 1 To $aFileList[0] GUICtrlCreateListViewItem($aFileList[$i], $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE) EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $hFileRead, $sFileRead ; Local $tBuffer $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $idListview Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sFileRead = FileRead($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) GUICtrlSetData($idEdit, $sFileRead) Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ShellExecute($sFilePath & '\' & _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"))) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc This really helps me a lot Subz... Perfectly I wanted to happened in my scripting. Thank you so much Subz for your help. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. 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