cgasb Posted February 8, 2008 Posted February 8, 2008 I create an array with PC names and then populate a listview. I am currently getting the selected PC by using $GUI_EVENT_PRIMARYDOWN and GUICtrlRead in the corrosponding function, but that's not accurate as the function is activated by clicking anywhere in the GUI. expandcollapse popup;============================================= ; Define some GUI stuff and display the GUI ;============================================= GUICreate("Computer List", 200, 250) ; will create a dialog box that when displayed is centered $PCView = GUICtrlCreateList (" ",17,17,120,200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Value") GUISetState () ;============================================= ; Setup the list with computer names ;============================================= For $z = 1 To $aPC[0] GUICtrlSetData(-1,$aPC[$z]) Next ;============================================= ; Idle around ;============================================= While 1 Sleep(1000) Wend ;============================================= ; Read the computer name that is selected and do something ;============================================= Func Value() $valuex = GUICtrlRead($PCView) MsgBox(0, "", $valuex) EndFunc ;============================================= ; Close the GUI and exit the program ;============================================= Func CLOSEClicked() Exit EndFunc What would be the "proper" way to grab what is clicked in the list?
Achilles Posted February 8, 2008 Posted February 8, 2008 expandcollapse popup#include<GuiListBox.au3> #include<GUIConstantsEx.au3> Opt("GuiOnEventMode", 1) ;============================================= ; Define some GUI stuff and display the GUI ;============================================= GUICreate("Computer List", 200, 250); will create a dialog box that when displayed is centered $PCView = GUICtrlCreateList (" ",17,17,120,200) GuiCtrlSetOnEvent(-1, '_Test') GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState () ;============================================= ; Setup the list with computer names ;============================================= Local $aPc[5] = [4, 7, 8, 9, 11] For $z = 1 To $aPC[0] GUICtrlSetData(-1,$aPC[$z]) Next ;============================================= ; Idle around ;============================================= While 1 Sleep(1000) Wend Func _Test() Msgbox(0, 'Currently selected...', 'Index = ' & _GuictrlListBox_GetCurSel($PCView) & @CRLF & 'Value = ' & _GuiCtrlLIstBox_GetText($PCView, _GuictrlListBox_GetCurSel($PCView))) EndFunc ;============================================= ; Close the GUI and exit the program ;============================================= Func CLOSEClicked() Exit EndFunc My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
cgasb Posted February 9, 2008 Author Posted February 9, 2008 expandcollapse popup#include<GuiListBox.au3> #include<GUIConstantsEx.au3> Opt("GuiOnEventMode", 1) ;============================================= ; Define some GUI stuff and display the GUI ;============================================= GUICreate("Computer List", 200, 250); will create a dialog box that when displayed is centered $PCView = GUICtrlCreateList (" ",17,17,120,200) GuiCtrlSetOnEvent(-1, '_Test') GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState () ;============================================= ; Setup the list with computer names ;============================================= Local $aPc[5] = [4, 7, 8, 9, 11] For $z = 1 To $aPC[0] GUICtrlSetData(-1,$aPC[$z]) Next ;============================================= ; Idle around ;============================================= While 1 Sleep(1000) Wend Func _Test() Msgbox(0, 'Currently selected...', 'Index = ' & _GuictrlListBox_GetCurSel($PCView) & @CRLF & 'Value = ' & _GuiCtrlLIstBox_GetText($PCView, _GuictrlListBox_GetCurSel($PCView))) EndFunc ;============================================= ; Close the GUI and exit the program ;============================================= Func CLOSEClicked() Exit EndFunc That worked beautifully when I incorporated your adjustments. Thanks for the lesson.
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