Sign in to follow this  
Followers 0
PerryRaptor

Listview Problem -- How Do I Double Click On An Item

6 posts in this topic

Okay ListView GUI Guru's I'm stumped again.

I've decided to use the INI File format for my project and I can get the contents into the ListView without problem.

I do not understand the underlying code needed to setup and detect left and right mouse double clicks.

I want to perform additional actions using the Key Value based on the selected ListView choice.

I do not want to use a ComboBox.

Here is the test.ini file. The included instructions area are invisable as planned.

<instructions go here>
So the goal is to select a key using a double click of a the left mouse button in the ListView allowing additional action to take place
<end instructions>

[Section1]
s1_Key1=s1_value1-1
s1_Key2=s1_value 1 - 2

[Section2]
s2_Key1=s2_value2-1
s2_Key2=s2_value 2 - 2

[Section3]
s3_Key1=s3_value3-1
s3_Key2=s3_value 3 - 2

Here is my start...

#include <GUIConstants.au3>
Opt("TrayIconHide", 1)
Opt("MustDeclareVars", 1)

_Main()

Func _Main()
Local $IniFile = "test.ini"
Local $listview, $msg
GUICreate(".INI File ListView and Action")
$listview = GUICtrlCreateListView("Key Name|Key Value|", 10, 10, 380, 300)
_ReadIniFile($IniFile, $listview)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>_Main() 

Func _ReadIniFile(ByRef $IniFile, ByRef $listview)
Local $Ini_section = IniReadSection($IniFile, "section1")
If Not IsArray($ini_section) Then
    MsgBox(0, ".INI File Listview and Action", "No Entry Found")
Else
   For $i = 1 To $ini_section[0][0]
   GUICtrlCreateListViewItem($ini_section[$i][0] & "|" & $ini_section[$i][1], $listview)
   Next
EndIf
EndFunc ;==>_ReadIniFile()

I'd like to learn the necessary code so please add comments to help me understand it.

Share this post


Link to post
Share on other sites




[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

That's the old way smoke,

; Events - ListView
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>

Global $ListView
Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1

;ListView Events
Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
;~ Global Const $NM_RETURN = ($NM_FIRST - 4)
;~ Global Const $NM_RCLICK = ($NM_FIRST - 5)
;~ Global Const $NM_RDBLCLK = ($NM_FIRST - 6)
;~ Global Const $NM_SETFOCUS = ($NM_FIRST - 7)
;~ Global Const $NM_KILLFOCUS = ($NM_FIRST - 8)
;~ Global Const $NM_CUSTOMDRAW = ($NM_FIRST - 12)
;~ Global Const $NM_HOVER = ($NM_FIRST - 13)
;~ Global Const $NM_NCHITTEST = ($NM_FIRST - 14)
;~ Global Const $NM_KEYDOWN = ($NM_FIRST - 15)
;~ Global Const $NM_RELEASEDCAPTURE = ($NM_FIRST - 16)
;~ Global Const $NM_SETCURSOR = ($NM_FIRST - 17)
;~ Global Const $NM_CHAR = ($NM_FIRST - 18)
;~ Global Const $NM_TOOLTIPSCREATED = ($NM_FIRST - 19)
#endregion End Global variables

Opt("WinTitleMatchMode", 2)

$main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX))

$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL))
_GUICtrlListViewSetColumnWidth ($ListView, 0, 100)
_GUICtrlListViewSetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)
GUISetState()

;Register WM_NOTIFY  events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
   
   $msg = GUIGetMsg()
   
   Switch $msg
      
   ;-----------------------------------------------------------------------------------------
   ;This case statement exits and updates code if needed
      Case $GUI_EVENT_CLOSE
         Exit
         
         
      ;-----------------------------------------------------------------------------------------
      ;put all the misc. stuff here
        Case Else
        ;;;
   EndSwitch
WEnd

Func ListView_Click()
;----------------------------------------------------------------------------------------------
    If $DebugIt Then    ConsoleWrite (_DebugHeader ("$NM_CLICK"))
;----------------------------------------------------------------------------------------------
EndFunc  ;==>ListView_Click

Func ListView_DoubleClick()
;----------------------------------------------------------------------------------------------
    If $DebugIt Then    ConsoleWrite (_DebugHeader ("$NM_DBLCLK"))
;----------------------------------------------------------------------------------------------
    MsgBox(0,"Double Clicked", _GUICtrlListViewGetItemText ($ListView, _GUICtrlListViewGetSelectedIndices($ListView)))
EndFunc  ;==>ListView_DoubleClick

;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
    Case $wParam = $ListView
        Select
            Case $event = $NM_CLICK
                ListView_Click ()
            Case $event = $NM_DBLCLK
                ListView_DoubleClick ()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
EndFunc  ;==>WM_Notify_Events

Func _DebugHeader($s_text)
    Return _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF
EndFunc  ;==>_DebugHeader

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

That's the old way smoke,

Yeah, I gave the wrong link too, wanted to give the one you gave the above example in one of my attempts at it with _IsPressed().

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Gary; however, you've fixed my shortcomings just the same way you helped me with my Question and Answers checklist.

I do not understand the underlying code...can you break it down for me or atleast add comments? I'd like to learn and understand it.

I do not understand the WM Notify() or the DebugHeader() functions, nor do I know where all of the pointers came from.

Edited by PerryRaptor

Share this post


Link to post
Share on other sites

Thanks Gary; however, you've fixed my shortcomings just the same way you helped me with my Question and Answers checklist.

I do not understand the underlying code...can you break it down for me or atleast add comments? I'd like to learn and understand it.

I do not understand the WM Notify() or the DebugHeader() functions, nor do I know where all of the pointers came from.

the DebugHeader is just a little something I use for when debugging

as to understanding the wm notify here's a place to start http://msdn.microsoft.com/library/default....s/wm_notify.asp


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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
Sign in to follow this  
Followers 0