Solved

Listview Execution off  sellected Items

Posted on 2000-03-16
14
163 Views
Last Modified: 2006-11-17
Hi,
I Have a listview and i want to execute files in it when a user bubbelclick the sellected item in it. Is there a easy code for it..

Thanks, Folks,,,
0
Comment
Question by:patrickvisser
  • 4
  • 3
  • 2
  • +4
14 Comments
 

Author Comment

by:patrickvisser
ID: 2626038
Need it Badley
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2626109
what's mean? open a file with default application ( txt with notepad, htm with IE, etc.)?
0
 

Author Comment

by:patrickvisser
ID: 2626150
Yes Yes, thats is. Just like the explorer does with files. When you dubbelklick a *.txt file the the notpad starts and when a *.doc is dubbelclk then word is starting..
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2626166
Use this:

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26

Private Sub Command1_Click()
Dim lngResult As Long

    lngResult = ShellExecute(Me.hwnd, "open", List1.List(list1.listindex), vbNullString, "", SW_SHOWNORMAL)

    'If the function fails, the return value is an error value that is less than or equal to 32.
    If lngResult >= 33 Then Exit Sub
   
    Select Case lngResult
        Case 0
            MsgBox "The operating system is out of memory or resources."
        Case ERROR_FILE_NOT_FOUND
            MsgBox "Le document est introuvable."
        Case ERROR_PATH_NOT_FOUND
            MsgBox "Le chemin d'accès est introuvable."
        Case ERROR_BAD_FORMAT
            MsgBox "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)."
        Case SE_ERR_ACCESSDENIED
            MsgBox "The operating system denied access to the specified file."
        Case SE_ERR_ASSOCINCOMPLETE
            MsgBox "The filename association is incomplete or invalid."
        Case SE_ERR_DDEBUSY
            MsgBox "The DDE transaction could not be completed because other DDE transactions were being processed."
        Case SE_ERR_DDEFAIL
            MsgBox "The DDE transaction failed."
        Case SE_ERR_DDETIMEOUT
            MsgBox "The DDE transaction could not be completed because the request timed out."
        Case SE_ERR_DLLNOTFOUND
            MsgBox "The specified dynamic-link library was not found."
        Case SE_ERR_FNF
            MsgBox "The specified file was not found."
        Case SE_ERR_NOASSOC
            MsgBox "Ce type de document n'est pas ASSOCIÉ à une application dans Windows."
        Case SE_ERR_OOM
            MsgBox "There was not enough memory to complete the operation."
        Case SE_ERR_PNF
            MsgBox "The specified path was not found."
        Case SE_ERR_SHARE
            MsgBox "A sharing violation occurred."
    End Select
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2626185
??
Case SE_ERR_NOASSOC
    MsgBox "Ce type de document n'est pas ASSOCIÉ à une application dans Windows."
0
 

Expert Comment

by:chrisblevins
ID: 2626195
Use the Shell function and pass it the Text property (or Tag property, whichever you're using to store the filename). Keep in mind this won't work with non-executable files, and your VB program will have no way of knowing when the called program finishes execution.

0
 

Expert Comment

by:chrisblevins
ID: 2626199
chrisblevins changed the proposed answer to a comment
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Expert Comment

by:TigerZhao
ID: 2626210
'the function ShellOpen will use defautl application open a file, if not success will show "Open With..." dialog

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Sub ShellOpen(strFile As String)
    Dim lngRet As Long
    Dim strDir As String
    lngRet = ShellExecute(GetDesktopWindow, "open", strFile, vbNullString, vbNullString, vbNormalFocus)
    If lngRet < 32 Then
        ' no association exists
        strDir = Space(260)
        lngRet = GetSystemDirectory(strDir, Len(strDir))
        strDir = Left(strDir, lngRet)
        ' show the Open with dialog box
        Call ShellExecute(GetDesktopWindow, vbNullString, "RUNDLL32.EXE", "shell32.dll,OpenAs_RunDLL " & strFile, strDir, vbNormalFocus)
    End If
End Sub
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2626245
Erick37,

"Ce type de document n'est pas ASSOCIÉ à une application dans Windows."

Means: File type is not associated.
0
 

Author Comment

by:patrickvisser
ID: 2626252
Please Engles No FRNS..
0
 
LVL 20

Expert Comment

by:hes
ID: 2626300
As everyboy has said use
Use the following:
(uses a textbox for filename, with path, and a command button to start the file)

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal _
lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
Call ShellExecute(0&, vbNullString, Text1.Text, vbNullString, _
vbNullString, vbNormalFocus)
End Sub
 
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 2626420
That's it patrickvisser - I have to agree.  All 3 of them work (some even in French).
0
 

Author Comment

by:patrickvisser
ID: 2626996
Whel the Code from emoreau works just fine. and i can finnnish my work..
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 2627861
I was the first presenting this solution so I think I deserve the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now