Jump to content

Clickable list with shell commands


hausl78
 Share

Recommended Posts

There seems not to be any SetOnEvent with Double klick as is know from former VB6. I found this via google, but on an double klick on an element nothtin happens. I dont know how the event knows on which element the double klick was, because there ist no realy "binding" from the event to toe control

 

; -----------------------------------------------------------------------------
;  S T A R T   P R O G R A M
; -----------------------------------------------------------------------------

Global $WM_NOTIFY, $fDblClk, $NM_DBLCLK

; Register "Click on ListView function"
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

GUIMain()

While 1
; Check if mouse has doubleclicked
    If $fDblClk = True Then
          ConsoleWrite("Yep")
        Else
        $fDblClk = False

    EndIf
Wend

; Deregister "Click on ListView function"
GUIRegisterMsg($WM_NOTIFY, "")


; -----------------------------------------------------------------------------
;  G U I
; -----------------------------------------------------------------------------
Func GUIMain()
    Global $aSectionArray, $aSectionNameArray
    Global $Artist, $Title, $Path, $Time
    Local $hGUIMain = GUICreate('Video Launcher', 500, 300, 300, 150, -1)

    GUISetOnEvent($GUI_EVENT_CLOSE, 'exitProgramm', $hGUIMain)

    Local $idListview = GUICtrlCreateListView('Interpret|Titel|Datei|Timecode', 20, 50, 450, 200)
    Global $sFilePath = @ScriptDir & '\songs.ini'
    GUISetState(@SW_SHOW)

    $aSectionNameArray = IniReadSectionNames($sFilePath)
    For $A = 1 To $aSectionNameArray[0]
        $Artist = IniRead($sFilePath, $aSectionNameArray[$A], 'artist', 'error')
        $Title = IniRead($sFilePath, $aSectionNameArray[$A], 'title', 'error')
        $Path = IniRead($sFilePath, $aSectionNameArray[$A], 'filepath', 'error')
        $Time = IniRead($sFilePath, $aSectionNameArray[$A], 'timecode', 'error')
        GUICtrlCreateListViewItem($Artist & '|' & $Title & '|' & $Path & '|' & $Time, $idListview)
    Next
EndFunc


; -----------------------------------------------------------------------------
;  F U N C T I O N S
; -----------------------------------------------------------------------------

; Handle Doubleclick
Func MY_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then
        $fDblClk = True
    EndIf
    $tNMHDR = 0
EndFunc

 

Link to comment
Share on other sites

I found another thread with another try, but also here nothing happens on click and also no errur occurs. Hm.. how to start debug this..

Is there really no possibility to bind an double click on an event like you can in JavaScript e.g.

Global $WM_NOTIFY, $idListview

GUIMain()

While 1
    sleep(10)
Wend


; -----------------------------------------------------------------------------
;  G U I
; -----------------------------------------------------------------------------
Func GUIMain()
    Global $aSectionArray, $aSectionNameArray
    Global $Artist, $Title, $Path, $Time
    Local $hGUIMain = GUICreate('Video Launcher', 500, 300, 300, 150, -1)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetOnEvent($GUI_EVENT_CLOSE, 'exitProgramm', $hGUIMain)

    Local $idListview = GUICtrlCreateListView('Interpret|Titel|Datei|Timecode', 20, 50, 450, 200)
    Global $sFilePath = @ScriptDir & '\songs.ini'
    GUISetState(@SW_SHOW)

    $aSectionNameArray = IniReadSectionNames($sFilePath)
    For $A = 1 To $aSectionNameArray[0]
        $Artist = IniRead($sFilePath, $aSectionNameArray[$A], 'artist', 'error')
        $Title = IniRead($sFilePath, $aSectionNameArray[$A], 'title', 'error')
        $Path = IniRead($sFilePath, $aSectionNameArray[$A], 'filepath', 'error')
        $Time = IniRead($sFilePath, $aSectionNameArray[$A], 'timecode', 'error')
        GUICtrlCreateListViewItem($Artist & '|' & $Title & '|' & $Path & '|' & $Time, $idListview)
    Next
EndFunc


; -----------------------------------------------------------------------------
;  F U N C T I O N S
; -----------------------------------------------------------------------------
Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $idListview And $code = -3 Then
        ConsoleWrite("yeah")
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

@hausl78
Maybe this could help you :)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

; Ctrl + F
HotKeySet("^f", "SearchTrack")

