home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 13 / CD_ASCQ_13_0494.iso / maj / 1697 / samples / notepad.frm < prev    next >
Text File  |  1994-01-09  |  11KB  |  451 lines

  1. VERSION 2.00
  2. Begin Form frmNotePad 
  3.    Caption         =   "Untitled"
  4.    ClientHeight    =   3555
  5.    ClientLeft      =   480
  6.    ClientTop       =   2220
  7.    ClientWidth     =   5430
  8.    Height          =   4185
  9.    Icon            =   NOTEPAD.FRX:0000
  10.    KeyPreview      =   -1  'True
  11.    Left            =   450
  12.    LinkTopic       =   "Form1"
  13.    MDIChild        =   -1  'True
  14.    ScaleHeight     =   3555
  15.    ScaleWidth      =   5430
  16.    Top             =   1620
  17.    Visible         =   0   'False
  18.    Width           =   5490
  19.    Begin Editor Text1 
  20.       BorderStyle     =   0  'None
  21.       FileOpen        =   ""
  22.       Height          =   3420
  23.       InsertMode      =   -1  'True
  24.       Left            =   0
  25.       Password        =   0
  26.       ReadOnly        =   0   'False
  27.       ScrollBars      =   3  'Both
  28.       SelDefaultType  =   1  'Stream
  29.       TabIndex        =   0
  30.       Top             =   0
  31.       Width           =   5115
  32.    End
  33.    Begin Menu mnuFile 
  34.       Caption         =   "&File"
  35.       Begin Menu mnuFNew 
  36.      Caption         =   "&New"
  37.      Shortcut        =   ^N
  38.       End
  39.       Begin Menu mnuFOpen 
  40.      Caption         =   "&Open..."
  41.      Shortcut        =   ^O
  42.       End
  43.       Begin Menu mnuFClose 
  44.      Caption         =   "&Close"
  45.       End
  46.       Begin Menu mnuFSave 
  47.      Caption         =   "&Save"
  48.      Shortcut        =   ^S
  49.       End
  50.       Begin Menu mnuFSaveAs 
  51.      Caption         =   "Save &As..."
  52.       End
  53.       Begin Menu mnuFSep 
  54.      Caption         =   "-"
  55.       End
  56.       Begin Menu mnuFExit 
  57.      Caption         =   "E&xit"
  58.       End
  59.       Begin Menu mnuRecentFile 
  60.      Caption         =   "-"
  61.      Index           =   0
  62.      Visible         =   0   'False
  63.       End
  64.       Begin Menu mnuRecentFile 
  65.      Caption         =   "RecentFile1"
  66.      Index           =   1
  67.      Visible         =   0   'False
  68.       End
  69.       Begin Menu mnuRecentFile 
  70.      Caption         =   "RecentFile2"
  71.      Index           =   2
  72.      Visible         =   0   'False
  73.       End
  74.       Begin Menu mnuRecentFile 
  75.      Caption         =   "RecentFile3"
  76.      Index           =   3
  77.      Visible         =   0   'False
  78.       End
  79.       Begin Menu mnuRecentFile 
  80.      Caption         =   "RecentFile4"
  81.      Index           =   4
  82.      Visible         =   0   'False
  83.       End
  84.    End
  85.    Begin Menu mnuEdit 
  86.       Caption         =   "&Edit"
  87.       Begin Menu mnuECut 
  88.      Caption         =   "Cu&t"
  89.      Shortcut        =   ^X
  90.       End
  91.       Begin Menu mnuECopy 
  92.      Caption         =   "&Copy"
  93.      Shortcut        =   ^C
  94.       End
  95.       Begin Menu mnuEPaste 
  96.      Caption         =   "&Paste"
  97.      Shortcut        =   ^V
  98.       End
  99.       Begin Menu mnuESep1 
  100.      Caption         =   "-"
  101.       End
  102.       Begin Menu mnuESelectAll 
  103.      Caption         =   "Select &All"
  104.       End
  105.       Begin Menu mnuETime 
  106.      Caption         =   "Time/&Date"
  107.       End
  108.    End
  109.    Begin Menu mnuSearch 
  110.       Caption         =   "&Search"
  111.       Begin Menu mnuSFind 
  112.      Caption         =   "&Find..."
  113.       End
  114.       Begin Menu mnuSearchReplace 
  115.      Caption         =   "&Replace..."
  116.       End
  117.       Begin Menu mnuSFindNext 
  118.      Caption         =   "Re&peat"
  119.      Shortcut        =   {F3}
  120.       End
  121.       Begin Menu mnuSSep 
  122.      Caption         =   "-"
  123.       End
  124.       Begin Menu mnuSGoto 
  125.      Caption         =   "&Goto Line..."
  126.      Shortcut        =   ^G
  127.       End
  128.    End
  129.    Begin Menu mnuOptions 
  130.       Caption         =   "&Options"
  131.       Begin Menu mnuOToolbar 
  132.      Caption         =   "&Toolbar"
  133.       End
  134.       Begin Menu mnuFont 
  135.      Caption         =   "&Font..."
  136.       End
  137.    End
  138.    Begin Menu mnuWindow 
  139.       Caption         =   "&Window"
  140.       WindowList      =   -1  'True
  141.       Begin Menu mnuWCascade 
  142.      Caption         =   "&Cascade"
  143.       End
  144.       Begin Menu mnuWindowTileHorizontal 
  145.      Caption         =   "&Tile"
  146.       End
  147.       Begin Menu mnuWArrange 
  148.      Caption         =   "&Arrange Icons"
  149.       End
  150.    End
  151.    Begin Menu mnuHelp 
  152.       Caption         =   "&Help"
  153.       Begin Menu mnuHelpAbout 
  154.      Caption         =   "&About..."
  155.       End
  156.    End
  157. End
  158. Option Explicit
  159.  
  160. Const SmallMarginTwipSize = 0
  161. Declare Function GetKeyState Lib "User" (ByVal nVirtKey As Integer) As Integer
  162.  
  163. Dim BeginCaretX As Long
  164. Dim BeginCaretY As Long
  165. Dim BeginCount As Long
  166. Dim MessageNesting As Integer
  167.  
  168. Sub Form_Activate ()
  169.   Text1.InsertMode = gfInsertMode
  170.   gfBlockType = Text1.SelDefaultType
  171.   UpdateToolBar
  172.   UpdateStatusLine
  173. End Sub
  174.  
  175. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  176.     Dim Msg, Filename, NL
  177.     Dim Response As Integer
  178.  
  179.     If Text1.IsDirty Then
  180.     Filename = Me.Caption
  181.     NL = Chr$(10) & Chr$(13)
  182.     Msg = "The text in [" & Filename & "] has changed."
  183.     Msg = Msg & NL
  184.     Msg = Msg & "Do you want to save the changes?"
  185.     Response = MsgBox(Msg, 51, frmMDI.Caption)
  186.     Select Case Response
  187.     ' User selects Yes
  188.     Case 6
  189.         If Left(Me.Caption, 8) = "Untitled" Then
  190.         ' The file hasn't been saved yet,
  191.         ' get the filename, then call the
  192.         ' save procedure
  193.         Filename = GetFileName()
  194.         Else
  195.         ' The caption contains the name of the open file
  196.         Filename = Me.Caption
  197.         End If
  198.  
  199.         'If the user did notspecify a file name,
  200.         'cancel the unload; otherwise, save it.
  201.         If Filename = "" Then
  202.         Cancel = True
  203.         Else
  204.         SaveFileAs (Filename)
  205.         End If
  206.  
  207.     ' User selects No
  208.     ' Ok to unload
  209.     Case 7
  210.         Cancel = False
  211.     ' User selects Cancel
  212.     ' Cancel the unload
  213.     Case 2
  214.         Cancel = True
  215.     End Select
  216.     End If
  217. End Sub
  218.  
  219. Sub Form_Resize ()
  220.     If windowstate <> 1 And ScaleHeight <> 0 Then
  221.     Text1.Visible = False
  222.     Text1.Top = SmallMarginTwipSize
  223.     Text1.Left = SmallMarginTwipSize
  224.     Text1.Height = ScaleHeight - SmallMarginTwipSize
  225.     Text1.Width = ScaleWidth - SmallMarginTwipSize
  226.     Text1.Visible = True
  227.     End If
  228. End Sub
  229.  
  230. Sub Form_Unload (Cancel As Integer)
  231.     ReleaseDocument (Me.Tag)
  232.     
  233.     UpdateToolBar
  234.     UpdateStatusLine
  235. End Sub
  236.  
  237. Sub mnuECopy_Click ()
  238.     EditCopyProc
  239. End Sub
  240.  
  241. Sub mnuECut_Click ()
  242.     EditCutProc
  243. End Sub
  244.  
  245. Sub mnuEDelete_Click ()
  246. '  ' If cursor is not at the end of the notepad.
  247. '  If screen.ActiveControl.SelStart <> Len(screen.ActiveControl.Text) Then
  248. '    ' If nothing is selected, extend selection by one.
  249. '    If screen.ActiveControl.SelLength = 0 Then
  250. '      screen.ActiveControl.SelLength = 1
  251. '      ' If cursor is on a blank line, extend selection by two.
  252. '      If Asc(screen.ActiveControl.SelText) = 13 Then
  253. '        screen.ActiveControl.SelLength = 2
  254. '      End If
  255. '    End If
  256. '    ' Delete selected text.
  257. '    screen.ActiveControl.SelText = ""
  258. '  End If
  259. End Sub
  260.  
  261. Sub mnuEPaste_Click ()
  262.     EditPasteProc
  263. End Sub
  264.  
  265. Sub mnuESelectAll_Click ()
  266.     SendKeys "^{HOME}", True 'move caret to top of file
  267.     SendKeys "+^{END}", True ' mark entire file
  268. End Sub
  269.  
  270. Sub mnuETime_Click ()
  271.     Text1.Redraw = False
  272.     SendKeys Now, True
  273.     Text1.Redraw = True
  274.  
  275.     ' You could also accomplish the task above this way...
  276.     'Text1.SelText= Now
  277.     '...I did it with SendKeys to show you that it's not
  278.     'neccessary to have properties to accomplish everything,
  279.     'the VBEditor control can be also be programmed by sending
  280.     'key strokes to it.
  281. End Sub
  282.  
  283. Sub mnuFClose_Click ()
  284.     Unload Me
  285. End Sub
  286.  
  287. Sub mnuFExit_Click ()
  288.     ' Unloading the MDI form invokes the QueryUnload event
  289.     ' for each child form, then the MDI form - before unloading
  290.     ' the MDI form. Setting the Cancel argument to True in any of the
  291.     ' QueryUnload events aborts the unload.
  292.  
  293.     Unload frmMDI
  294.  
  295.  
  296. End Sub
  297.  
  298. Sub mnuFNew_Click ()
  299.     FileNew
  300. End Sub
  301.  
  302. Sub mnuFont_Click ()
  303.     SetFontProc
  304. End Sub
  305.  
  306. Sub mnuFOpen_Click ()
  307.     FOpenProc
  308. End Sub
  309.  
  310. Sub mnuFSave_Click ()
  311.     Dim Filename As String
  312.  
  313.     If Left(Me.Caption, 8) = "Untitled" Then
  314.     ' The file hasn't been saved yet,
  315.     ' get the filename, then call the
  316.     ' save procedure
  317.     Filename = GetFileName()
  318.     Else
  319.     ' The caption contains the name of the open file
  320.     Filename = Me.Caption
  321.     End If
  322.     ' call the save procedure, if Filename = Empty then
  323.     ' the user selected Cancel in the Save As dialog, otherwise
  324.     ' save the file
  325.     If Filename <> "" Then
  326.     SaveFileAs Filename
  327.     End If
  328. End Sub
  329.  
  330. Sub mnuFSaveAs_Click ()
  331.     Dim SaveFileName As String
  332.  
  333.     SaveFileName = GetFileName()
  334.     If SaveFileName <> "" Then SaveFileAs (SaveFileName)
  335.     ' Update the recent files menu
  336.     UpdateFileMenu (SaveFileName)
  337. End Sub
  338.  
  339. Sub mnuHelpAbout_Click ()
  340.     frmAbout.Show 1 'modal
  341. End Sub
  342.  
  343. Sub mnuOptions_Click ()
  344.     mnuOToolbar.Checked = frmMDI!picToolbar.Visible
  345. End Sub
  346.  
  347. Sub mnuOToolbar_Click ()
  348.     OptionsToolbarProc Me
  349. End Sub
  350.  
  351. Sub mnuRecentFile_Click (index As Integer)
  352.   Dim File2Open As String
  353.   File2Open = mnuRecentFile(index).Caption
  354.   If OpenFile(File2Open, False) = True Then
  355.     ' Update recent files list for new notepad.
  356.     GetRecentFiles
  357.   End If
  358. End Sub
  359.  
  360. Sub mnuSearchReplace_Click ()
  361.     ReplaceProc
  362. End Sub
  363.  
  364. Sub mnuSFind_Click ()
  365.     FindProc
  366. End Sub
  367.  
  368. Sub mnuSFindNext_Click ()
  369.     FindNextProc
  370. End Sub
  371.  
  372. Sub mnuSGoto_Click ()
  373.     frmGotoLine.Show
  374. End Sub
  375.  
  376. Sub mnuWArrange_Click ()
  377.     frmMDI.Arrange ARRANGE_ICONS
  378. End Sub
  379.  
  380. Sub mnuWCascade_Click ()
  381.     frmMDI.Arrange CASCADE
  382. End Sub
  383.  
  384. Sub mnuWindowTileHorizontal_Click ()
  385. ' if the shift key was help down when the menu item was
  386. ' clicked then tile the windows vertically otherwise tile
  387. ' them horizontally
  388.  
  389.     Dim ShiftDown As Integer
  390.     ShiftDown = GetKeyState(&H10) And &H8000
  391.  
  392.     If ShiftDown Then
  393.     frmMDI.Arrange TILE_VERTICAL
  394.     Else
  395.     frmMDI.Arrange TILE_HORIZONTAL
  396.     End If
  397. End Sub
  398.  
  399. Sub mnuWindowTileVertical_Click ()
  400.     frmMDI.Arrange TILE_VERTICAL
  401. End Sub
  402.  
  403. Sub Text1_BeginMessage (HControl As Long, HWindow As Integer, Message As Integer, WParam As Integer, LParam As Long, fProcessMessage As Integer)
  404.     If MessageNesting = 0 Then
  405.     BeginCaretY = Text1.CaretY
  406.     BeginCaretX = Text1.CaretX
  407.     BeginCount = Text1.Count
  408.     End If
  409.     MessageNesting = MessageNesting + 1
  410. End Sub
  411.  
  412. Sub Text1_DblClick ()
  413.     Text1.Redraw = False
  414.     Text1.SelMark = 0' turn off block mark, if any
  415.     If 1 < Text1.CaretX Then
  416.     Text1.TextIndex = Text1.CaretY
  417.     If Not IsBlankString(Mid(Text1.Text, Text1.CaretX - 1, 1)) Then
  418.         'move to beginning of current word
  419.         SendKeys "^{LEFT}", False
  420.     End If
  421.     End If
  422.     SendKeys "+^{RIGHT}", True ' mark word
  423.  
  424.     Text1.Redraw = True
  425. End Sub
  426.  
  427. Sub Text1_EndMessage (HControl As Long, HWindow As Integer, Message As Integer, WParam As Integer, LParam As Long)
  428.     If MessageNesting = 1 Then
  429.     If BeginCaretX <> Text1.CaretX Or BeginCaretY <> Text1.CaretY Or BeginCount <> Text1.Count Then
  430.         UpdateStatusLine
  431.     End If
  432.     End If
  433.     MessageNesting = MessageNesting - 1
  434. End Sub
  435.  
  436. Sub Text1_GotFocus ()
  437.     Text1.InsertMode = gfInsertMode
  438.     If frmFind.Visible Then
  439.     frmFind.ZOrder 0
  440.     End If
  441. End Sub
  442.  
  443. Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  444.     ' If the Ins key is pressed and neither the Shift, Ctrl, nor Alt
  445.     ' key is down then flip the insert mode property
  446.     If KeyCode = KEY_INSERT And Shift = 0 Then
  447.     FlipInsertMode
  448.     End If
  449. End Sub
  450.  
  451.