home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Mini-Filem509031252002.psc / Module2.bas < prev    next >
Encoding:
BASIC Source File  |  2002-01-19  |  2.5 KB  |  66 lines

  1. Attribute VB_Name = "Module2"
  2. Private Declare Function apiShellExecute Lib "shell32.dll" _
  3.     Alias "ShellExecuteA" _
  4.     (ByVal hwnd As Long, _
  5.     ByVal lpOperation As String, _
  6.     ByVal lpFile As String, _
  7.     ByVal lpParameters As String, _
  8.     ByVal lpDirectory As String, _
  9.     ByVal nShowCmd As Long) _
  10.     As Long
  11.  
  12. '***App Window Constants***
  13. Public Const WIN_NORMAL = 1         'Open Normal
  14. Public Const WIN_MAX = 3            'Open Maximized
  15. Public Const WIN_MIN = 2            'Open Minimized
  16.  
  17. '***Error Codes***
  18. Private Const ERROR_SUCCESS = 32&
  19. Private Const ERROR_NO_ASSOC = 31&
  20. Private Const ERROR_OUT_OF_MEM = 0&
  21. Private Const ERROR_FILE_NOT_FOUND = 2&
  22. Private Const ERROR_PATH_NOT_FOUND = 3&
  23. Private Const ERROR_BAD_FORMAT = 11&
  24.  
  25. '***************Usage Examples***********************
  26. 'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
  27. 'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
  28. 'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
  29. 'Handle Unknown extensions (call Open With Dialog):
  30. '                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
  31. 'Start Access instance:
  32. '                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
  33. '****************************************************
  34.  
  35. Function fHandleFile(stFile As String, lShowHow As Long)
  36. Dim lRet As Long, varTaskID As Variant
  37. Dim stRet As String
  38.     'First try ShellExecute
  39.     lRet = apiShellExecute(hWndAccessApp, vbNullString, _
  40.             stFile, vbNullString, vbNullString, lShowHow)
  41.  
  42.     If lRet > ERROR_SUCCESS Then
  43.         stRet = vbNullString
  44.         lRet = -1
  45.     Else
  46.         Select Case lRet
  47.             Case ERROR_NO_ASSOC:
  48.                 'Try the OpenWith dialog
  49.                 varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & stFile, WIN_NORMAL)
  50.                 lRet = (varTaskID <> 0)
  51.             Case ERROR_OUT_OF_MEM:
  52.                 stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
  53.             Case ERROR_FILE_NOT_FOUND:
  54.                 stRet = "Error: File not found.  Couldn't Execute!"
  55.             Case ERROR_PATH_NOT_FOUND:
  56.                 stRet = "Error: Path not found. Couldn't Execute!"
  57.             Case ERROR_BAD_FORMAT:
  58.                 stRet = "Error:  Bad File Format. Couldn't Execute!"
  59.             Case Else:
  60.         End Select
  61.     End If
  62.     fHandleFile = lRet & _
  63.                 IIf(stRet = "", vbNullString, ", " & stRet)
  64. End Function
  65.  
  66.