Jump to content

Single-click to trigger event?


Recommended Posts

I've had a little trouble with getting events triggered with ListBoxes in the past... is there a simple way to get the ListBox to notify on single click instead of double click?

It's not difficult. Here is an example someone wrote, but I don't remember who.

#Include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

$Debug_LV = False; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $B_DESCENDING

Local $btnInstall, $btnAdd

$iniFile = @ScriptDir & "\InstaProLauncher.ini"

$hGUI = GUICreate("InstaPro Launcher", 875, 600)

$cListView = GUICtrlCreateListView("", 100, 40, 750, 500, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)


$dummy = GUICtrlCreateDummy()
$lvcm = GUICtrlCreateContextMenu($dummy)
$menuRow = GUICtrlCreateMenuItem("aaa", $lvcm)
$menuCol = GUICtrlCreateMenuItem("aaa",$lvcm)
;Added Code
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
;Added Code End

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
_GUICtrlListView_InsertColumn($hListView, 3, "Column 4", 100)
_GUICtrlListView_InsertColumn($hListView, 4, "Column 5", 100)

_GUICtrlListView_SetColumnWidth($hListView, 0, 150)
_GUICtrlListView_SetColumnWidth($hListView, 1, 296)
_GUICtrlListView_SetColumnWidth($hListView, 2, 100)
_GUICtrlListView_SetColumnWidth($hListView, 3, 100)
_GUICtrlListView_SetColumnWidth($hListView, 4, 100)
    
GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")
Global $setcm = false
Dim $varAI[3][5]
; Add items
For $i = 0 To UBound($varAI) - 1  
    $varAI[$i][0] = $i & "One"
    $varAI[$i][1] = $i & "two"
    $varAI[$i][2] = $i & "three"
    $varAI[$i][3] = $i & "four"
    $varAI[$i][4] = $i & "five"
Next
_GUICtrlListView_AddArray($hListView, $varAI)



$btnInstall = GUICtrlCreateButton("Install", 750, 550, 100)

GUISetState()

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]

Do
    $msg = GUIGetMsg()
        
    if $setcm Then
    ConsoleWrite("uihh" & @CRLF)
    $setcm = False
    TrackPopupMenu($hGui,GuiCtrlGetHandle($lvcm),MouseGetPos(0),MouseGetPos(1))
    EndIf
Until $msg = $GUI_EVENT_CLOSE

Exit



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
         
               ;Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the right mouse button
                 Case $NM_CLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
               ;Return 1; not to allow the default processing
                GuiCtrlSetData($menuRow,"-->Index:" & @TAB & DllStructGetData($tInfo, "Index"))
                GuiCtrlSetData($menuCol,"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem"))
                if DllStructGetData($tInfo, "Index") <> -1 Then $setcm = true
                    Return 0; allow the default processing
                

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY


;Added Function
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    return
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc ;==>_DebugPrint
;Added Function End

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    ConsoleWrite("x,y = " & $hmenu & ',' & $hwnd & @CRLF)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc  ;==>TrackPopupMenu
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...