home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD13331132001.psc / Webstore / AppDoc.ctl (.txt) next >
Encoding:
Visual Basic Form  |  2000-12-28  |  8.7 KB  |  245 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.UserControl AppDoc 
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   4800
  8.    InvisibleAtRuntime=   -1  'True
  9.    ScaleHeight     =   3600
  10.    ScaleWidth      =   4800
  11.    Begin MSComDlg.CommonDialog CmnDlg 
  12.       Left            =   3960
  13.       Top             =   240
  14.       _ExtentX        =   847
  15.       _ExtentY        =   847
  16.       _Version        =   393216
  17.    End
  18.    Begin VB.Image Image1 
  19.       Height          =   420
  20.       Left            =   0
  21.       Picture         =   "AppDoc.ctx":0000
  22.       Top             =   0
  23.       Width           =   420
  24.    End
  25. Attribute VB_Name = "AppDoc"
  26. Attribute VB_GlobalNameSpace = False
  27. Attribute VB_Creatable = True
  28. Attribute VB_PredeclaredId = False
  29. Attribute VB_Exposed = False
  30. 'AppDoc - VB5 control demo
  31. 'Copyright (c) 1997 SoftCircuits
  32. 'Redistributed by Permission.
  33. 'This Visual Basic 5.0 example program demonstrates how you can use
  34. 'VB5 controls to encapsulate the logic for keeping track of File New,
  35. 'Open, Save and Save As commands. Simply call the appropriate methods
  36. 'to implement each of these commands.
  37. 'The control saves you time by keeping track of if the current file
  38. 'has been modified and if it has yet been named. All you need to do
  39. 'is implement the code that actually initializes, loads and saves your
  40. 'data. This is done via the NewFile, LoadFile and SaveFile methods
  41. 'that the control calls at the appropriate times.
  42. 'The control is not visible at run time. A sample program is provided
  43. 'to demonstrate use of the control.
  44. 'This program may be distributed on the condition that it is
  45. 'distributed in full and unchanged, and that no fee is charged for
  46. 'such distribution with the exception of reasonable shipping and media
  47. 'charged. In addition, the code in this program may be incorporated
  48. 'into your own programs and the resulting programs may be distributed
  49. 'without payment of royalties.
  50. 'This example program was provided by:
  51. ' SoftCircuits Programming
  52. ' http://www.softcircuits.com
  53. ' P.O. Box 16262
  54. ' Irvine, CA 92623
  55. Option Explicit
  56. Const DEF_FILEFILTER = "HTML Files (*.html)|*.html|HTM Files (*.html)|*.html|iWeb Files (*.iwd)|*.iwd|ASP Files (*.asp)|*.asp|All Files (*.*)|*.*|"
  57. Const DEF_DEFEXTENSION = "100000kb"
  58. Event NewFile(bSuccess As Boolean)
  59. Event LoadFile(sFileName As String, bSuccess As Boolean)
  60. Event SaveFile(sFileName As String, bSuccess As Boolean)
  61. 'Indicates supported file types
  62. Private m_sFileFilter As String
  63. 'Default extension appended to files saved with no extension
  64. Private m_sDefExtension As String
  65. 'File name and title
  66. Private m_sFileName As String
  67. Private m_sFileTitle As String
  68. 'Public property to get/set modified status
  69. Private m_bModified As Boolean
  70. Public Property Let FileFilter(sFileFilter As String)
  71. Attribute FileFilter.VB_Description = "Returns/sets the file filters for common file dialog"
  72.     m_sFileFilter = sFileFilter
  73.     PropertyChanged "FileFilter"
  74. End Property
  75. Public Property Get FileFilter() As String
  76.     FileFilter = m_sFileFilter
  77. End Property
  78. Public Property Let DefExtension(sDefExtension As String)
  79. Attribute DefExtension.VB_Description = "Returns/sets the default extension appended to files with no extension during Save As"
  80.     m_sDefExtension = sDefExtension
  81.     PropertyChanged "DefExtension"
  82. End Property
  83. Public Property Get DefExtension() As String
  84.     DefExtension = m_sDefExtension
  85. End Property
  86. 'Returns the current filename
  87. Public Function GetFileTitle() As String
  88.     GetFileTitle = m_sFileTitle
  89. End Function
  90. 'Returns the current filename (with path)
  91. Public Function GetFilename() As String
  92.     GetFilename = m_sFileName
  93. End Function
  94. 'Sets the "dirty" flag
  95. Public Sub SetModified(Optional bModified As Boolean = True)
  96.     m_bModified = bModified
  97. End Sub
  98. 'Returns the "dirty" flag
  99. Public Function GetModified() As Boolean
  100.     GetModified = m_bModified
  101. End Function
  102. 'Creates a new file
  103. 'Call to implement the New command
  104. Public Function FileNew() As Boolean
  105.     If FileSaveIfModified() Then
  106.         If DoFileNew Then
  107.             m_sFileTitle = "Untitled"
  108.             m_sFileName = ""
  109.             m_bModified = False
  110.             FileNew = True
  111.         End If
  112.     End If
  113. End Function
  114. 'Lets the user select and open a new file
  115. 'Call to implement the Open command
  116. Public Function FileOpen() As Boolean
  117.     If FileSaveIfModified() Then
  118.         CmnDlg.Filename = ""
  119.         CmnDlg.Filter = m_sFileFilter
  120.         CmnDlg.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or cdlOFNLongNames 'Or cdlOFNHelpButton
  121.         CmnDlg.CancelError = True
  122.         On Error GoTo FileOpenErr
  123.         CmnDlg.ShowOpen
  124.         If DoFileLoad(CmnDlg.Filename) Then
  125.             m_sFileTitle = CmnDlg.FileTitle
  126.             m_sFileName = CmnDlg.Filename
  127.             m_bModified = False
  128.             FileOpen = True
  129.         End If
  130.     End If
  131. EndFileOpen:
  132.     Exit Function
  133. FileOpenErr:
  134.     If Err <> cdlCancel Then
  135.         MsgBox "Error opening file : " & Err.Description
  136.     End If
  137.     Resume EndFileOpen
  138. End Function
  139. 'Lets the user save the current file
  140. 'Call to implement the Save command
  141. Public Function FileSave() As Boolean
  142.     If m_sFileName = "" Then
  143.         FileSave = FileSaveAs()
  144.     Else
  145.         If DoFileSave(m_sFileName) Then
  146.             m_bModified = False
  147.             FileSave = True
  148.         End If
  149.     End If
  150. End Function
  151. 'Lets the user save the current file with a specified filename
  152. 'Call to implement the Save As command
  153. Public Function FileSaveAs() As Boolean
  154.     CmnDlg.Filename = m_sFileName
  155.     CmnDlg.Filter = m_sFileFilter
  156.     CmnDlg.DefaultExt = m_sDefExtension
  157.     CmnDlg.Flags = cdlOFNOverwritePrompt Or cdlOFNHideReadOnly Or cdlOFNLongNames 'Or cdlOFNHelpButton
  158.     CmnDlg.CancelError = True
  159.     On Error GoTo FileSaveAsErr
  160.     CmnDlg.ShowSave
  161.     If DoFileSave(CmnDlg.Filename) Then
  162.         m_sFileTitle = CmnDlg.FileTitle
  163.         m_sFileName = CmnDlg.Filename
  164.         m_bModified = False
  165.         FileSaveAs = True
  166.     End If
  167. EndFileSaveAs:
  168.     Exit Function
  169. FileSaveAsErr:
  170.     If Err <> cdlCancel Then
  171.     End If
  172.     Resume EndFileSaveAs
  173. End Function
  174. 'Allows the user to save the current file if it is modified
  175. 'Call just before closing a file
  176. Public Function FileSaveIfModified() As Boolean
  177.     Dim bResult As Boolean, I As Integer
  178.     bResult = True  'Assume success for now
  179.     If m_bModified Then
  180.         I = MsgBox("Save changes to '" & m_sFileTitle & "'?", vbYesNoCancel)
  181.         If I = vbYes Then
  182.             bResult = FileSave()
  183.         ElseIf I = vbCancel Then
  184.             bResult = False
  185.         End If
  186.     End If
  187.     FileSaveIfModified = bResult
  188. End Function
  189. 'Perform file new
  190. Private Function DoFileNew() As Boolean
  191.     Dim bSuccess As Boolean
  192.     Screen.MousePointer = vbHourglass
  193.     On Error Resume Next
  194.     bSuccess = True 'Return success if no event
  195.     RaiseEvent NewFile(bSuccess)
  196.     Screen.MousePointer = vbDefault
  197.     DoFileNew = bSuccess
  198.     Screen.MousePointer = vbDefault
  199. End Function
  200. 'Perform file load
  201. Private Function DoFileLoad(sFileName As String) As Boolean
  202.     Dim bSuccess As Boolean
  203.     Screen.MousePointer = vbHourglass
  204.     bSuccess = True 'Return success if no event
  205.     RaiseEvent LoadFile(sFileName, bSuccess)
  206.     DoFileLoad = bSuccess
  207.     Screen.MousePointer = vbDefault
  208. End Function
  209. 'Perform file save
  210. Private Function DoFileSave(sFileName As String) As Boolean
  211.     Dim bSuccess As Boolean
  212.     Screen.MousePointer = vbHourglass
  213.     On Error Resume Next
  214.     bSuccess = True 'Return success if no event
  215.     RaiseEvent SaveFile(sFileName, bSuccess)
  216.     DoFileSave = bSuccess
  217.     Screen.MousePointer = vbDefault
  218. End Function
  219. 'Initialize control properties on first use
  220. Private Sub UserControl_InitProperties()
  221.     m_sFileFilter = DEF_FILEFILTER
  222.     m_sDefExtension = DEF_DEFEXTENSION
  223. End Sub
  224. 'Load control properties
  225. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  226.     On Error GoTo ReadPropErr
  227.     m_sFileFilter = PropBag.ReadProperty("FileFilter", DEF_FILEFILTER)
  228.     m_sDefExtension = PropBag.ReadProperty("DefExtension", DEF_DEFEXTENSION)
  229. EndReadProp:
  230.     Exit Sub
  231. ReadPropErr:
  232.     'Use default property settings
  233.     UserControl_InitProperties
  234.     Resume EndReadProp
  235. End Sub
  236. 'Save control properties
  237. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  238.     PropBag.WriteProperty "FileFilter", m_sFileFilter, DEF_FILEFILTER
  239.     PropBag.WriteProperty "DefExtension", m_sDefExtension, DEF_DEFEXTENSION
  240. End Sub
  241. 'Restrict design-time size to image size
  242. Private Sub UserControl_Resize()
  243.     Size Image1.Width, Image1.Height
  244. End Sub
  245.