home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / appshell / appmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  8.8 KB  |  302 lines

  1. VERSION 2.00
  2. Begin Form AppMain 
  3.    Caption         =   "App Shell - [untitled]"
  4.    ClientHeight    =   5370
  5.    ClientLeft      =   885
  6.    ClientTop       =   1485
  7.    ClientWidth     =   8205
  8.    FontBold        =   0   'False
  9.    FontItalic      =   0   'False
  10.    FontName        =   "MS Sans Serif"
  11.    FontSize        =   8.25
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   6060
  15.    Icon            =   APPMAIN.FRX:0000
  16.    Left            =   825
  17.    LinkMode        =   1  'Source
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   5370
  20.    ScaleWidth      =   8205
  21.    Top             =   855
  22.    Width           =   8325
  23.    Begin TextBox AppText 
  24.       FontBold        =   0   'False
  25.       FontItalic      =   0   'False
  26.       FontName        =   "Courier"
  27.       FontSize        =   12
  28.       FontStrikethru  =   0   'False
  29.       FontUnderline   =   0   'False
  30.       Height          =   5415
  31.       Left            =   -45
  32.       MultiLine       =   -1  'True
  33.       ScrollBars      =   3  'Both
  34.       TabIndex        =   0
  35.       Top             =   -45
  36.       Width           =   8250
  37.    End
  38.    Begin Menu FileMenu 
  39.       Caption         =   "&File"
  40.       Begin Menu FileNewCmd 
  41.          Caption         =   "&New"
  42.       End
  43.       Begin Menu FileOpenCmd 
  44.          Caption         =   "&Open..."
  45.       End
  46.       Begin Menu FileSaveCmd 
  47.          Caption         =   "&Save"
  48.       End
  49.       Begin Menu FileSaveAsCmd 
  50.          Caption         =   "Save &As..."
  51.       End
  52.       Begin Menu FileSep1 
  53.          Caption         =   "-"
  54.       End
  55.       Begin Menu FilePrintCmd 
  56.          Caption         =   "&Print..."
  57.       End
  58.       Begin Menu FilePrinterSetupCmd 
  59.          Caption         =   "P&rinter Setup..."
  60.       End
  61.       Begin Menu FileSep2 
  62.          Caption         =   "-"
  63.       End
  64.       Begin Menu FileExitCmd 
  65.          Caption         =   "E&xit"
  66.       End
  67.    End
  68.    Begin Menu HelpMenu 
  69.       Caption         =   "&Help"
  70.       Begin Menu UsingHelpCmd 
  71.          Caption         =   "Using Help"
  72.       End
  73.       Begin Menu HelpSep2 
  74.          Caption         =   "-"
  75.       End
  76.       Begin Menu HelpAboutCmd 
  77.          Caption         =   "&About"
  78.       End
  79.    End
  80. ' ================
  81. ' Copyrights & CYA
  82. ' ================
  83. ' App Shell is freeware with the following intent:
  84. ' -  You are free to incorporate App Shell into your code that will be
  85. '    distributed in executable form.
  86. ' -  You are free to distribute App Shell source or incorporate App Shell
  87. '    source into your source code assuming no charge is required and this
  88. '    copyright is maintained and acknowledged.
  89. ' -  You are free to distribute App Shell source as shareware assuming
  90. '    you are an approved vendor and associate member of the Association
  91. '    of Shareware Professionals (ASP).  No registration fee is required
  92. '    but this copyright must be maintained and acknowledged.
  93. ' -  All other distribution rights are maintained by the author.
  94. ' -  The author makes NO warranties, express or implied, oral or written,
  95. '    including any implied warranties of merchantability or fitness for
  96. '    a particular purpose.  In no event shall the author be liable for
  97. '    any damages whatsoever arising out of the use of the software.
  98. ' If you find any bugs, anomalies, or have any questions or suggestions,
  99. ' please send them to Jim Presley (CIS ID - 73417,2674).  Enjoy!
  100. Sub AppText_Change ()
  101.   App_Changed = True
  102.   App_Data = AppText.Text
  103. End Sub
  104. Function CheckForChange () As Integer
  105.   x% = 0
  106.   If App_Changed Then
  107.     If App_FileName = "" Then
  108.       a$ = "[Untitled]"
  109.     Else
  110.       a$ = UCase$(App_FileName)
  111.     End If
  112.     x% = MsgBox(a$ + " has changed.  Save current changes?", MB_YESNOCANCEL + MB_ICONEXCLAMATION, APP_NAME)
  113.     If x% = IDYES Then
  114.       x% = SaveFile(False)
  115.     End If
  116.   End If
  117.   CheckForChange = x%
  118. End Function
  119. Sub ExitProcessing ()
  120.   If CheckForChange() <> IDCANCEL Then End
  121. End Sub
  122. Sub FileExitCmd_Click ()
  123.   ExitProcessing
  124. End Sub
  125. Sub FileNewCmd_Click ()
  126.   If CheckForChange() <> IDCANCEL Then
  127.     LoadFileNew
  128.     LoadMainControls
  129.     App_Changed = False
  130.   End If
  131. End Sub
  132. Sub FileOpenCmd_Click ()
  133.   If CheckForChange() <> IDCANCEL Then
  134.     App_OpenTitle = "Open File"
  135.     App_OpenSaveStyle = APP_OPEN
  136.     AppOpenSave.Show Modal
  137.     Unload AppOpenSave
  138.     If App_DialogReturn = IDOK Then
  139.       '
  140.       ' load the file
  141.       '
  142.       If LoadFile() Then
  143.         LoadMainControls
  144.         App_Changed = False
  145.       End If
  146.     End If
  147.   End If
  148. End Sub
  149. Sub FilePrintCmd_Click ()
  150.   Dim Win_PrinterName As String
  151.   Dim Win_PrinterDriver As String
  152.   Dim Win_PrinterPort As String
  153.   Dim RestorePrinter As Integer
  154.   ' get the print parameters
  155.   AppPrint.Show Modal
  156.   GetDefaultPrinter Win_PrinterName, Win_PrinterDriver, Win_PrinterPort
  157.   ' print the document
  158.   RestorePrinter = False
  159.   If App_PrinterName <> Win_PrinterName Then
  160.     '
  161.     ' make the printer the default
  162.     '
  163.     WriteDefaultPrinter App_PrinterName, App_PrinterDriver, App_PrinterPort
  164.     RestorePrinter = True
  165.   End If
  166.   For App_PrintCopyNumber = 1 To App_PrintCopies
  167.     AppPrinting.Show Modal
  168.     If App_PrintCancel Then Exit For
  169.   Next
  170.   If RestorePrinter Then
  171.     '
  172.     ' restore the default windows printer
  173.     '
  174.     WriteDefaultPrinter Win_PrinterName, Win_PrinterDriver, Win_PrinterPort
  175.   End If
  176. End Sub
  177. Sub FilePrinterSetupCmd_Click ()
  178.   AppPrSetup.Show Modal
  179. End Sub
  180. Sub FileSaveAsCmd_Click ()
  181.   ' save the file and load main form's caption
  182.   If SaveFile(True) Then LoadMainTitle
  183. End Sub
  184. Sub FileSaveCmd_Click ()
  185.     x% = SaveFile(False)
  186. End Sub
  187. Sub Form_Load ()
  188.   ' load any file specified on the command line into memory
  189.   c$ = Command$
  190.   If c$ <> "" Then
  191.     If InStr(c$, ".") = 0 Then c$ = c$ + App_FileExtension
  192.     a$ = Dir$(c$)
  193.     If a$ = "" Then
  194.       MsgBox "File name " + UCase$(c$) + " entered on command line not valid.", MB_ICONEXCLAMATION, APP_NAME
  195.       LoadFileNew
  196.     Else
  197.       App_FullFileName = c$
  198.       SplitFileName App_FullFileName, App_Path, App_FileName
  199.       If Not LoadFile() Then
  200.         LoadFileNew
  201.       End If
  202.     End If
  203.   Else
  204.     LoadFileNew
  205.   End If
  206.   LoadMainControls
  207.   App_Changed = False
  208. End Sub
  209. Sub Form_Resize ()
  210.   AppText.Move 0, 0, ScaleWidth, ScaleHeight
  211. End Sub
  212. Sub Form_Unload (Cancel As Integer)
  213.   ExitProcessing
  214.   ' if processing returns that means the user cancelled
  215.   ' the termination
  216.   Cancel = True
  217. End Sub
  218. Sub HelpAboutCmd_Click ()
  219.   AppAbout.Show Modal
  220. End Sub
  221. Function LoadFile () As Integer
  222.   ' Load the file
  223.   LoadFile = True
  224.   Screen.MousePointer = HOURGLASS
  225.   On Error GoTo LoadFileError
  226.   FileNum% = FreeFile
  227.   Open App_FullFileName For Input As FileNum%
  228.   If LOF(FileNum%) > 60000 Then
  229.     MsgBox "Sorry, file too large", MB_STOPICON, APP_NAME
  230.     LoadFile = False
  231.     Exit Function
  232.   End If
  233.   Do Until EOF(FileNum%)
  234.     Line Input #FileNum%, nl$
  235.     a$ = a$ + nl$ + CRLF
  236.   Loop
  237.   Close FileNum%
  238.   App_Data = a$
  239.   Screen.MousePointer = DEFAULT
  240.   On Error GoTo 0
  241.   Exit Function
  242. LoadFileError:
  243.   a$ = Error$(Err)
  244.   MsgBox "Error: " + a$, MB_ICONSTOP, APP_NAME
  245.   LoadFile = False
  246.   On Error GoTo 0
  247.   Screen.MousePointer = DEFAULT
  248.   Exit Function
  249. End Function
  250. Sub LoadFileNew ()
  251.   App_FileName = ""
  252.   App_Path = CurDir$
  253.   App_Data = ""
  254. End Sub
  255. Sub LoadMainControls ()
  256.   LoadMainTitle
  257.   AppText.Text = App_Data
  258. End Sub
  259. Sub LoadMainTitle ()
  260.   If App_FileName <> "" Then
  261.     AppMain.Caption = APP_NAME + " - " + UCase$(App_FileName)
  262.   Else
  263.     AppMain.Caption = APP_NAME + " - [Untitled]"
  264.   End If
  265. End Sub
  266. Function SaveFile (NewName As Integer) As Integer
  267.   ' get a file name if untitled
  268.   If App_FileName = "" Or NewName Then
  269.     App_SaveTitle = "Save File As"
  270.     App_OpenSaveStyle = APP_SAVE
  271.     AppOpenSave.Show Modal
  272.     Unload AppOpenSave
  273.     If App_DialogReturn = IDCANCEL Then
  274.       SaveFile = IDCANCEL
  275.       Exit Function
  276.     End If
  277.   End If
  278.   ' Save the file
  279.   Screen.MousePointer = HOURGLASS
  280.   On Error GoTo SaveFileError
  281.   FileNum% = FreeFile
  282.   Open App_FullFileName For Output As FileNum%
  283.   Print #FileNum%, App_Data
  284.   Close FileNum%
  285.   App_Changed = False
  286.   SaveFile = True
  287.   On Error GoTo 0
  288.   Screen.MousePointer = DEFAULT
  289.   Exit Function
  290. SaveFileError:
  291.   a$ = Error$(Err)
  292.   MsgBox "Error: " + a$, MB_ICONEXCLAMATION, APP_NAME
  293.   SaveFile = IDCANCEL
  294.   On Error GoTo 0
  295.   Screen.MousePointer = DEFAULT
  296.   Exit Function
  297. End Function
  298. Sub UsingHelpCmd_Click ()
  299.     Dim work As Integer
  300.     Worked = WinHelp(AppMain.hWnd, "", HELP_HELPONHELP, 0)
  301. End Sub
  302.