List/ListView Events Using GuiRegisterMsg

   (6 reviews)
Sign in to follow this  
Followers 0

GaryFrost

1 Screenshot

About This File

Examples of Listbox and ListView events.

Mainly the DoubleClick in both and Click event in ListView

Thought I would provide examples of both being these are asked for quite often.





User Feedback

You may only provide a review once you have downloaded the file.


GaryFrost

  • 5
  

Share this review


Link to review
PaulIA

  • 1
  

Share this review


Link to review
Guest

  • 5
  

Share this review


Link to review
Katrijn

  • 5
  

Share this review


Link to review
Guest

  • 5
  

Share this review


Link to review
mLipok

· Edited by mLipok

  • 4
  

Intresting.

Here are fixed version for Au3.3.12.0

List.au3

 

#include <GuiConstants.au3>
#include <GuiStatusbar.au3>

Global Const $DebugIt = 1
;~ Global Const $WM_COMMAND = 0x0111


$main_GUI = GuiCreate("MyGUI", 460, 280,-1, -1)

$Edit_1 = GuiCtrlCreateEdit("Edit1", 10, 10, 360, 210)
$Input_2 = GuiCtrlCreateInput("Input2", 10, 230, 360, 20)
$List_3 = GuiCtrlCreateList("List3", 380, 10, 70, 240, BitOR($LBS_SORT, $LBS_NOINTEGRALHEIGHT, $LBS_NOTIFY, $WS_TABSTOP))
GUICtrlSetData($List_3,"item2")
$StatusBar1 = _GUICtrlStatusBar_Create($main_GUI, -1, "")
_GUICtrlStatusBar_SetSimple($StatusBar1)

GuiSetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;
    EndSelect
WEnd
Exit

Func List_DoubleClick()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then
        _DebugPrint ("$LBN_DBLCLK: " & GUICtrlRead($List_3))
        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_DBLCLK: " & GUICtrlRead($List_3), $SB_SIMPLEID)
    EndIf
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>ListView_DoubleClick

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam
    Local Const $LBN_ERRSPACE = (-2);
    Local Const $LBN_SELCHANGE = 1;
    Local Const $LBN_DBLCLK = 2;
    Local Const $LBN_SELCANCEL = 3;
    Local Const $LBN_SETFOCUS = 4;
    Local Const $LBN_KILLFOCUS = 5;

    Switch $nID
        Case $List_3
            Switch $nNotifyCode
                Case $LBN_ERRSPACE
                    If $DebugIt Then
                        _DebugPrint ("$LBN_ERRSPACE")
                        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_ERRSPACE", $SB_SIMPLEID)
                    EndIf
                Case $LBN_SELCHANGE
                    If $DebugIt Then
                        _DebugPrint ("$LBN_SELCHANGE")
                        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_SELCHANGE", $SB_SIMPLEID)
                    EndIf
                Case $LBN_SELCANCEL
                    If $DebugIt Then
                        _DebugPrint ("$LBN_SELCANCEL")
                        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_SELCANCEL", $SB_SIMPLEID)
                    EndIf
                Case $LBN_SETFOCUS
                    If $DebugIt Then
                        _DebugPrint ("$LBN_SETFOCUS")
                        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_SETFOCUS", $SB_SIMPLEID)
                    EndIf
                Case $LBN_KILLFOCUS
                    If $DebugIt Then
                        _DebugPrint ("$LBN_KILLFOCUS")
                        _GUICtrlStatusBar_SetText($StatusBar1, "$LBN_KILLFOCUS", $SB_SIMPLEID)
                    EndIf
                Case $LBN_DBLCLK
                    List_DoubleClick()
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

 

 

ListView.au3

 

; Events - ListView
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>
#include <GuiStatusbar.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))
_GUICtrlListView_SetColumnWidth ($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth ($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)
$StatusBar1 = _GUICtrlStatusBar_Create($main_GUI, -1, "")
_GUICtrlStatusBar_SetSimple($StatusBar1)

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
        _DebugPrint ("$NM_CLICK")
        _GUICtrlStatusBar_SetText($StatusBar1, "$NM_CLICK", $SB_SIMPLEID)
    EndIf
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>ListView_Click

Func ListView_DoubleClick()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then
        _DebugPrint ("$NM_DBLCLK")
        _GUICtrlStatusBar_SetText($StatusBar1, "$NM_DBLCLK", $SB_SIMPLEID)
    EndIf
    ;----------------------------------------------------------------------------------------------
    MsgBox(0,"Double Clicked", _GUICtrlListView_GetItemText ($ListView, _GUICtrlListView_GetSelectedIndices($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
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_Notify_Events

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

 

 

 

Share this review


Link to review