home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / fdlg32 / frmfiled.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-06  |  6.1 KB  |  153 lines

  1. VERSION 4.00
  2. Begin VB.Form frmFileDialogs 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "32-Bit File Dialog APIs"
  5.    ClientHeight    =   1755
  6.    ClientLeft      =   1755
  7.    ClientTop       =   2070
  8.    ClientWidth     =   3435
  9.    Height          =   2445
  10.    Icon            =   "frmFileDialogs.frx":0000
  11.    Left            =   1695
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1755
  16.    ScaleWidth      =   3435
  17.    Top             =   1440
  18.    Width           =   3555
  19.    Begin VB.Label Label2 
  20.       Caption         =   "By David Warren MMC Software CompuServe: 72500,1406 or davidw@mmcsoftware.com"
  21.       ForeColor       =   &H00800000&
  22.       Height          =   615
  23.       Left            =   300
  24.       TabIndex        =   1
  25.       Top             =   1020
  26.       Width           =   2775
  27.    End
  28.    Begin VB.Label Label1 
  29.       Caption         =   "Sample in Visual Basic 4 (32-bit) demonstrating the use of GetOpenFileName and GetSaveFileName"
  30.       ForeColor       =   &H00800000&
  31.       Height          =   795
  32.       Left            =   300
  33.       TabIndex        =   0
  34.       Top             =   120
  35.       Width           =   2775
  36.    End
  37.    Begin VB.Menu mnuFile 
  38.       Caption         =   "&File"
  39.       Begin VB.Menu mnuFileOpenDialog 
  40.          Caption         =   "&Open..."
  41.          Shortcut        =   ^O
  42.       End
  43.       Begin VB.Menu mnuFileSaveAsDialog 
  44.          Caption         =   "Save &as..."
  45.          Shortcut        =   ^A
  46.       End
  47.       Begin VB.Menu mnuSeparator 
  48.          Caption         =   "-"
  49.       End
  50.       Begin VB.Menu mnuFileExitApp 
  51.          Caption         =   "E&xit"
  52.          Shortcut        =   ^X
  53.       End
  54.    End
  55. Attribute VB_Name = "frmFileDialogs"
  56. Attribute VB_Creatable = False
  57. Attribute VB_Exposed = False
  58. Private Sub mnuFileExitApp_Click()
  59.     On Error GoTo mnuFileExitApp_Click_Error
  60.     Unload Me
  61.     End
  62. mnuFileExitApp_Click_Exit:
  63.     Exit Sub
  64. mnuFileExitApp_Click_Error:
  65.     MsgBox "Error: " & Format$(Err) & " " & Error$, , "mnuFileExitApp_Click"
  66.     Resume mnuFileExitApp_Click_Exit
  67. End Sub
  68. Private Sub mnuFileOpenDialog_Click()
  69.     On Error GoTo mnuFileOpenDialog_Click_Error
  70.     Dim file As OPENFILENAME, sFile As String, sFileTitle As String, lResult As Long, iDelim As Integer
  71.     file.lStructSize = Len(file)
  72.     file.hwndOwner = Me.hWnd
  73.     file.Flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST
  74.     'wildcard to display, returns with selected path\file
  75.     file.lpstrFile = "*.exe" & String$(250, 0)
  76.     file.nMaxFile = 255
  77.     'returns with just file name
  78.     file.lpstrFileTitle = String$(255, 0)
  79.     file.nMaxFileTitle = 255
  80.     'set the initial directory, otherwise uses current
  81.     file.lpstrInitialDir = Environ$("WinDir")
  82.     'file type filter
  83.     file.lpstrFilter = "Programs" & Chr$(0) & "*.EXE;*.COM;*.BAT" & Chr$(0) & "MS Word Documents" & Chr$(0) & "*.DOC" & Chr$(0) & Chr$(0)
  84.     file.nFilterIndex = 1
  85.     'dialog title
  86.     file.lpstrTitle = "Open"
  87.     lResult = GetOpenFileName(file)
  88.     If lResult <> 0 Then
  89.         iDelim = InStr(file.lpstrFileTitle, Chr$(0))
  90.         If iDelim > 0 Then
  91.             sFileTitle = Left$(file.lpstrFileTitle, iDelim - 1)
  92.         End If
  93.         iDelim = InStr(file.lpstrFile, Chr$(0))
  94.         If iDelim > 0 Then
  95.             sFile = Left$(file.lpstrFile, iDelim - 1)
  96.         End If
  97.         'file.nFileOffset is the number of characters from the beginning of the
  98.         '  full path to the start of the file name
  99.         'file.nFileExtension is the number of characters from the beginning of the
  100.         '  full path to the file's extention, including the (.)
  101.         MsgBox "File Name is " & sFileTitle & Chr$(13) & Chr$(10) & "Full path and file is " & sFile, , "Open"
  102.     End If
  103. mnuFileOpenDialog_Click_Exit:
  104.     Exit Sub
  105. mnuFileOpenDialog_Click_Error:
  106.     MsgBox "Error: " & Format$(Err) & " " & Error$, , "mnuFileOpenDialog_Click"
  107.     Resume mnuFileOpenDialog_Click_Exit
  108. End Sub
  109. Private Sub mnuFileSaveAsDialog_Click()
  110.     On Error GoTo mnuFileSaveAsDialog_Click_Error
  111.         Dim file As OPENFILENAME, sFile As String, sFileTitle As String, lResult As Long, iDelim As Integer
  112.     file.lStructSize = Len(file)
  113.     file.hwndOwner = Me.hWnd
  114.     file.Flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT
  115.     'If you have a starting file name, put it here, padded with Chr$(0) to make
  116.     'a buffer large enough for return
  117.     file.lpstrFile = String$(255, 0)
  118.     file.nMaxFile = 255
  119.     'returns with just file name
  120.     file.lpstrFileTitle = String$(255, 0)
  121.     file.nMaxFileTitle = 255
  122.     'set the initial directory, otherwise uses current
  123.     file.lpstrInitialDir = Environ$("WinDir")
  124.     'file type filter
  125.     file.lpstrFilter = "Text Files" & Chr$(0) & "*.TXT" & Chr$(0) & Chr$(0)
  126.     file.nFilterIndex = 1
  127.     'dialog title
  128.     file.lpstrTitle = "Save As..."
  129.     'you can provide a default extension; appended if user types none
  130.     file.lpstrDefExt = "TXT"
  131.     lResult = GetSaveFileName(file)
  132.     If lResult <> 0 Then
  133.         'file.nFileOffset is the number of characters from the beginning of the
  134.         '  full path to the start of the file name
  135.         'file.nFileExtension is the number of characters from the beginning of the
  136.         '  full path to the file's extention, including the (.)
  137.         iDelim = InStr(file.lpstrFileTitle, Chr$(0))
  138.         If iDelim > 0 Then
  139.             sFileTitle = Left$(file.lpstrFileTitle, iDelim - 1)
  140.         End If
  141.         iDelim = InStr(file.lpstrFile, Chr$(0))
  142.         If iDelim > 0 Then
  143.             sFile = Left$(file.lpstrFile, iDelim - 1)
  144.         End If
  145.         MsgBox "File Name is " & sFileTitle & Chr$(13) & Chr$(10) & "Full path and file is " & sFile, , "Save As..."
  146.     End If
  147. mnuFileSaveAsDialog_Click_Exit:
  148.     Exit Sub
  149. mnuFileSaveAsDialog_Click_Error:
  150.     MsgBox "Error: " & Format$(Err) & " " & Error$, , "mnuFileSaveAsDialog_Click"
  151.     Resume mnuFileSaveAsDialog_Click_Exit
  152. End Sub
  153.