gcue

wm_notify - unable to get listview index

17 posts in this topic

#1 ·  Posted (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!

 
#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 by gcue

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ok give me a few

sorry bout that

Share this post


Link to post
Share on other sites

updated

thanks

so when i click i get index but when i hit arrow keys i do not - i get some weird number

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

gcue,

Here you go: :)

#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   ;==>_Exit
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 :(

Share this post


Link to post
Share on other sites

gcue,

Did you read what I posted above: :huh:

The $LVN_KEYDOWN message does not fill an "index" field, so you cannot read it directly

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

gcue,

Did you read what I posted above: :huh:

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by gcue

Share this post


Link to post
Share on other sites

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. :huh:

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

i did but it doesnt output 0 when i use the arrows

Share this post


Link to post
Share on other sites

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:0
You 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? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

hehe ya i know i been meaning to upgrade.

ill try that

thanks

Share this post


Link to post
Share on other sites

hmm i was able to do it this way... pretty dirty i know... for some reason the index #s are off.. weird

gcue,

The "dirty way" solved my issue, thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now