CartoonDragon Posted March 21, 2011 Author Posted March 21, 2011 Hello everyone, I ran in to a new problem, I would like to use the case function on a Listview to do something when you click an item on the list, my attempt to do it almost works, but i need it to stop looping the function. Any help would be greatly apprisiated expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect ;~ --------------------- Start added code If GUICtrlRead(GUICtrlRead($listview)) = "" Then Else MsgBox(0,"",GUICtrlRead(GUICtrlRead($listview))) EndIf ;~ --------------------- End added code Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example
BrewManNH Posted March 21, 2011 Posted March 21, 2011 You'd need to jump to another function, and then after the function returns either jump out of the loop with an exitloop or just exiting the script if that's your intent. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
CartoonDragon Posted March 21, 2011 Author Posted March 21, 2011 You'd need to jump to another function, and then after the function returns either jump out of the loop with an exitloop or just exiting the script if that's your intent.I'm sorry, i know i didn't make it clear, i don't care about this function, the script was just to use an example to give anyone willing to help a better understanding of the problem i'm faced with. I need it to continue to run that loop, the function it self from the example as well.
BrewManNH Posted March 21, 2011 Posted March 21, 2011 (edited) You should probably use a double click on the listview item to fire off the function needed then, otherwise unless you deselect the ListView item it will always loop through it. Here's how I do it, there's probably other ways of doing it, but I found that this works for me. GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ;~ Add this line to the start of your script somewhere before the While...Wend loop Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Windows message function used to call the double click function #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $lParam $hWndListView = $ListView If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMACTIVATE Local $nmia = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $I = DllStructGetData($nmia, "Index") MsgBox(0,"",GUICtrlRead(GUICtrlRead($listview))) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Edited March 21, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
CartoonDragon Posted March 21, 2011 Author Posted March 21, 2011 BrewManNH, Thank you very much, i will be using that then
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