0MikeyJ0

Double click List View Item to run underlying file

6 posts in this topic

Hi All,

First post here and new to AutoIT but not new to scripting, Have previously written a scripts using VBScript and am now converting them to AutoIT.

I'm trying to create a basic GUI that lists the .au3 files in a folder and then lets me run the file directly by double clicking it in the ListView. I've grabbed some code that Melba23 wrote from a 2011 post that seemed to work for Melba but not for the OP. The last post was Melba asking what the console showed with a small rewritten piece of code but OP didn't not answer. Here's the original thread for reference:

https://www.autoitscript.com/forum/topic/133356-how-to-select-run-a-program-in-the-listview/

I seem to have the same issue OP did in that the underlying file in the ListView does not run when it is double clicked. Can anyone see why this might not work?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

;#requireadmin
;#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

;#NoTrayIcon
#include <Array.au3>
#include <ButtonConstants.au3>
#include <File.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$sAppClicked = ""

$GUI = GUICreate("RunApp in ListView", 545, 290, -1, -1)
$Label = GUICtrlCreateLabel("Discript:Files List", 190, 10, 200, 17)
$Button = GUICtrlCreateButton("Browse", 200, 250, 75, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 0)
$hListView = _GUICtrlListView_Create($GUI, "", 10, 30, 525, 200)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_SetUnicodeFormat($hListView, True)
_GUICtrlListView_InsertColumn($hListView, 0, "Application:", 225)
_GUICtrlListView_InsertColumn($hListView, 1, "Target:", 300)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $sFiles = FileSelectFolder("Choose a drive or folder", @DesktopDir, 2)
            If (@error) Or (Not $sFiles) Then Exit
            $iFlist = _FileListToArray($sFiles, "*", 0)
            For $i = 0 To UBound($iFlist) - 1
                _GUICtrlListView_AddItem($hListView, $iFlist[$i] & @CRLF)
            Next
            _GUICtrlListView_DeleteItem($hListView, 0)
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            $Target = $sFiles
            For $x = 0 To $iCount
                _GUICtrlListView_AddSubItem($hListView, $x, $Target, 1)
            Next
            If $iCount Then GUICtrlSetData($Label, "Discript:BoubleClick App name to Run")
    EndSwitch

        If $sAppClicked Then
            $sAppToRun = $sFiles & "\" & StringTrimRight($sAppClicked, 2) ; <<<<<<<< Remove the trailing @CRLF
            Run($sAppToRun)
            $sAppClicked = ""
        EndIf

        ;If $sAppClicked Then
        ;   ConsoleWrite($sAppClicked & " - " & StringToBinary($sAppClicked) & @CRLF)
        ;   $sAppToRun = $sFiles & "\" & StringTrimRight($sAppClicked, 2) ; <<<<<<<< Remove the trailing @CRLF
        ;   Run($sAppToRun)
        ;   $sAppClicked = ""
        ;EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    $sAppClicked = _GUICtrlListView_GetItemText($hWndListView, _GUICtrlListView_GetSelectedIndices($hWndListView))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

The piece of info Melba was asking able from the console that happens when I double click a ListView item is: 0x4469736B4465667261672E6175330D0A.

Thanks!

Mike

Share this post


Link to post
Share on other sites



0MikeyJ0,

Welcome to the AutoIt forums.

Run only works with executable files (EXE, BAT, COM or PIF - as explained in the Help file) so to "run" an .au3 file you need to use ShellExecute.

However, this depends on how you installed AutoIt: if you selected as default "Run the file" then it will work - if you selected "Edit the file" then all it will do is open the file in SciTE.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Ahh! I see what you're saying. So, if I need to use this script set on other pc's that don't have AutoIT installed, I'd need to compile the .au3 files into .exe files?

Share this post


Link to post
Share on other sites

0MikeyJ0,

Or compile the script and use the built-in interpreter to run the other scripts - look in the Help file under <Using AutoIt - Running Scripts - AutoIt specific command Line Switches>.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Can't you also run the AutoIt3.exe with the path to the .au3 file? Then you could just pack up the one AutoIt.exe file and double clicking the script in the list view would pass the path to the exe.

I know you can drag and drop multiple .au3 files on autoit3.exe but I don't know what dependencies autoit3.exe needs in order to run. I'd test it but I don't want to uninstall and then reinstall autoit lol

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

AutoIt doesn't need any dependencies to run when compiled. You can run a script using another script you compiled if you use the correct parameters when compiling.

#pragma compile(AutoItExecuteAllowed, true)

 

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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