Results 1 to 3 of 3

Thread: 2 Q's

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Staffodshire, England
    Posts
    32
    Hi there

    1) How do I open a file in its default viewer/editor?????
    2) Ive got a filelist box, when the user clicks the a file I want a picture box on the same form to show the default icon for the program??

    Can anyone help with these questions?

    Thanks in advance!!

  2. #2
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155

    Post Answer to Question 1

    Well, here is the code I usually use for default programs...
    Code:
    ' Usually in a module...
    Public 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
    Public Const SW_SHOWNORMAL = 1
    
    
    ' A URL to invoke browser
    lResult = ShellExecute(0&, vbNullString, "http://www.vb-world.net/", vbNullString, "C:\", SW_SHOWNORMAL)
    
    ' A URL to invoke mail client
    lResult = ShellExecute(0&, vbNullString, "mailto:[email protected]", vbNullString, "C:\", SW_SHOWNORMAL)
    
    ' Open Notepad, EditPad, etc.
    lResult = ShellExecute(0&, vbNullString, "c:\windows\setup.txt", vbNullString, "C:\", SW_SHOWNORMAL)
    I hope this helps!

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    Hopefully this answers one part.

    'open a file with associated app can be done this way [using API]

    'open a file with it's associated application
    'this example opens addin.txt with notepad
    'put this in a bas module
    '
    Public Declare Function ShellEx Lib "shell32.dll" Alias _
    "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As Any, _
    ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
    '
    Sub ShellDef(strFileName)
    x = ShellEx(Form1.hwnd, "open", strFileName, "", "", 1)
    End Sub

    ' >>> code for event on form <<<
    '
    Dim strYourFileVariable$
    strYourFileVariable = "c:\your folder\yourfile.ext"
    ShellDef strYourFileVariable
    '=====================================
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width