gcue Posted January 29, 2015 Share Posted January 29, 2015 (edited) hello i am able to get the listview $index using $NM_CLICK but not under $LVN_KEYDOWN. driving me crazy! any help is appreciated thanks! expandcollapse popup#include <Array.au3> $msg_normal = 262144 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $iWindowStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING) $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) $custom_portfolios_child = GUICreate("Custom Collections", 485, 570, -1, -1, $WS_EX_MDICHILD) $custom_portfolios_listview = GUICtrlCreateListView("CUSTOM COLLECTIONS", 15, 110, 200, 310, -1, $iExWindowStyle) $symbols_listview = GUICtrlCreateListView("SYMBOLS", 260, 110, 200, 310, $iWindowStyle, $iExWindowStyle) GUICtrlCreateButton("Exit", 205, 500, 70, 20) GUICtrlSetOnEvent(-1, "_Exit") GUICtrlCreateListViewItem("test1", $custom_portfolios_listview) GUICtrlCreateListViewItem("test2", $custom_portfolios_listview) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() While 1 Sleep(10) WEnd Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tNMHDR, $hWndFrom, $code, $idFrom $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $idFrom = DllStructGetData($tNMHDR, "IDFrom") $code = DllStructGetData($tNMHDR, "Code") Switch $code Case $NM_CLICK Switch $idFrom Case $custom_portfolios_listview $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $index = DllStructGetData($tInfo, "Index") Custom_Collections_Show($index) EndSwitch Case $LVN_KEYDOWN Switch $idFrom Case $custom_portfolios_listview ;~ $taGLVKEYDOWN = DllStructCreate("int;int;int;int;uint", $lParam) ;~ $key_code = Hex(DllStructGetData($taGLVKEYDOWN, 4), 2) $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $index = DllStructGetData($tInfo, "Index") Debug($index) Custom_Collections_Show($index) ;~ If $key_code = 26 Then ;up ;~ Debug("up", $index) ;~ Custom_Collections_Show($index) ;~ EndIf ;~ If $key_code = 28 Then ;down ;~ Debug("down", $index) ;~ Custom_Collections_Show($index) ;~ EndIf EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY func Custom_Collections_Show($index) debug($index) EndFunc Func Debug($variable1 = "", $variable2 = "", $variable3 = "") ;~ #include <array.au3> ;~ $msg_normal = 0 If IsArray($variable1) Then _ArrayDisplay($variable1) Else If $variable2 <> "" Then $variable1 &= @CRLF & $variable2 EndIf If $variable3 <> "" Then $variable1 &= @CRLF & $variable3 EndIf ClipPut($variable1) MsgBox($msg_normal, "Debug", $variable1) EndIf EndFunc ;==>Debug func _Exit() Exit EndFunc Edited January 29, 2015 by gcue Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2015 Moderators Share Posted January 29, 2015 gcue,Give me some runnable code and I will look into it. 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...
gcue Posted January 29, 2015 Author Share Posted January 29, 2015 ok give me a few sorry bout that Link to comment Share on other sites More sharing options...
gcue Posted January 29, 2015 Author Share Posted January 29, 2015 updated thanks so when i click i get index but when i hit arrow keys i do not - i get some weird number Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2015 Moderators Share Posted January 29, 2015 (edited) gcue,The $LVN_KEYDOWN message does not fill an "index" field, so you cannot read it directly. >I am looking into how you might get it. M23 Edited January 29, 2015 by Melba23 Typo 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...
Moderators Melba23 Posted January 29, 2015 Moderators Share Posted January 29, 2015 gcue,Here you go: expandcollapse popup#include <Array.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> Opt("GUIOnEventMode", 1) $bKeyDown = False $msg_normal = 262144 $iWindowStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING) $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) $custom_portfolios_child = GUICreate("Custom Collections", 485, 570) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $custom_portfolios_listview = GUICtrlCreateListView("CUSTOM COLLECTIONS", 15, 110, 200, 310, -1, $iExWindowStyle) $symbols_listview = GUICtrlCreateListView("SYMBOLS", 260, 110, 200, 310, $iWindowStyle, $iExWindowStyle) GUICtrlCreateButton("Exit", 205, 500, 70, 20) GUICtrlSetOnEvent(-1, "_Exit") GUICtrlCreateListViewItem("test1", $custom_portfolios_listview) GUICtrlCreateListViewItem("test2", $custom_portfolios_listview) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Sleep(10) ; If flag set If $bKeyDown Then ; Get selection $KeyIndex = _GUICtrlListView_GetSelectedIndices($custom_portfolios_listview, False) ConsoleWrite($KeyIndex & @CRLF) ; Clear flag $bKeyDown = False EndIf WEnd Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $index $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) $hWndFrom = DllStructGetData($tStruct, 1) $idFrom = DllStructGetData($tStruct, 2) $code = DllStructGetData($tStruct, 3) $index = DllStructGetData($tStruct, 4) Switch $code Case $NM_CLICK Switch $idFrom Case $custom_portfolios_listview ConsoleWrite("+Click: " & $index & @CRLF) EndSwitch Case $LVN_KEYDOWN Switch $idFrom Case $custom_portfolios_listview $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) $key_code = Hex(DllStructGetData($tInfo, "VKey"), 2) Switch $key_code Case 26 ConsoleWrite("-UP - ") Case 28 ConsoleWrite("-Down - ") EndSwitch ; Set flag $bKeyDown = True EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Func _Exit() Exit EndFunc ;==>_ExitM23 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...
gcue Posted January 30, 2015 Author Share Posted January 30, 2015 thanks for your help melba.. but i am still not getting the listview index from $LVN_KEYDOWN. i replaced this Switch $key_code Case 26 ConsoleWrite("-UP - ") Case 28 ConsoleWrite("-Down - ") EndSwitch with this Switch $key_code Case 26 ConsoleWrite("-UP - " & $index) Case 28 ConsoleWrite("-Down - " & $index) EndSwitch behavior still works but still no $index Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2015 Moderators Share Posted January 30, 2015 gcue,Did you read what I posted above: The $LVN_KEYDOWN message does not fill an "index" field, so you cannot read it directlyGo and look at the LVN_KEYDOWN page on MSDN and you will see that there is no "index" field that you can read in any of the structures that you can access. So you have to go the roundabout route that I used. 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...
gcue Posted January 30, 2015 Author Share Posted January 30, 2015 gcue, Did you read what I posted above: Go and look at the LVN_KEYDOWN page on MSDN and you will see that there is no "index" field that you can read in any of the structures that you can access. So you have to go the roundabout route that I used. M23 ah ok i read what you had said and thought that your round about way would get me index. your method certainly works to know which key is pressed - thanks for that. however, i still need to know which listview item is being impacted when using arrow keys.. so it sounds like theres no way to do that or am i missing something? thanks again for your help Link to comment Share on other sites More sharing options...
gcue Posted January 30, 2015 Author Share Posted January 30, 2015 (edited) hmm i was able to do it this way... pretty dirty i know... for some reason the index #s are off.. weird Switch $key_code Case 26 For $x = 0 To $item_count - 1 $selected = _GUICtrlListView_GetItemSelected($custom_portfolios_listview, $x) If $selected = True Then $selected_index = $x ExitLoop EndIf Next ConsoleWrite("-UP- " & $selected_index) Case 28 For $x = 0 To $item_count - 1 $selected = _GUICtrlListView_GetItemSelected($custom_portfolios_listview, $x) If $selected = True Then $selected_index = $x ExitLoop EndIf Next ConsoleWrite("-DOWN- " & $selected_index) EndSwitch Edited January 30, 2015 by gcue Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2015 Moderators Share Posted January 30, 2015 gcue, i still need to know which listview item is being impacted when using arrow keys.. so it sounds like theres no way to do that or am i missing something?Did you actually run the code I posted in post #6 above? It returns the selected index in the SciTE console whenever you click or use the up/down keys within the ListView. It uses essentially the same trick as you have posted above (_GUICtrlListView_GetItemSelected) but rather than use it in the handler (before the ListView has had time to react) my code sets a flag and reads the selection once the script has returned to the main loop. That way you get the correct index. 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...
gcue Posted January 30, 2015 Author Share Posted January 30, 2015 i did but it doesnt output 0 when i use the arrows Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2015 Moderators Share Posted January 30, 2015 gcue,This is what I get when I run the posted code and click on the top line followed by using the down and up keys:>Running:(3.3.13.19):D:\Program\AutoIt3\Beta\autoit3.exe "D:\Program\Au3 Scripts\fred1.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop +Click: 0 -Down - 1 -UP - 0 -Down - 1 -UP - 0 +>18:23:42 AutoIt3.exe ended.rc:0You can see the initial click on the top row and then the key detections with the index changing accordingly. Do you not get a similar result? 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...
gcue Posted January 30, 2015 Author Share Posted January 30, 2015 if you click item 0 first then hit arrow? this is what i get >Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\New Script.au3" +Click: 0 -UP - -Down - 0 -UP - 0 -UP - 0 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2015 Moderators Share Posted January 31, 2015 gcue, Running:(3.3.6.1):Running a nearly 5 year old release might well have something to do with that. 3.3.6.1 (16th April, 2010) (Release)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...
gcue Posted February 3, 2015 Author Share Posted February 3, 2015 hehe ya i know i been meaning to upgrade. ill try that thanks Link to comment Share on other sites More sharing options...
Peng Posted December 19, 2015 Share Posted December 19, 2015 hmm i was able to do it this way... pretty dirty i know... for some reason the index #s are off.. weirdgcue,The "dirty way" solved my issue, thank you! 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