Razormaul Posted October 22, 2013 Share Posted October 22, 2013 (edited) Hey all. I am trying to display an RTF file in a Treeview GUI, and it Works, sort of... As you can se in the example code, the pages in the treeview are hidden and shown with the use of cases, and this works fine with TXT files. I can also display the RTF file, but i can´t hide it? It shows no matter what I try. I have searched this forum, and the web with no luck. The initial code is much larger, with many more treeview items and sub items. The code shown should be enough to show the problem. I´ve also Attached the files needed. ;(EDIT --> don´t mind page3, there is no case for it) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <ScrollBarConstants.au3> #include <GuiEdit.au3> #include <file.au3> #include <GuiRichEdit.au3> _Main() Func _Main() Local $maintree, $about, $about_show, $msg, $company Local $page1, $page1_show, $page1_open, $page1_read Local $page2, $page2_show, $page2_open, $page2_read Local $page3, $page3_show, $page3_open, $page3_read Local $hRichEdit ; FILES TO DISPLAY ;Company ;PAGE1 file Local $page1_open = FileOpen("c:\it\page1.txt", 0) $page1_read = FileRead($page1_open) ;PAGE2 file Local $page2_open = FileOpen ("page2.rtf", 0) $page2_read = FileRead ($page2_open) ;PAGE3 file Local $page3_open = FileOpen("c:\it\page3.txt", 0) $page3_read = FileRead($page3_open) ;<------------------------------------------------------------------------------------------------------------------------------------------------------ ; MAIN GUI $hGui = GUICreate("Company Helpdesk Guide", 1100, 685, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_MAXIMIZEBOX)) ; TreeView main categories $maintree = GUICtrlCreateTreeView(10, 10, 150, 640) $about = GUICtrlCreateTreeViewItem("About", $maintree) $company = GUICtrlCreateTreeViewItem("Company", $maintree) ; SubCategories (COMPANY) $page1 = GUICtrlCreateTreeViewItem("Text file", $company) $page2 = GUICtrlCreateTreeViewItem("RTF file", $company) $webmail = GUICtrlCreateTreeViewItem("Another Page", $company) ; FrontPage $about_show = GUICtrlCreateLabel("Company Helpdesk Guide - v.1.0." & @CRLF & "Copyright" & Chr(169) & "2013 - Company du Nord", 500, 280, 500, 200) ; Make and hide pages ;Company ;PAGE 1 $page1_show = GUICtrlCreateEdit($page1_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) ;PAGE 2 $page2_show = _GUICtrlRichEdit_Create($hGui,$page2_read, 185, 10, 900, 640, BitOR($WS_CHILD, $ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUICtrlSetState(-1,$GUI_HIDE) ;PAGE 3 $page3_show = GUICtrlCreateEdit("Another Page" & @CRLF & $page3_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) GUISetState() ; Cases to show and hide pages While 1 $msg = GUIGetMsg() Select Case $msg = -3 Or $msg = -1 _GUICtrlRichEdit_Destroy($hRichEdit) ExitLoop Case $msg = $about ;(LABEL) GUICtrlSetState($page1_show, $GUI_HIDE) GUICtrlSetState($page2_show, $GUI_HIDE) GUICtrlSetState($about_show, $GUI_SHOW) FileClose($page1_open) Case $msg = $page1 ;(TEXT FILE) GUICtrlSetState($about_show, $GUI_HIDE) GUICtrlSetState($page2_show, $GUI_HIDE) GUICtrlSetState($page1_show, $GUI_SHOW) GUICtrlSetBkColor($page1_show, 0xFFFFFF) FileClose($page2_open) Case $msg = $page2 ;(RTF FILE) GUICtrlSetState($page1_show, $GUI_HIDE) GUICtrlSetState($about_show, $GUI_HIDE) GUICtrlSetState($page2_show, $GUI_SHOW) FileClose($page1_open) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main page1.txtpage2.rtfpage3.txttester.au3 Edited October 22, 2013 by Soler Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty! Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 22, 2013 Moderators Solution Share Posted October 22, 2013 Soler,The RTF page is created by a UDF and returns a handle, not a ControlID. As a result, you cannot use the GUICtrl* functions as they only work with controls created using AutoIt's native funtions. This amended script - using the correct functions to hide/show the RTF page - shows how it should be done:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <ScrollBarConstants.au3> #include <GuiEdit.au3> #include <file.au3> #include <GuiRichEdit.au3> _Main() Func _Main() Local $maintree, $about, $about_show, $msg, $company Local $page1, $page1_show, $page1_open, $page1_read Local $page2, $page2_show, $page2_open, $page2_read Local $page3, $page3_show, $page3_open, $page3_read Local $hRichEdit ; FILES TO DISPLAY ;Company ;PAGE1 file ;Local $page1_open = FileOpen("page1.txt", 0) ; No need to open the files to read them <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $page1_read = FileRead("page1.txt") ;PAGE2 file ;Local $page2_open = FileOpen ("page2.rtf", 0) $page2_read = FileRead ("page2.rtf") ;PAGE3 file ;Local $page3_open = FileOpen("c:\it\page3.txt", 0) ;$page3_read = FileRead($page3_open) ;<------------------------------------------------------------------------------------------------------------------------------------------------------ ; MAIN GUI $hGui = GUICreate("Company Helpdesk Guide", 1100, 685, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_MAXIMIZEBOX)) ; TreeView main categories $maintree = GUICtrlCreateTreeView(10, 10, 150, 640) $about = GUICtrlCreateTreeViewItem("About", $maintree) $company = GUICtrlCreateTreeViewItem("Company", $maintree) ; SubCategories (COMPANY) $page1 = GUICtrlCreateTreeViewItem("Text file", $company) $page2 = GUICtrlCreateTreeViewItem("RTF file", $company) $webmail = GUICtrlCreateTreeViewItem("Another Page", $company) ; FrontPage $about_show = GUICtrlCreateLabel("Company Helpdesk Guide - v.1.0." & @CRLF & "Copyright" & Chr(169) & "2013 - Company du Nord", 500, 280, 500, 200) ; Make and hide pages ;Company ;PAGE 1 $page1_show = GUICtrlCreateEdit($page1_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) ;PAGE 2 $page2_show = _GUICtrlRichEdit_Create($hGui,$page2_read, 185, 10, 900, 640, BitOR($WS_CHILD, $ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;PAGE 3 $page3_show = GUICtrlCreateEdit("Another Page" & @CRLF & $page3_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) GUISetState() ; Cases to show and hide pages While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ; Use proper constants - not magic numbers _GUICtrlRichEdit_Destroy($hRichEdit) ExitLoop Case $msg = $about ;(LABEL) GUICtrlSetState($page1_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($about_show, $GUI_SHOW) ;FileClose($page1_open) ; as yo didi not open - no need to close Case $msg = $page1 ;(TEXT FILE) GUICtrlSetState($about_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($page1_show, $GUI_SHOW) GUICtrlSetBkColor($page1_show, 0xFFFFFF) ;FileClose;$page2_open) Case $msg = $page2 ;(RTF FILE) GUICtrlSetState($page1_show, $GUI_HIDE) GUICtrlSetState($about_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_SHOW) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;FileClose($page1_open) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_MainI have also added some comments - I hope they are useful. Please ask if you have any questions. M23 Razormaul 1 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 Link to comment Share on other sites More sharing options...
Razormaul Posted October 22, 2013 Author Share Posted October 22, 2013 Soler, The RTF page is created by a UDF and returns a handle, not a ControlID. As a result, you cannot use the GUICtrl* functions as they only work with controls created using AutoIt's native funtions. This amended script - using the correct functions to hide/show the RTF page - shows how it should be done: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <ScrollBarConstants.au3> #include <GuiEdit.au3> #include <file.au3> #include <GuiRichEdit.au3> _Main() Func _Main() Local $maintree, $about, $about_show, $msg, $company Local $page1, $page1_show, $page1_open, $page1_read Local $page2, $page2_show, $page2_open, $page2_read Local $page3, $page3_show, $page3_open, $page3_read Local $hRichEdit ; FILES TO DISPLAY ;Company ;PAGE1 file ;Local $page1_open = FileOpen("page1.txt", 0) ; No need to open the files to read them <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $page1_read = FileRead("page1.txt") ;PAGE2 file ;Local $page2_open = FileOpen ("page2.rtf", 0) $page2_read = FileRead ("page2.rtf") ;PAGE3 file ;Local $page3_open = FileOpen("c:\it\page3.txt", 0) ;$page3_read = FileRead($page3_open) ;<------------------------------------------------------------------------------------------------------------------------------------------------------ ; MAIN GUI $hGui = GUICreate("Company Helpdesk Guide", 1100, 685, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_MAXIMIZEBOX)) ; TreeView main categories $maintree = GUICtrlCreateTreeView(10, 10, 150, 640) $about = GUICtrlCreateTreeViewItem("About", $maintree) $company = GUICtrlCreateTreeViewItem("Company", $maintree) ; SubCategories (COMPANY) $page1 = GUICtrlCreateTreeViewItem("Text file", $company) $page2 = GUICtrlCreateTreeViewItem("RTF file", $company) $webmail = GUICtrlCreateTreeViewItem("Another Page", $company) ; FrontPage $about_show = GUICtrlCreateLabel("Company Helpdesk Guide - v.1.0." & @CRLF & "Copyright" & Chr(169) & "2013 - Company du Nord", 500, 280, 500, 200) ; Make and hide pages ;Company ;PAGE 1 $page1_show = GUICtrlCreateEdit($page1_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) ;PAGE 2 $page2_show = _GUICtrlRichEdit_Create($hGui,$page2_read, 185, 10, 900, 640, BitOR($WS_CHILD, $ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;PAGE 3 $page3_show = GUICtrlCreateEdit("Another Page" & @CRLF & $page3_read, 185, 10, 900, 640, BitOR(0, $ES_READONLY, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) GUISetState() ; Cases to show and hide pages While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ; Use proper constants - not magic numbers _GUICtrlRichEdit_Destroy($hRichEdit) ExitLoop Case $msg = $about ;(LABEL) GUICtrlSetState($page1_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($about_show, $GUI_SHOW) ;FileClose($page1_open) ; as yo didi not open - no need to close Case $msg = $page1 ;(TEXT FILE) GUICtrlSetState($about_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($page1_show, $GUI_SHOW) GUICtrlSetBkColor($page1_show, 0xFFFFFF) ;FileClose;$page2_open) Case $msg = $page2 ;(RTF FILE) GUICtrlSetState($page1_show, $GUI_HIDE) GUICtrlSetState($about_show, $GUI_HIDE) WinSetState($page2_show, "", @SW_SHOW) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;FileClose($page1_open) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main I have also added some comments - I hope they are useful. Please ask if you have any questions. M23 Melba23, Thank you very much, this works perfect. Very nice info, I didn´t think of that. And also, thank you for the comments, helpfull endeed. Always good to learn something. I will get on with my code now Thanks again.... Soler Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty! Link to comment Share on other sites More sharing options...
kylomas Posted October 23, 2013 Share Posted October 23, 2013 Solar, The program design you are persuing will get cumbersome very quickly as the number of pages increases. If this is a one-off or only uses two or three pages, no sweat. If not, then we may be able to help redesign your appraoch to something better if you tell us what you are trying to do. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Razormaul Posted October 23, 2013 Author Share Posted October 23, 2013 (edited) Solar, The program design you are persuing will get cumbersome very quickly as the number of pages increases. If this is a one-off or only uses two or three pages, no sweat. If not, then we may be able to help redesign your appraoch to something better if you tell us what you are trying to do. kylomas Hey BOHICA That is very nice of you, i will try to explain my intentions. My initial thoughts was to build the treeview by looking at a folder structure with subfolders as subcategories. This way, whenever i need to add a new subject, i would just have to make a new folder, maby subfolder, and then just put an RTF file in there. No need to recompile and update the program. But that prooved a bit to difficult for me. I can see what you mean by cumbersome, i agree. But im not shure what else to do. I´ve only just startet with Autoit. The plan is to build a kind of userguide (im it-support) with faq´s and solutions for our software, Network setup, and so on.. I know i could just do some WordPress page instead. But the point is, anyone can make an RTF dokument and put it in a folder. And it´s offline. Not just another website for the user, but a nice litte app on there desktop. That is my goal, and any suggestions and/or actual examples you might have, is very welcome. NB. My guess is i have to create some kind of statement that only allows a particularly page to be displayed, whenever that subject is clicked, not having to hide all other pages manually.? Edited October 23, 2013 by Soler Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty! Link to comment Share on other sites More sharing options...
kylomas Posted October 23, 2013 Share Posted October 23, 2013 Soler, My initial thoughts was to build the treeview by looking at a folder structure with subfolders as subcategories. This way, whenever i need to add a new subject, i would just have to make a new folder, maby subfolder, and then just put an RTF file in there. A much better approach. I'll whip up a short example to show you how to do this. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted October 23, 2013 Share Posted October 23, 2013 (edited) Soler, Here is a short, simple example of reading a directory, creatng treeview items and displaying whatever is in the file associated with the treeview item. The treeview can be navigated by either ckicking on the item or using the arrow keys to scroll through the items. I don't know shit about Rich Edit controls except that they can contain either RTF formatted data or plain text, so no need to use multiple controls. I've include some cursory comments to indicate what is being done. See the Help file for more detailed explanations. The file structure that I used is, of course, tailored to my environment. You'll have to change this. expandcollapse popup#include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiMenu.au3> #include <GuiRichEdit.au3> Local $gui010 = GUICreate('User Doc Example', 800, 520) GUISetBkColor(0xE5E4E2) ; create the treeview control with some formatting Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Local $hTV = _GUICtrlTreeView_Create($gui010, 10, 10, 200, 500, $iStyle, $WS_EX_CLIENTEDGE) _GUICtrlTreeView_SetTextColor($hTV, 0x000000) _GUICtrlTreeView_SetLineColor($hTV, 0xaa0000) _GUICtrlTreeView_SetBkColor($hTV, 0xEFEEEC) ; image list for what symbol to display for each treeview item Local $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, "shell32.dll", 3) _GUICtrlTreeView_SetNormalImageList($hTV, $hImage) ; richedit controls accept either RTF or plain text data $edt010 = _GUICtrlRichEdit_Create($gui010, "", 210, 10, 580, 500, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ; dummy control signalled by message processing routine local $FileChange = guictrlcreatedummy() ; iterate through the target directory creating one treeview item for each file found local $SourcePath = 'k:\testdoc\' local $files = filefindfirstfile($SourcePath & '*.*'), $file if $files = -1 then msgbox(0,'*** FileFindFirst ***','No files found for path = ' & $SourcePath) Exit endif while 1 $file = FileFindNextFile($files) if @error then exitloop _guictrltreeview_add($hTV,0,$file,0,0) wend GUISetState() ; notification message processing routine used to signal that a selection on the treeview has changed GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; message loop While 1 Switch GUIGetMsg() Case $gui_event_close Exit case $FileChange _GUICtrlRichEdit_SetText($edt010, fileread($sourcepath & _guictrltreeview_gettext($hTV,_guictrltreeview_getselection($hTV)))) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $hTV If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $TVN_SELCHANGEDW ; use this to get out of the notification routine quickly. Processing occurs in the messageloop GUICtrlSendtodummy($FileChange) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY kylomas edit: added more comments to the code Edited October 23, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Razormaul Posted October 24, 2013 Author Share Posted October 24, 2013 (edited) Soler, Here is a short, simple example of reading a directory, creatng treeview items and displaying whatever is in the file associated with the treeview item. The treeview can be navigated by either ckicking on the item or using the arrow keys to scroll through the items. I don't know shit about Rich Edit controls except that they can contain either RTF formatted data or plain text, so no need to use multiple controls. I've include some cursory comments to indicate what is being done. See the Help file for more detailed explanations. The file structure that I used is, of course, tailored to my environment. You'll have to change this. expandcollapse popup#include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiMenu.au3> #include <GuiRichEdit.au3> Local $gui010 = GUICreate('User Doc Example', 800, 520) GUISetBkColor(0xE5E4E2) ; create the treeview control with some formatting Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Local $hTV = _GUICtrlTreeView_Create($gui010, 10, 10, 200, 500, $iStyle, $WS_EX_CLIENTEDGE) _GUICtrlTreeView_SetTextColor($hTV, 0x000000) _GUICtrlTreeView_SetLineColor($hTV, 0xaa0000) _GUICtrlTreeView_SetBkColor($hTV, 0xEFEEEC) ; image list for what symbol to display for each treeview item Local $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, "shell32.dll", 3) _GUICtrlTreeView_SetNormalImageList($hTV, $hImage) ; richedit controls accept either RTF or plain text data $edt010 = _GUICtrlRichEdit_Create($gui010, "", 210, 10, 580, 500, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ; dummy control signalled by message processing routine local $FileChange = guictrlcreatedummy() ; iterate through the target directory creating one treeview item for each file found local $SourcePath = 'k:\testdoc\' local $files = filefindfirstfile($SourcePath & '*.*'), $file if $files = -1 then msgbox(0,'*** FileFindFirst ***','No files found for path = ' & $SourcePath) Exit endif while 1 $file = FileFindNextFile($files) if @error then exitloop _guictrltreeview_add($hTV,0,$file,0,0) wend GUISetState() ; notification message processing routine used to signal that a selection on the treeview has changed GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; message loop While 1 Switch GUIGetMsg() Case $gui_event_close Exit case $FileChange _GUICtrlRichEdit_SetText($edt010, fileread($sourcepath & _guictrltreeview_gettext($hTV,_guictrltreeview_getselection($hTV)))) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $hTV If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $TVN_SELCHANGEDW ; use this to get out of the notification routine quickly. Processing occurs in the messageloop GUICtrlSendtodummy($FileChange) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY kylomas edit: added more comments to the code Hey BOHICA That´s pretty cool m8. It works fine, except for a coupple of things. 1. Subfolders is supposed to create subcategories. (otherwise it´s going to be one long list) 2. It only works if you put files in the root folder, files are not displayed if they are in a folder. I really appreciate your example, it´s more than I expected. But I need to create the structure like this: About (folder with file to display) -Subject1 (folder with subfolders) Subject1.1 (subfolder with file to display) Subject1.2 (subfolder with file to display) Subject1.3 (subfolder with file to display) -Subject2 (folder with file to display) Subject2.1 (subfolder with file to display) +Subject3 (folder with subfolders and file to display) and so on.... Thanks Again m8, i will let you know if I can make it work like that:) Soler Edited October 24, 2013 by Soler Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty! Link to comment Share on other sites More sharing options...
kylomas Posted October 24, 2013 Share Posted October 24, 2013 Solar, I can see what you mean by cumbersome, i agree. But im not shure what else to do. I´ve only just startet with Autoit Yes, I was providing an alternative. Try to visulaize then code with 50 pages comprised of a three level hierarchy coded in the original manner. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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