jfcby Posted September 8, 2008 Share Posted September 8, 2008 Hi, I'm creating a script to install programs and decided to use TreeView because I'll be adding programs. This is my problem the script I'm modifying is from the help file and it uses check boxes so multiple selections can be made. I need to modify it so that one selection can be made at a time. Is there a Radio Button option when using TreeView? If not, is there a way to deactivate a check box? Is there a easier or better method recommended to use other than the TreeView? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $maintree, $aboutitem, $helpitem, $pcprotectionitem, $pcsoftwareitem, $pclearnitem, $antivirusitem, $adspywareitem Local $cmditem, $miscitem, $descgroup, $effectsgroup, $effectstree Local $effect1, $effect2, $effect3, $effect4, $effect5 Local $stylesgroup, $stylestree, $style1, $style2, $style3, $style4, $style5 Local $aboutlabel, $helplabel, $cancelbutton, $msg #forceref $cmditem, $miscitem, $effect2, $effect4, $effect5, $style1, $style2, $style3 GUICreate("InstaPro", 340, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_GROUP, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) $maintree = GUICtrlCreateTreeView(10, 10, 120, 150) $aboutitem = GUICtrlCreateTreeViewItem("About", $maintree) $helpitem = GUICtrlCreateTreeViewItem("Help", $maintree) $pcprotectionitem = GUICtrlCreateTreeViewItem("PC Protection", $maintree) $pcsoftwareitem = GUICtrlCreateTreeViewItem("PC Software", $maintree) $pclearnitem = GUICtrlCreateTreeViewItem("PC Learn", $maintree) $antivirusitem = GUICtrlCreateTreeViewItem("Anti-Virus", $pcprotectionitem) $adspywareitem = GUICtrlCreateTreeViewItem("Ad/Spy-Ware", $pcprotectionitem) $cmditem = GUICtrlCreateTreeViewItem("Commandline", $pcsoftwareitem) $miscitem = GUICtrlCreateTreeViewItem("Misc", $pcsoftwareitem) $descgroup = GUICtrlCreateGroup("Description", 140, 105, 180, 55) GUICtrlSetState(-1, $GUI_HIDE) $effectsgroup = GUICtrlCreateGroup("Effects", 140, 5, 180, 95) GUICtrlSetState(-1, $GUI_HIDE) $effectstree = GUICtrlCreateTreeView(150, 20, 160, 70, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP), $WS_EX_CLIENTEDGE) GUICtrlSetState(-1, $GUI_HIDE) $effect1 = GUICtrlCreateTreeViewItem("Effect 1", $effectstree) $effect2 = GUICtrlCreateTreeViewItem("Effect 2", $effectstree) $effect3 = GUICtrlCreateTreeViewItem("Effect 3", $effectstree) $effect4 = GUICtrlCreateTreeViewItem("Effect 4", $effectstree) $effect5 = GUICtrlCreateTreeViewItem("Effect 5", $effectstree) $stylesgroup = GUICtrlCreateGroup("Styles", 140, 5, 180, 95) GUICtrlSetState(-1, $GUI_HIDE) $stylestree = GUICtrlCreateTreeView(150, 20, 160, 70, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP), $WS_EX_CLIENTEDGE) GUICtrlSetState(-1, $GUI_HIDE) $style1 = GUICtrlCreateTreeViewItem("Style 1", $stylestree) $style2 = GUICtrlCreateTreeViewItem("Style 2", $stylestree) $style3 = GUICtrlCreateTreeViewItem("Style 3", $stylestree) $style4 = GUICtrlCreateTreeViewItem("Style 4", $stylestree) $style5 = GUICtrlCreateTreeViewItem("Style 5", $stylestree) $aboutlabel = GUICtrlCreateLabel("Simply Install, Update, and Track Programs!", 160, 80, 160, 40) $helplabel = GUICtrlCreateLabel("Help Instructions Coming Soon!", 160, 80, 160, 40) $cancelbutton = GUICtrlCreateButton("Cancel", 130, 170, 70, 20) GUISetState() GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effect1, $GUI_CHECKED) GUICtrlSetState($effect3, $GUI_CHECKED) GUICtrlSetState($style4, $GUI_CHECKED) GUICtrlSetState($style5, $GUI_CHECKED) While 1 $msg = GUIGetMsg() Select Case $msg = -3 Or $msg = -1 Or $msg = $cancelbutton ExitLoop Case $msg = $aboutitem GUICtrlSetState($descgroup, $GUI_HIDE) GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_SHOW) Case $msg = $helpitem GUICtrlSetState($descgroup, $GUI_HIDE) GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_SHOW) Case $msg = $pcprotectionitem Case $msg = $pcsoftwareitem Case $msg = $pclearnitem Case $msg = $antivirusitem GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) GUICtrlSetState($effectstree, $GUI_SHOW) GUICtrlSetBkColor($effectstree, 0xD0F0F0) ;GUIctrlSetState...($effectstree,$GUI_SHOW) Case $msg = $adspywareitem GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) ;GUIctrlSetState.($stylestree,$GUI_SHOW) GUICtrlSetState($stylestree, $GUI_SHOW) GUICtrlSetColor($stylestree, 0xD00000) GUICtrlSetBkColor($stylestree, 0xD0FFD0) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Thank you for your help, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 8, 2008 Share Posted September 8, 2008 Hi,I'm creating a script to install programs and decided to use TreeView because I'll be adding programs. This is my problem the script I'm modifying is from the help file and it uses check boxes so multiple selections can be made. I need to modify it so that one selection can be made at a time. Is there a Radio Button option when using TreeView?If not, is there a way to deactivate a check box?Is there a easier or better method recommended to use other than the TreeView?Thank you for your help,jfcbyA TreeView only allows one selection at a time by default. Why use the checkboxes at all? For that matter, why use a TreeView? Your "Styles" and "Effects" controls could just be ListViews, or even some actual Radio Buttons. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jfcby Posted September 9, 2008 Author Share Posted September 9, 2008 A TreeView only allows one selection at a time by default. Why use the checkboxes at all? For that matter, why use a TreeView? Your "Styles" and "Effects" controls could just be ListViews, or even some actual Radio Buttons. With my above code I changed line 43 to: $effectstree = GUICtrlCreateTreeView(150, 20, 160, 70) and I added below line 49: If $effect1 = True Then _GUICtrlTreeView_GetSelection($effect1)) Run("Notepad.exe", "", @SW_MAXIMIZE EndIf But I'm getting the Au3Check error: [error] D:\Program Files\AutoIt3\AutoIT3Mobile\AutoIT3\My Projects\InstaPro.au3(52,42) : ERROR: syntax error _GUICtrlTreeView_GetSelection($effect1)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\Program Files\AutoIt3\AutoIT3Mobile\AutoIT3\My Projects\InstaPro.au3 - 1 error(s), 0 warning(s) [/error] When I select a option how do I run a program? Full Code: expandcollapse popup;InstaPro - Simply Install, Update, & Track Programs! #cs - Notes - #ce #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #Include <GuiTreeView.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $maintree, $aboutitem, $helpitem, $pcprotectionitem, $pcsoftwareitem, $pclearnitem, $antivirusitem, $adspywareitem Local $cmditem, $miscitem, $descgroup, $effectsgroup, $effectstree Local $effect1, $effect2, $effect3, $effect4, $effect5 Local $stylesgroup, $stylestree, $style1, $style2, $style3, $style4, $style5 Local $aboutlabel, $helplabel, $cancelbutton, $msg #forceref $cmditem, $miscitem, $effect2, $effect4, $effect5, $style1, $style2, $style3 GUICreate("InstaPro", 340, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_GROUP, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) $maintree = GUICtrlCreateTreeView(10, 10, 120, 150) $aboutitem = GUICtrlCreateTreeViewItem("About", $maintree) $helpitem = GUICtrlCreateTreeViewItem("Help", $maintree) $pcprotectionitem = GUICtrlCreateTreeViewItem("PC Protection", $maintree) $pcsoftwareitem = GUICtrlCreateTreeViewItem("PC Software", $maintree) $pclearnitem = GUICtrlCreateTreeViewItem("PC Learn", $maintree) $antivirusitem = GUICtrlCreateTreeViewItem("Anti-Virus", $pcprotectionitem) $adspywareitem = GUICtrlCreateTreeViewItem("Ad/Spy-Ware", $pcprotectionitem) $cmditem = GUICtrlCreateTreeViewItem("Commandline", $pcsoftwareitem) $miscitem = GUICtrlCreateTreeViewItem("Misc", $pcsoftwareitem) $descgroup = GUICtrlCreateGroup("Description", 140, 105, 180, 55) GUICtrlSetState(-1, $GUI_HIDE) $effectsgroup = GUICtrlCreateGroup("Effects", 140, 5, 180, 95) GUICtrlSetState(-1, $GUI_HIDE) $effectstree = GUICtrlCreateTreeView(150, 20, 160, 70) GUICtrlSetState(-1, $GUI_HIDE) $effect1 = GUICtrlCreateTreeViewItem("Effect 1", $effectstree) $effect2 = GUICtrlCreateTreeViewItem("Effect 2", $effectstree) $effect3 = GUICtrlCreateTreeViewItem("Effect 3", $effectstree) $effect4 = GUICtrlCreateTreeViewItem("Effect 4", $effectstree) $effect5 = GUICtrlCreateTreeViewItem("Effect 5", $effectstree) If $effect1 = True Then _GUICtrlTreeView_GetSelection($effect1)) Run("Notepad.exe", "", @SW_MAXIMIZE EndIf $stylesgroup = GUICtrlCreateGroup("Styles", 140, 5, 180, 95) GUICtrlSetState(-1, $GUI_HIDE) $stylestree = GUICtrlCreateTreeView(150, 20, 160, 70, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP), $WS_EX_CLIENTEDGE) GUICtrlSetState(-1, $GUI_HIDE) $style1 = GUICtrlCreateTreeViewItem("Style 1", $stylestree) $style2 = GUICtrlCreateTreeViewItem("Style 2", $stylestree) $style3 = GUICtrlCreateTreeViewItem("Style 3", $stylestree) $style4 = GUICtrlCreateTreeViewItem("Style 4", $stylestree) $style5 = GUICtrlCreateTreeViewItem("Style 5", $stylestree) $aboutlabel = GUICtrlCreateLabel("Simply Install, Update, and Track Programs!", 160, 80, 160, 40) $helplabel = GUICtrlCreateLabel("Help Instructions Coming Soon!", 160, 80, 160, 40) $cancelbutton = GUICtrlCreateButton("Cancel", 130, 170, 70, 20) GUISetState() GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effect1, $GUI_CHECKED) GUICtrlSetState($effect3, $GUI_CHECKED) GUICtrlSetState($style4, $GUI_CHECKED) GUICtrlSetState($style5, $GUI_CHECKED) While 1 $msg = GUIGetMsg() Select Case $msg = -3 Or $msg = -1 Or $msg = $cancelbutton ExitLoop Case $msg = $aboutitem GUICtrlSetState($descgroup, $GUI_HIDE) GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_SHOW) Case $msg = $helpitem GUICtrlSetState($descgroup, $GUI_HIDE) GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_SHOW) Case $msg = $pcprotectionitem Case $msg = $pcsoftwareitem Case $msg = $pclearnitem Case $msg = $antivirusitem GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) GUICtrlSetState($effectstree, $GUI_SHOW) GUICtrlSetBkColor($effectstree, 0xD0F0F0) ;GUIctrlSetState...($effectstree,$GUI_SHOW) Case $msg = $adspywareitem GUICtrlSetState($effectstree, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) ;GUIctrlSetState.($stylestree,$GUI_SHOW) GUICtrlSetState($stylestree, $GUI_SHOW) GUICtrlSetColor($stylestree, 0xD00000) GUICtrlSetBkColor($stylestree, 0xD0FFD0) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Thank you for your help, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 9, 2008 Share Posted September 9, 2008 With my above code I changed line 43 to: $effectstree = GUICtrlCreateTreeView(150, 20, 160, 70) and I added below line 49: If $effect1 = True Then _GUICtrlTreeView_GetSelection($effect1)) Run("Notepad.exe", "", @SW_MAXIMIZE EndIf But I'm getting the Au3Check error: [error] D:\Program Files\AutoIt3\AutoIT3Mobile\AutoIT3\My Projects\InstaPro.au3(52,42) : ERROR: syntax error _GUICtrlTreeView_GetSelection($effect1)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\Program Files\AutoIt3\AutoIT3Mobile\AutoIT3\My Projects\InstaPro.au3 - 1 error(s), 0 warning(s) [/error] When I select a option how do I run a program? Full Code: Thank you for your help, jfcby Bad case of a wandering close-paren: If $effect1 = True Then _GUICtrlTreeView_GetSelection($effect1) Run("Notepad.exe", "", @SW_MAXIMIZE) EndIf That will fix the syntax error, but there are other problems. The variable $effect1 is a TreeView item control ID. Why are you testing $effect1 = True? You have to choose to either use ControlTreeView() or _GuiCtrlTreeView_* functions, and you can't directly swap them. For example, ControlTreeView() can work with the control ID of the TreeView control, while _GuiCtrlTreeView_* functions require the HANDLE to the control, so you can't pass $effect1 to _GuiCtrlTreeView_GetSelection(), and once you pass the handle you didn't save the selection to a variable. Since you create the TreeView and the items with the native AutoIt GUI functions GuiCtrlCreateTreeView() and GuiCtrlCreateTreeViewItem(), you should avoid manipulating them with the _GuiCtrlTreeView_* UDF functions. There could be conflicts. On the assumption that code is supposed to be "if the $effect1 TreeView item is selected then run notepad", it would be more like: If ControlTreeView("InstaPro", "", $effectstree, "GetSelected") = "Effect 1" Then Run("Notepad.exe") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jfcby Posted September 9, 2008 Author Share Posted September 9, 2008 On the assumption that code is supposed to be "if the $effect1 TreeView item is selected then run notepad", it would be more like: If ControlTreeView("InstaPro", "", $effectstree, "GetSelected") = "Effect 1" Then Run("Notepad.exe") I'm having a difficult time understanding how to insert the above code in my script because the help files does not give examples on running programs but how the TreeView is suppose to coded. I inserted the code below line 110 and when I selected Effect 1 nothing happened. How is the above suppose to be inserted in the code to work? Case $msg = $antivirusitem GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) GUICtrlSetState($effectstree, $GUI_SHOW) GUICtrlSetBkColor($effectstree, 0xD0F0F0) ;GUIctrlSetState...($effectstree,$GUI_SHOW) If ControlTreeView("InstaPro", "", $effectstree, "GetSelected") = "Effect 1" Then Run("Notepad.exe") Thank you for your help, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 9, 2008 Share Posted September 9, 2008 I'm having a difficult time understanding how to insert the above code in my script because the help files does not give examples on running programs but how the TreeView is suppose to coded. I inserted the code below line 110 and when I selected Effect 1 nothing happened. How is the above suppose to be inserted in the code to work? Case $msg = $antivirusitem GUICtrlSetState($stylestree, $GUI_HIDE) GUICtrlSetState($stylesgroup, $GUI_HIDE) GUICtrlSetState($aboutlabel, $GUI_HIDE) GUICtrlSetState($helplabel, $GUI_HIDE) GUICtrlSetState($effectsgroup, $GUI_SHOW) GUICtrlSetState($descgroup, $GUI_SHOW) GUICtrlSetState($effectstree, $GUI_SHOW) GUICtrlSetBkColor($effectstree, 0xD0F0F0) ;GUIctrlSetState...($effectstree,$GUI_SHOW) If ControlTreeView("InstaPro", "", $effectstree, "GetSelected") = "Effect 1" Then Run("Notepad.exe") Thank you for your help, jfcby I'm not understanding what you want to do. Why was the block of code I addressed earlier there at all? What was it supposed to do? Why would you put that line after "Case $msg = $antivirusitem"? Did you only want to check the selection of "Effect 1" when $antivirusitem was selected? If you want action when "Effect 1" is selected, you'll have to add a "Case $msg = $effect1" for it: Case $msg = $effect1 Run("Notepad.exe") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jfcby Posted September 9, 2008 Author Share Posted September 9, 2008 I'm not understanding what you want to do. I apologize for not explaining in more detail what I wanted to do! Why was the block of code I addressed earlier there at all? What was it supposed to do? Why would you put that line after "Case $msg = $antivirusitem"? Did you only want to check the selection of "Effect 1" when $antivirusitem was selected? Problem Solved with the code below: If you want action when "Effect 1" is selected, you'll have to add a "Case $msg = $effect1" for it: Case $msg = $effect1 Run("Notepad.exe") I did not know the answer would be so simple and I've got a lot of AutoIT3 Coding to learn. Thank you for your help, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** 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