Jump to content

how to capture a click event on a list?


Recommended Posts

  • Moderators

ShadowElf,

Just look for it in your GUIGetMsg loop: :D

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hList = GUICtrlCreateList("", 10, 10, 480, 200)
GUICtrlSetData($hList, "One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            _My_Func()
    EndSwitch

WEnd

Func _My_Func()

    MsgBox(0, "List Item", GUICtrlRead($hList) & " clicked")

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • 9 years later...
#include <GUIConstants.au3>
#NoTrayIcon

;~ Global Const $WM_COMMAND = 0x0111
;~ Global Const $LBN_SELCHANGE = 1
;~ Global Const $LBN_DBLCLK = 2

$Form2 = GUICreate("Menu", 300, 300, 302, 218, -1, $WS_EX_TOPMOST)
;GUISetIcon("C:\Documenti\Icone\cvbxbd.ico")
$GCCList = GUICtrlCreateList("", 10, 10, 220, 300)
$Label1 = GUICtrlCreateLabel("Menu", 20, 32, 140, 30)
;GUICtrlSetFont(-1, 20, 400, 0, "Century Gothic")
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
poplist()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case _IsPressed('0D') And ControlGetFocus($Form2) = 'ListBox1'
            If GUICtrlRead($GCCList) Then
                Run("rundll32 shell32,Control_RunDLL " & GUICtrlRead($GCCList))
                Sleep(10); Delay not to run multiple copies
            EndIf
            Exit
    EndSelect
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam
    If $nID = $GCCList Then
        Switch $nNotifyCode
            Case $LBN_DBLCLK
                If GUICtrlRead($GCCList) Then
                    Run("rundll32 shell32,Control_RunDLL " & GUICtrlRead($GCCList))
                EndIf
                Exit
                Return 0
        EndSwitch
    EndIf
EndFunc   ;==>MY_WM_COMMAND

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc   ;==>_IsPressed

Func Runcpl()
    ;Run (@Comspec & " /c start " &GUICtrlRead($GCCList))
    Run("rundll32 shell32,Control_RunDLL " & GUICtrlRead($GCCList))
EndFunc   ;==>Runcpl

Func poplist()
    $search = FileFindFirstFile(@SystemDir & "\*.cpl")
    If @error Then Return
    While 1
        $file = FileFindNextFile($search)
        If @error Then Return
        GUICtrlSetData($GCCList, $file)
    WEnd
EndFunc   ;==>poplist

 

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