c.haslam Posted July 15, 2012 Share Posted July 15, 2012 Here is the code: expandcollapse popupAutoItSetOption("MustDeclareVars", 1) AutoItSetOption("TrayIconDebug",1) #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <GuiListView.au3> Func GetLatestPreviousFilspcs() ; Much simplified for AutoIt forum Local $retVec[3] $retVec[0] = "cat" $retVec[1] = "dog" $retVec[2] = "goat" Return $retVec EndFunc Local $frmSelFromPrev = GUICreate("Select based on previous files", 623, 501, 192, 114) Local $style = BitOR($LVS_LIST,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL,$LVS_SORTASCENDING) Local $hListView = GUICtrlCreateListView("", 8, 8, 593, 361, $style) Local $btnOK = GUICtrlCreateButton("OK", 424, 448, 49, 25) Local $btnCancel = GUICtrlCreateButton("Cancel", 488, 448, 65, 25) Local $Input1 = GUICtrlCreateInput("", 96, 384, 305, 21) Local $ctrlExStyles = $LVS_EX_ONECLICKACTIVATE GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE,$ctrlExStyles,$ctrlExStyles) Local $itemvec = GetLatestPreviousFilspcs() For $i = 0 to ubound($itemvec)-1 GUICtrlCreateListViewItem($itemvec[$i],$hListView) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) Local $nMsg,$Index=999 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE,$btnCancel ExitLoop Case $btnOK MsgBox(0, "input control", GUICtrlRead($Input1), 2) ExitLoop EndSwitch WEnd GUIDelete($frmSelFromPrev) ;~ ======================================================== ;~ This thing is responsible for click events ;~ ======================================================== Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMACTIVATE ; Sent by a list-view control when the user clicks an item with the left mouse button Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $Index = DllStructGetData($tInfo, "Index") ; Local $subitemNR = DllStructGetData($tInfo, "SubItem") If $Index <> -1 Then GUICtrlSetData($Input1,_GUICtrlListView_GetItemText($hWndListView,$Index)) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY In my code, there are about 100 list items. but the above code demonstrates the problem. I want to do something like FileSaveDialog(), where single-clicking on an item copies the text of the item to the input box. But the above code requires two clicks to do the copy. I would appreciate any guidance you can give me on achieving single-click copying. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 15, 2012 Moderators Share Posted July 15, 2012 c.haslam, In my experience using a single click to action something when dealing with a ListView is not a good idea as the ListView often "eats" the single click to select the item rather than acting upon it as you wish. Using a double click is a much better option - I would stick with what you have got at the moment. M23 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...
c.haslam Posted July 15, 2012 Author Share Posted July 15, 2012 Thanks, Melba23. I can live with 2 clicks, but I do wonder how FileSaveDialog() does it. Perhaps the answer is: it's not written in AutoIt! A second question about this code: I have now made a function out of the GUI..() stuff and the message loop, but I am now getting "possibly used before declaration." for $Input 1 and $hListview. I know that I can overcome these warnings by making these variables global, but is there a way of forcing WM_NOTIFY() to see $Input1 with Opt("MustDeclareVars",1) ? And the same for $hListView? I think I knew the answer a long time ago, but have forgotten it. ...chris Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 15, 2012 Moderators Share Posted July 15, 2012 c.haslam,Not that I know of. If you want variables to be visible across function boundaries then they have to be Global in scope. M23 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...
Zedna Posted July 15, 2012 Share Posted July 15, 2012 Use $LVN_ITEMCHANGED in WM_NOTIFYand test if LVIS_SELECTED state is in "NewState" member of $NMLISTVIEW structureHere is similar idea Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
c.haslam Posted July 16, 2012 Author Share Posted July 16, 2012 Thanks, Zedna ...chris Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard 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