#Region ### START Koda GUI section ### Form=
Global $frmMainForm = GUICreate("frmMainForm", 405, 293, -1, -1)
GUISetFont(10, 400, 0, "Arial")
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication")
Global $lvwListView = GUICtrlCreateListView("Artist|Track|Video Path|Video Pos", 7, 9, 394, 278, BitOR($LVS_REPORT, $GUI_SS_DEFAULT_LISTVIEW), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
Global $hdlListView = GUICtrlGetHandle($lvwListView)
_GUICtrlListView_SetColumnWidth($lvwListView, 0, 100)
_GUICtrlListView_SetColumnWidth($lvwListView, 1, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($lvwListView, 2, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($lvwListView, 3, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW, $frmMainForm)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
#EndRegion ### END Koda GUI section ###

Global $strINIFile = @ScriptDir & "\Tracks.ini"

; Create Tracks.ini with 200 Tracks ( to run only once )
; CreateTracksFile()

; Adding some tracks to the ListView
AddTracksToListView()


While 1
    Sleep(100)
WEnd


Func ExitApplication()
    Exit
EndFunc

Func CreateTracksFile()

    Local $arrSectionValues[1][2], _
          $strArrayItem = ""

    If FileExists($strINIFile) Then FileDelete($strINIFile)

    _FileCreate($strINIFile)

    _GUICtrlListView_BeginUpdate($lvwListView)

    For $i = 1 To 200 Step 1

        $arrSectionValues[0][0] = 4
        $arrSectionValues[0][1] = ""

        $strArrayItem = "Artist"& "|" & "Artist " & $i & @CRLF & _
                        "Track"& "|" & "Track " & $i & @CRLF & _
                        "VideoPath"& "|" & "Video Path " & $i & @CRLF & _
                        "VideoPos"& "|" & "Video Pos " & $i

        _ArrayAdd($arrSectionValues, $strArrayItem)
        If @error Then Return ConsoleWrite("Error while adding the item '" & $strArrayItem & "' in the array. Error: " & @error & @CRLF)

        IniWriteSection($strINIFile, "Track" & $i, $arrSectionValues)
        If @error Then ConsoleWrite("Error while creating the section. Error: " & @error & @CRLF)

        Local $arrSectionValues[1][2]
    Next

    _GUICtrlListView_EndUpdate($lvwListView)

EndFunc

Func AddTracksToListView()

    Local $arrSections, _
          $arrSectionValues, _
          $strListViewItem = ""


    $arrSections = IniReadSectionNames($strINIFile)
    If @error Then
        ConsoleWrite("Error while reading the section names in the file '" & $strINIFile & "'. Error: " & @error & @CRLF)
    Else
        _GUICtrlListView_BeginUpdate($lvwListView)
        For $i = 1 To $arrSections[0] Step 1
            $arrSectionValues = IniReadSection($strINIFile, $arrSections[$i])
            If @error Then
                ConsoleWrite("Error while reading the section '" & $arrSections[$i] & "'. Error: " & @error & @CRLF)
            Else
                For $j = 1 To $arrSectionValues[0][0] Step 1
                    $strListViewItem &= $arrSectionValues[$j][1] & "|"
                Next
                GUICtrlCreateListViewItem($strListViewItem, $lvwListView)
                $strListViewItem = ""
            EndIf
        Next
        _GUICtrlListView_EndUpdate($lvwListView)
    EndIf

EndFunc

Func SearchTrack()

    Local $strSearchText = "", _
          $intItemIndex = 0

    $strSearchText = InputBox("Search Track:", "Enter the string you want to look for:", "")
    If @error = 1 Then
        MsgBox($MB_ICONINFORMATION, "", "No text entered.", 5)
        Return
    ElseIf Not @error Then
        $intItemIndex = _GUICtrlListView_FindInText($lvwListView, $strSearchText)

        If $intItemIndex = -1 Then
            MsgBox($MB_ICONWARNING, "", "The text '" & $strSearchText & "' has not been found.")
        Else
            _GUICtrlListView_SetItemSelected($lvwListView, $intItemIndex, True, True)
            If @error Then
                ConsoleWrite("Error while selecting the item #" & $intItemIndex & " in the ListView. Error: " & @error & @CRLF)
            Else
                _GUICtrlListView_EnsureVisible($lvwListView, $intItemIndex)
            EndIf
        EndIf
    EndIf

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMHDR, _
          $hdlWindowFrom, _
          $intControlID_From, _
          $intMessageCode, _
          $tNMLISTVIEW


    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Then Return

    $hdlWindowFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $intMessageCode = DllStructGetData($tNMHDR, "Code")

    Switch $hdlWindowFrom
        Case $hdlListView
            Switch $intMessageCode
                ; Column Click
                Case $LVN_COLUMNCLICK
                    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    If @error Then Return

                    ConsoleWrite("Item: " & DllStructGetData($tNMLISTVIEW, "Item") & @CRLF & _
                                 "SubItem: " & DllStructGetData($tNMLISTVIEW, "SubItem") & @CRLF & _ ; This parameter tells you the Column clicked
                                 "New State: " & DllStructGetData($tNMLISTVIEW, "NewState") & @CRLF & _
                                 "Old State: " & DllStructGetData($tNMLISTVIEW, "OldState") & @CRLF & _
                                 "Changed: " & DllStructGetData($tNMLISTVIEW, "Changed") & @CRLF & _
                                 "Action X: " & DllStructGetData($tNMLISTVIEW, "ActionX") & @CRLF & _
                                 "Action Y: " & DllStructGetData($tNMLISTVIEW, "ActionY") & @CRLF & _
                                 "Param: " & DllStructGetData($tNMLISTVIEW, "Param") & @CRLF)

                ; ListView Click
                Case $NM_CLICK
                    ConsoleWrite("Item clicked!" & @CRLF)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Wow thank you, this can help me sure, so i can analze it because it seems not simple to me with, especialy the WM_NOTIFY Function. I used this on my ini File and asking how can i identify the clicked item? Are the data in the "background" to call or is it possible to fetch then again (like if you have an id and get the row out of a DB).

Link to comment
Share on other sites

16 minutes ago, hausl78 said:

how can i identify the clicked item?

If you want to identify the item clicked, you have to use the structure NMITEMACTIVATE :)

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMHDR, _
          $hdlWindowFrom, _
          $intControlID_From, _
          $intMessageCode, _
          $tNMLISTVIEW, _
          $tNMITEMACTIVATE


    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Then Return

    $hdlWindowFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $intMessageCode = DllStructGetData($tNMHDR, "Code")

    Switch $hdlWindowFrom
        Case $hdlListView
            Switch $intMessageCode
                ; Column Click
                Case $LVN_COLUMNCLICK
                    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    If @error Then Return

                    ConsoleWrite("Item: " & DllStructGetData($tNMLISTVIEW, "Item") & @CRLF & _
                                 "SubItem: " & DllStructGetData($tNMLISTVIEW, "SubItem") & @CRLF & _ ; This parameter tells you the Column clicked
                                 "New State: " & DllStructGetData($tNMLISTVIEW, "NewState") & @CRLF & _
                                 "Old State: " & DllStructGetData($tNMLISTVIEW, "OldState") & @CRLF & _
                                 "Changed: " & DllStructGetData($tNMLISTVIEW, "Changed") & @CRLF & _
                                 "Action X: " & DllStructGetData($tNMLISTVIEW, "ActionX") & @CRLF & _
                                 "Action Y: " & DllStructGetData($tNMLISTVIEW, "ActionY") & @CRLF & _
                                 "Param: " & DllStructGetData($tNMLISTVIEW, "Param") & @CRLF)

                ; ListView Click
                Case $NM_CLICK
                    $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    If @error Then Return

                    ConsoleWrite("Index: " & DllStructGetData($tNMITEMACTIVATE, "Index") & @CRLF & _     ; The ListView Item Index ( Row )
                                 "SubItem: " & DllStructGetData($tNMITEMACTIVATE, "SubItem") & @CRLF)    ; The ListView SubItem ( Column )
                                 ; Other Parameters...

            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Ah ok thats tricky. Now i got the index. As is can see in your Link its not possible to get the array/line data directly from the Win API. So now i have to use the Index i get back and search within the ini Arrays for the data to this number, correct?

Edited by hausl78
Link to comment
Share on other sites

Too late now i see, but just in case someone else needs this

; -----------------------------------------------------------------------------
;  S T A R T   O P T I O N S
; -----------------------------------------------------------------------------
; no tray-icon
#NoTrayIcon
; OnEvent Modus
AutoItSetOption('GUIOnEventMode', 1)
; ~ option explicit
AutoItSetOption('MustDeclareVars', 1)
; ESC trigger $GUI_EVENT_CLOSE ?
AutoItSetOption('GUICloseOnESC', 1)

; -----------------------------------------------------------------------------
;  I N C L U D E S
; -----------------------------------------------------------------------------
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <Misc.au3>
Global $aSectionArray, $aSectionNameArray, $SearchWindow, $GetLTLV, $ReadInpt, $Srch, $Rd = ''
Global $Artist, $Title, $Path, $Time, $hGUIMain, $idListview, $SearchCursorInfo, $GetItemTxt
Global $hDLL = DllOpen("user32.dll")
Global $sFilePath = @ScriptDir & '\songs.ini'
; -----------------------------------------------------------------------------
;  S T A R T   P R O G R A M
; -----------------------------------------------------------------------------

GUIMain()

; -----------------------------------------------------------------------------
;  G U I
; -----------------------------------------------------------------------------

Func GUIMain()
    $hGUIMain = GUICreate('Video Launcher', 500, 300, 300, 150, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'exitProgramm', $hGUIMain)
    $idListview = GUICtrlCreateListView('Interpret|Titel|Datei|Timecode', 20, 50, 450, 200)
    GUISetState(@SW_SHOW)
    ;=============================================================================
    $Srch = GUICtrlCreateInput('', 20, 260, 150, 23)
    ;=============================================================================
    Load()
EndFunc   ;==>GUIMain

;=============================================================================

While 1
    $SearchWindow = WinGetState($hGUIMain)
    If BitAND($SearchWindow, 8) Then
        $SearchCursorInfo = GUIGetCursorInfo($hGUIMain)
        If $SearchCursorInfo[4] = $idListview Then
            If _IsPressed("01", $hDLL) Then
                Sleep(10)
                If _IsPressed("01", $hDLL) Then
                    $GetLTLV = _GUICtrlListView_GetNextItem($idListview, -1, 0, 8)
                    If $GetLTLV <> -1 Then
                        $GetItemTxt = _GUICtrlListView_GetItemText($idListview, $GetLTLV, 0)
                        MsgBox(64, '', $GetItemTxt)
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
    ;=============================================================================
    $ReadInpt = GUICtrlRead($Srch)
    If $Rd <> $ReadInpt Then
        _GUICtrlListView_DeleteAllItems($idListview)
        $Rd = $ReadInpt
        If StringLen($ReadInpt) > 2 Then
            $aSectionNameArray = IniReadSectionNames($sFilePath)
            For $A = 1 To $aSectionNameArray[0]
                If StringInStr(IniRead($sFilePath, $aSectionNameArray[$A], 'artist', 'error'), $ReadInpt) <> 0 Or StringInStr(IniRead($sFilePath, $aSectionNameArray[$A], 'title', 'error'), $ReadInpt) <> 0 Then
                    $Artist = IniRead($sFilePath, $aSectionNameArray[$A], 'artist', 'error')
                    $Title = IniRead($sFilePath, $aSectionNameArray[$A], 'title', 'error')
                    $Path = IniRead($sFilePath, $aSectionNameArray[$A], 'filepath', 'error')
                    $Time = IniRead($sFilePath, $aSectionNameArray[$A], 'timecode', 'error')
                    GUICtrlCreateListViewItem($Artist & '|' & $Title & '|' & $Path & '|' & $Time, $idListview)
                EndIf
            Next
            Else
            _GUICtrlListView_DeleteAllItems($idListview)
            Load()
        EndIf
    EndIf
    Sleep(100)
WEnd

; ----------------------------------------------------------------------------
;  F U N C T I O N S
; -----------------------------------------------------------------------------
;=============================================================================

Func Load()
    $aSectionNameArray = IniReadSectionNames($sFilePath)
    For $A = 1 To $aSectionNameArray[0]
        $Artist = IniRead($sFilePath, $aSectionNameArray[$A], 'artist', 'error')
        $Title = IniRead($sFilePath, $aSectionNameArray[$A], 'title', 'error')
        $Path = IniRead($sFilePath, $aSectionNameArray[$A], 'filepath', 'error')
        $Time = IniRead($sFilePath, $aSectionNameArray[$A], 'timecode', 'error')
        GUICtrlCreateListViewItem($Artist & '|' & $Title & '|' & $Path & '|' & $Time, $idListview)
    Next
EndFunc   ;==>Load
;=============================================================================
; Handle event
Func exitProgramm()
    Exit
EndFunc   ;==>exitProgramm

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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