home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / vbasic / Data / Utils / cmdbtnx5.msi / Cabs.w1.cab / FileCommonDialogs.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-09  |  8.9 KB  |  256 lines

  1. Attribute VB_Name = "modFileCommonDialogs"
  2. Attribute VB_HelpID = 3208
  3.  
  4. '--------------------------------------'
  5. '            Ariad Development Library '
  6. '                          Version 3.0 '
  7. '--------------------------------------'
  8. '                  File Common Dialogs '
  9. '                          Version 2.0 '
  10. '--------------------------------------'
  11. 'Copyright ⌐ 1999 by Ariad Software. All Rights Reserved.
  12.  
  13. 'Created        : 21/09/1999
  14. 'Completed      :
  15. 'Last Updated   :
  16.  
  17.  
  18. Option Explicit
  19. DefInt A-Z
  20.  
  21. Public Declare Function CommDlgExtendedError Lib "COMDLG32.DLL" () As Long
  22. Public Declare Function GetOpenFileName Lib "COMDLG32.DLL" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  23. Public Declare Function GetSaveFileName Lib "COMDLG32.DLL" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
  24.  
  25. Public Type OPENFILENAME
  26.  lStructSize        As Long
  27.  hWndOwner          As Long
  28.  hInstance          As Long
  29.  lpStrFilter        As String
  30.  lpStrCustomFilter  As String
  31.  nMaxCustFilter     As Long
  32.  nFilterIndex       As Long
  33.  lpStrFile          As String
  34.  nMaxFile           As Long
  35.  lpStrFileTitle     As String
  36.  nMaxFileTitle      As Long
  37.  lpStrInitialDir    As String
  38.  lpStrTitle         As String
  39.  Flags              As Long
  40.  nFileOffset        As Integer
  41.  nFileExtension     As Integer
  42.  lpStrDefExt        As String
  43.  lCustData          As Long
  44.  lpfnHook           As Long
  45.  lpTemplateName     As String
  46. End Type
  47.  
  48. Public Enum CDFileModes
  49.  cdfmOpenFile
  50.  cdfmOpenFileOrPrompt
  51.  cdfmSaveFile
  52.  cdfmSaveFileNoConfirm
  53. End Enum
  54.  
  55. Public Enum CDFileFlags
  56.  OFN_ALLOWMULTISELECT = &H200
  57.  OFN_CREATEPROMPT = &H2000
  58.  OFN_ENABLEHOOK = &H20
  59.  OFN_ENABLETEMPLATE = &H40
  60.  OFN_ENABLETEMPLATEHANDLE = &H80
  61.  OFN_EXPLORER = &H80000
  62.  OFN_EXTENSIONDIFFERENT = &H400
  63.  OFN_FILEMUSTEXIST = &H1000
  64.  OFN_HIDEREADONLY = &H4
  65.  OFN_LONGNAMES = &H200000
  66.  OFN_NOCHANGEDIR = &H8
  67.  OFN_NODEREFERENCELINKS = &H100000
  68.  OFN_NOLONGNAMES = &H40000
  69.  OFN_NONETWORKBUTTON = &H20000
  70.  OFN_NOREADONLYRETURN = &H8000
  71.  OFN_NOTESTFILECREATE = &H10000
  72.  OFN_NOVALIDATE = &H100
  73.  OFN_OVERWRITEPROMPT = &H2
  74.  OFN_PATHMUSTEXIST = &H800
  75.  OFN_READONLY = &H1
  76.  OFN_SHAREAWARE = &H4000
  77.  OFN_SHAREFALLTHROUGH = 2
  78.  OFN_SHAREWARN = 0
  79.  OFN_SHARENOWARN = 1
  80.  OFN_SHOWHELP = &H10
  81.  OFS_MAXPATHNAME = 128
  82. End Enum
  83.  
  84. Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_NODEREFERENCELINKS Or OFN_HIDEREADONLY
  85. Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST
  86.  
  87. Public OFN As OPENFILENAME
  88. Attribute OFN.VB_VarHelpID = 3211
  89.  
  90.  
  91. '-------------------------------------------------------
  92. 'Name        : CreatePath
  93. 'Created     : 07/02/2000 16:06
  94. '-------------------------------------------------------
  95. 'Author      : Richard Moss
  96. 'Organisation: Ariad Software
  97. '-------------------------------------------------------
  98. 'Description : Creates a new path.
  99. '-------------------------------------------------------
  100. 'Returns     : Returns True on Success, otherwise False
  101. '-------------------------------------------------------
  102. 'Updates     :
  103. '
  104. '-------------------------------------------------------
  105. '               Ariad Procedure Builder Add-In 1.00.0035
  106. Public Function CreatePath(ByVal DestPath$) As Boolean
  107. Attribute CreatePath.VB_HelpID = 3212
  108.  Dim Temp$, DP$
  109.  Dim BackPos, ForePos
  110.  Dim P
  111.  DP$ = DestPath$
  112.  P = Screen.MousePointer
  113.  Screen.MousePointer = 11
  114.   If Right$(DP$, 1) <> "\" Then DP$ = DP$ + "\"
  115.   On Error Resume Next
  116.    'Change to root directory of dest drive
  117.    ChDrive DP$
  118.    If Err <> 0 Then GoTo ErrorOut
  119.    ChDir "\"
  120.    'Make directory
  121.    BackPos = 3
  122.    ForePos = InStr(4, DP$, "\")
  123.    Do While ForePos <> 0
  124.      Temp$ = Mid$(DP$, BackPos + 1, ForePos - BackPos - 1)
  125.     Err = 0
  126.     MkDir Temp$
  127.     If Err <> 0 And Err <> 75 Then GoTo ErrorOut
  128.     Err = 0
  129.     ChDir Temp$
  130.     If Err <> 0 Then GoTo ErrorOut
  131.     BackPos = ForePos
  132.     ForePos = InStr(BackPos + 1, DP$, "\")
  133.    Loop
  134.    CreatePath = -1
  135.   On Error GoTo 0
  136.  Screen.MousePointer = P
  137. Exit Function
  138.  
  139. ErrorOut:
  140.  MsgBox "Invalid path entered." + vbCr + vbCr + DP$, vbCritical
  141.  CreatePath = 0
  142.  Screen.MousePointer = P
  143. End Function '(Public) Function CreatePath () As Boolean
  144.  
  145.  
  146. '----------------------------------------------------------------------
  147. 'Name        : SelectFile
  148. 'Created     : 21/09/1999 08:02
  149. '----------------------------------------------------------------------
  150. 'Author      : Richard Moss
  151. 'Organisation: Ariad Software
  152. '----------------------------------------------------------------------
  153. 'Description : Displays an API created file common dialog and returns
  154. '              the name of the selected file.
  155. '----------------------------------------------------------------------
  156. 'Returns     : Returns a String Variable
  157. '----------------------------------------------------------------------
  158. 'Updates     :
  159. '
  160. '----------------------------------------------------------------------
  161. '                              Ariad Procedure Builder Add-In 1.00.0027
  162. Public Function SelectFile$(ByVal hWndOwner As Long, Optional ByVal Filter$ = "All Files (*.*)|*.*", Optional ByVal DefaultExtension$ = "", Optional ByVal FileMode As CDFileModes = cdfmOpenFile, Optional ByVal DialogCaption$ = "", Optional ByVal DefaultFilename$ = "", Optional ByVal DefaultPath$ = "", Optional ByVal FilterIDX As Long = 0, Optional ByVal MoreFlags As CDFileFlags)
  163. Attribute SelectFile.VB_HelpID = 3213
  164.  Dim R As Long, SP As Long, ShortSize As Long, Z As Long
  165.  'determine defaults
  166.  If InStr(DefaultFilename, "\") Then
  167.   DefaultPath = GetPath$(DefaultFilename)
  168.   DefaultFilename = GetFile$(DefaultFilename)
  169.  End If
  170.  If Len(DefaultPath$) = 0 Then DefaultPath$ = CurDir$
  171.  'fill structure
  172.  With OFN
  173.   .lStructSize = Len(OFN)
  174.   .hWndOwner = hWndOwner
  175.   .hInstance = App.hInstance
  176.   .lpStrFilter = Replace$(Filter$, "|", Chr$(0)) & Chr$(0)
  177.   .nFilterIndex = FilterIDX
  178.   .lpStrFile = DefaultFilename$ & String$(257 - Len(DefaultFilename$), 0)
  179.   .nMaxFile = Len(.lpStrFile) - 1
  180.   .lpStrFileTitle = .lpStrFile
  181.   .nMaxFileTitle = .nMaxFile
  182.   .lpStrDefExt = DefaultExtension$ & Chr$(0)
  183.   .lpStrInitialDir = DefaultPath$ & Chr$(0)
  184.   .lpStrTitle = DialogCaption$ & Chr$(0)
  185.   If FileMode = cdfmSaveFile Or FileMode = cdfmSaveFileNoConfirm Then
  186.    'Flags for save dialog
  187.    .Flags = .Flags Or OFS_FILE_SAVE_FLAGS
  188.    If FileMode <> cdfmSaveFileNoConfirm Then .Flags = .Flags Or OFN_OVERWRITEPROMPT
  189.    R = GetSaveFileName(OFN)
  190.   ElseIf FileMode = cdfmOpenFile Or FileMode = cdfmOpenFileOrPrompt Then
  191.    'Flags for open dialog
  192.    .Flags = .Flags Or OFS_FILE_OPEN_FLAGS
  193.    If FileMode = cdfmOpenFileOrPrompt Then .Flags = .Flags Or OFN_CREATEPROMPT
  194.    R = GetOpenFileName(OFN)
  195.   End If
  196.   'returnfilename
  197.   If R Then
  198.    SP = InStr(.lpStrFile, Chr$(0))
  199.    If SP Then .lpStrFile = Left$(.lpStrFile, SP - 1)
  200.    SelectFile$ = Trim$(Replace$(.lpStrFile, Chr$(0), ""))
  201.   Else
  202.    Z = CommDlgExtendedError()
  203.    If Z Then MsgBox "Unable to get filename(s)." & vbCr & vbCr & "CommDlgExtendedError returned " & Z, vbCritical
  204.   End If
  205.  End With
  206. End Function '(Public) Function SelectFile () As String
  207.  
  208.  
  209. '----------------------------------------------------------------------
  210. 'Name        : GetFile
  211. 'Created     : 06/07/1999 12:36
  212. 'Modified    :
  213. '----------------------------------------------------------------------
  214. 'Author      : Richard Moss
  215. 'Organisation: Ariad Software
  216. '----------------------------------------------------------------------
  217. 'Description : Extracts the filename from a path
  218. '----------------------------------------------------------------------
  219. 'Returns     : Returns the extracted filename, or the original string if no path exists
  220. '----------------------------------------------------------------------
  221. Private Function GetFile(ByVal PathAndFile$) As String
  222. Attribute GetFile.VB_HelpID = 3214
  223.  Dim R$()
  224.  If Len(PathAndFile$) Then
  225.   R$() = Split(PathAndFile$, "\")
  226.   GetFile$ = R$(UBound(R$))
  227.  End If
  228. End Function '(Public) Function GetFile () As String
  229.  
  230. '----------------------------------------------------------------------
  231. 'Name        : GetPath
  232. 'Created     : 08/08/1999 09:07
  233. 'Modified    :
  234. 'Modified By :
  235. '----------------------------------------------------------------------
  236. 'Author      : Richard James Moss
  237. 'Organisation: Ariad Software
  238. '----------------------------------------------------------------------
  239. 'Description : Removes the filename from path
  240. '----------------------------------------------------------------------
  241. 'Returns     : Returns the path minus it's filename
  242. '----------------------------------------------------------------------
  243. Private Function GetPath(ByVal Filename$) As String
  244. Attribute GetPath.VB_HelpID = 3215
  245.  Dim R$(), P$
  246.  Dim I
  247.  If InStr(Filename$, "\") Then
  248.   R$() = Split(Filename$, "\")
  249.   For I = 0 To UBound(R$) - 1
  250.    P$ = P$ + R$(I) + "\"
  251.   Next
  252.  End If
  253.  GetPath$ = P$
  254. End Function '(Public) Function GetPath () As String
  255.  
  256.