Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 - CommonDialogControls-Opening Selected Files 1

Status
Not open for further replies.

hafod

Technical User
Mar 14, 2005
73
0
0
GB
Hi
I am using the Common Dialog Controls: FileListBox, DriveListBox and DirListBox (es) to select and launch applications. Whilst the process of displaying all folder files in the FileListBox is straight forward I am having difficulty getting application files (Access .mdb) to launch when double clicking on an executable in the FileList box.

Is there a re usable code segment for filtering and launching these file types?
 
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 Sub File1_DblClick()
ShellExecute hWnd, vbNullString, File1.List(File1.ListIndex), vbNullString, vbNullString, vbNormalFocus
End Sub
 
Hi Hugh,
Thanks very much for your post. I have entered your suggested code (I am not really conversant with Win 32 API). VB reports an error 'Expected: Lib" and highlights 'Shell32.dll' in the 'Private declare ....' line of code. I have included this line in the Generaal - Declarations part of the form on which the Common Dialog boxes reside. Shell32.dll does exist in the Win \system32 sub dir on my pc.
Any suggestions?
Mike
 
>I have entered your suggested code

I think you may have included a typo; have you tried copy/ pasting it from my post.

My code was copy/ pasted from a test VB6 project consisting of a Form having a single FileList Box(called File1). It fires up Access when I double click an MDB file.

I'm a little confused as to whether you are using a combination of FileListBox, DriveListBox and DirListBox (es) on a Form to create a custom File Dialog or an actual Common Dialog Control.
 
You can also use the Shell objects:
Code:
Option Explicit
'Ref to: Microsoft Shell Controls and Automation (Shell32)

Private Sub Command1_Click()
    With New Shell32.Shell
        .NameSpace(ssfDESKTOP).ParseName(App.Path & "\test.mdb").InvokeVerb "open"
    End With
End Sub
 
Hi Hugh/Dilettante,
Thanks for your last post Hugh. There was a typo - corrected by pasing your code. Incidentally, my post was unclear - I am using three 'boxes' to customise a file management interface. Thanks again.

Thanks also dilettante. Will also try your approach to develop my VB codind skills.
Mike

 
Hi
Regarding Hugh's solution
Perhaps a little premature with my last post. Solution launches all executables in the default list displayed in the 'List1' box. The default path for the displayed files is 'C\program files\MicrosoftVisualStudio\VB98' where several executable files reside and can be successfully launched.

However, when this List box is populated using a drive and directory objects providing alternative paths it is no longer possible to 'shell' the file selected 'double clicked'. No error messages appear.

Any suggestions?
Mike

 
Private Sub File1_DblClick()
ShellExecute hWnd, vbNullString, File1.Path & "\" & File1.List(File1.ListIndex), vbNullString, vbNullString, vbNormalFocus
End Sub
 
Hi Hugh,
Excellent! manythanks for your posts - now have a working solution.
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top