home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / glm2demo.exe / %MAINDIR% / Taskbar / filopen.bas next >
Encoding:
BASIC Source File  |  2002-06-10  |  4.0 KB  |  135 lines

  1. Attribute VB_Name = "Module2"
  2. '*** Standard module with procedures for working with   ***
  3. '*** files. Part of the MDI Notepad sample application. ***
  4. '**********************************************************
  5. Option Explicit
  6.  
  7. Dim dwDialog As dwFileOpenSave
  8.  
  9. Sub Main()
  10.     Set dwDialog = New dwFileOpenSave
  11.     dwDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
  12.     dwDialog.CancelError = True
  13.     dwDialog.MaxFileSize = 260
  14.     dwDialog.FilterIndex = 557
  15.     dwDialog.DefaultExt = "TXT"
  16.     dwDialog.Flags = glmcdOFNExplorer
  17.     dwDialog.DlgWindowOwner = frmMDI.hwnd
  18.     frmMDI.Show
  19. End Sub
  20.  
  21. Sub FileOpenProc()
  22.     Dim intRetVal
  23.     On Error Resume Next
  24.     Dim strOpenFileName As String
  25.     dwDialog.Filename = ""
  26.     dwDialog.ShowOpen
  27.     If Err <> 32755 Then    ' User chose Cancel.
  28.         strOpenFileName = dwDialog.Filename
  29.         ' If the file is larger than 65K, it can't
  30.         ' be opened, so cancel the operation.
  31.         If FileLen(strOpenFileName) > 65000 Then
  32.             MsgBox "The file is too large to open."
  33.             Exit Sub
  34.         End If
  35.         
  36.         OpenFile (strOpenFileName)
  37.         UpdateFileMenu (strOpenFileName)
  38.         ' Show the toolbar if they aren't already visible.
  39.         If gToolsHidden Then
  40.             frmMDI.imgCutButton.Visible = True
  41.             frmMDI.imgCopyButton.Visible = True
  42.             frmMDI.imgPasteButton.Visible = True
  43.             gToolsHidden = False
  44.         End If
  45.     End If
  46. End Sub
  47.  
  48. Function GetFileName(Filename As Variant)
  49.     ' Display a Save As dialog box and return a filename.
  50.     ' If the user chooses Cancel, return an empty string.
  51.     On Error Resume Next
  52.     dwDialog.Filename = Filename
  53.     dwDialog.ShowSave
  54.     If Err <> 32755 Then    ' User chose Cancel.
  55.         GetFileName = dwDialog.Filename
  56.     Else
  57.         GetFileName = ""
  58.     End If
  59. End Function
  60.  
  61. Function OnRecentFilesList(Filename) As Integer
  62.   Dim i         ' Counter variable.
  63.  
  64.   For i = 1 To 4
  65.     If frmMDI.mnuRecentFile(i).Caption = Filename Then
  66.       OnRecentFilesList = True
  67.       Exit Function
  68.     End If
  69.   Next i
  70.     OnRecentFilesList = False
  71. End Function
  72.  
  73. Sub OpenFile(Filename)
  74.     Dim fIndex As Integer
  75.     
  76.     On Error Resume Next
  77.     ' Open the selected file.
  78.     Open Filename For Input As #1
  79.     If Err Then
  80.         MsgBox "Can't open file: " + Filename
  81.         Exit Sub
  82.     End If
  83.     ' Change the mouse pointer to an hourglass.
  84.     Screen.MousePointer = 11
  85.     
  86.     ' Change the form's caption and display the new text.
  87.     fIndex = FindFreeIndex()
  88.     Document(fIndex).Tag = fIndex
  89.     Document(fIndex).Caption = UCase(Filename)
  90.     Document(fIndex).Text1.Text = Input(LOF(1), 1)
  91.     FState(fIndex).Dirty = False
  92.     Document(fIndex).Show
  93.     Close #1
  94.     ' Reset the mouse pointer.
  95.     Screen.MousePointer = 0
  96. End Sub
  97.  
  98. Sub SaveFileAs(Filename)
  99.     On Error Resume Next
  100.     Dim strContents As String
  101.  
  102.     ' Open the file.
  103.     Open Filename For Output As #1
  104.     ' Place the contents of the notepad into a variable.
  105.     strContents = frmMDI.ActiveForm.Text1.Text
  106.     ' Display the hourglass mouse pointer.
  107.     Screen.MousePointer = 11
  108.     ' Write the variable contents to a saved file.
  109.     Print #1, strContents
  110.     Close #1
  111.     ' Reset the mouse pointer.
  112.     Screen.MousePointer = 0
  113.     ' Set the form's caption.
  114.     If Err Then
  115.         MsgBox Error, 48, App.Title
  116.     Else
  117.         frmMDI.ActiveForm.Caption = UCase(Filename)
  118.         ' Reset the dirty flag.
  119.         FState(frmMDI.ActiveForm.Tag).Dirty = False
  120.     End If
  121. End Sub
  122.  
  123. Sub UpdateFileMenu(Filename)
  124.         Dim intRetVal As Integer
  125.         ' Check if the open filename is already in the File menu control array.
  126.         intRetVal = OnRecentFilesList(Filename)
  127.         If Not intRetVal Then
  128.             ' Write open filename to the registry.
  129.             WriteRecentFiles (Filename)
  130.         End If
  131.         ' Update the list of the most recently opened files in the File menu control array.
  132.         GetRecentFiles
  133. End Sub
  134.  
  135.