Jump to content
Sign in to follow this  
Laymanball

How to select run a program in the listview.?

Recommended Posts

Laymanball

Help me.

DoubleClick on program name in listview to run program.

Thanks.

Edited by Laymanball

My Sample Script

Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html

                     VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html

Share this post


Link to post
Share on other sites
Beege
I believe you would need to register msg WM_NOTIFY to recive a the dbclick msg. Look at GuiListView UDF in the help file. _GuiCtrlListView_SubItemHitTest() gives a good example of using WM_NOTIFY.

Share this post


Link to post
Share on other sites
Melba23

Laymanball,

By chance I posted this yesterday. :graduated:

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
Laymanball

Thanks..Idea.. Beege and Melba23.

But,I would choose to import all the files on the drive or folder into a ListView

and can double click at a program name to run program.

How to write code?

----------------------------------------------------------------------------------

I write new code.

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
$Debug_LV = False
Global $hListView, $pid

_Main()
Func _Main()
    GUICreate("ListView DoubleClick Item", 320, 140, -1, -1)

    GUICtrlCreateLabel("DoubleClick Program name to Run", 75, 10, 167, 17)
    $hListView = GUICtrlCreateListView("", 10, 30, 300, 100)
    _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    _GUICtrlListView_InsertColumn($hListView, 0, "Programs name", 300)
    _GUICtrlListView_AddItem($hListView, "Notepad.exe", 0)
    _GUICtrlListView_AddItem($hListView, "Calc.exe", 1)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

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
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint(DllStructGetData($tInfo, "Index"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _DebugPrint($iIndex)
    ConsoleWrite("--> Line:Index "& $iIndex & @LF)
    Switch $iIndex
        Case 0
            $pid = Run("Notepad.exe")
            Sleep(1500)
            ProcessClose($pid)
        Case 1
            $pid = Run("Calc.exe")
            Sleep(1500)
            ProcessClose($pid)
    EndSwitch
EndFunc

OR

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
$Debug_LV = False
Global $GUI, $hListView, $pid

_Main()
Func _Main()
    $GUI = GUICreate("RunApp in ListView", 320, 240, -1, -1)
    GUICtrlCreateLabel("DoubleClick Program name to Run", 75, 10, 167, 17)
    $hListView = _GUICtrlListView_Create($GUI, "", 10, 30, 300, 200)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_SetUnicodeFormat($hListView, True)
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    _GUICtrlListView_InsertColumn($hListView, 0, "Application:", 100)
     _GUICtrlListView_InsertColumn($hListView, 1, "Target:", 200)
    _GUICtrlListView_AddItem($hListView, "Notepad.exe", 0)
    _GUICtrlListView_AddItem($hListView, "Calc.exe", 1)
     _GUICtrlListView_AddSubItem($hListView, 0, @SystemDir, 1)
     _GUICtrlListView_AddSubItem($hListView, 1, @SystemDir, 1)
 EndFunc

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint(DllStructGetData($tInfo, "Index"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _DebugPrint($iIndex)
    ConsoleWrite("--> Line:Index "& $iIndex & @LF)
    Switch $iIndex
        Case 0
            $pid = Run("Notepad.exe")
            Sleep(1000)
            ProcessClose($pid)
        Case 1
            $pid = Run("Calc.exe")
            Sleep(1000)
            ProcessClose($pid)
        Case -1
            MsgBox(0, "", "No, Program name.", 1, $GUI)
    EndSwitch
EndFunc
Edited by Laymanball

My Sample Script

Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html

                     VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html

Share this post


Link to post
Share on other sites
Melba23

Laymanball,

Use _FileListToArray to get an array of all the *.exe files in the folder and then loop through the array to add them to the ListView. When the item is clicked, concantenate the original path the the name and use Run. :graduated:

If you want to list the executables in subfolders on the path then look at the RecFileListToArray UDF in my sig. ;)

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
Laymanball

Laymanball,

Use _FileListToArray to get an array of all the *.exe files in the folder and then loop through the array to add them to the ListView. When the item is clicked, concantenate the original path the the name and use Run. :graduated:

If you want to list the executables in subfolders on the path then look at the RecFileListToArray UDF in my sig. ;)

M23

Thanks. I will try to write.


My Sample Script

Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html

                     VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html

Share this post


Link to post
Share on other sites
Laymanball

Help me. App in List not run

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

$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
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
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint(DllStructGetData($tInfo, "Index"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _DebugPrint($iIndex)
    ConsoleWrite("--> Line:Index "& $iIndex & @LF)
    Global $ItemText = _GUICtrlListView_GetItemText($hListView, $iIndex)
    Switch $iIndex
        Case 0
            _message()
     Case 1
            _message()
     Case 2
            _message()
      Case 3
            _message()
     Case 4
            _message()
     Case 5
            _message()
     Case 6
            _message()
     Case 7
            _message()
     Case 8
            _message()
      Case 9
            _message()
     Case 10
            _message()
     Case 11
            _message()
     Case -1
         MsgBox(0, "", "No, Program name.", 1, $GUI)
    EndSwitch
EndFunc

Func _message()
    MsgBox(0, "ItemText", $ItemText)
EndFunc

My Sample Script

Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html

                     VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html

Share this post


Link to post
Share on other sites
Melba23

Laymanball,

Interesting - the returned text ends in @CRLF. :graduated:

So you need to remove it before you try to use that text to Run the file: ;)

;#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

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

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
Laymanball

Melba23

I test your code by double click to App name in the ListView.

But, App It no run. Must how do to next.


My Sample Script

Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html

                     VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html

Share this post


Link to post
Share on other sites
Melba23

Laymanball,

It worked when I tried it! :graduated:

Change this bit and post the result which will be written in the SciTE console: ;)

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

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

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
Sign in to follow this  

×