home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / VISBASIC / EMED16A / SAMPLES / VB / MDINOTE.BA_ / MDINOTE.BA
Text File  |  1994-08-26  |  22KB  |  698 lines

  1. Option Explicit
  2.  
  3. Global Const modal = 1
  4. Global Const CASCADE = 0
  5. Global Const TILE_HORIZONTAL = 1
  6. Global Const TILE_VERTICAL = 2
  7. Global Const ARRANGE_ICONS = 3
  8.  
  9.  
  10. Global Const REPLACE_CANCEL = 0
  11. Global Const REPLACE_YES = 1
  12. Global Const REPLACE_NO = 2
  13. Global Const REPLACE_ONE = 3
  14. Global Const REPLACE_ALL = 4
  15.  
  16.  
  17. ' globals used to manage MDI child windows...
  18. Type FormState
  19.     Deleted As Integer
  20.     Color As Long
  21. End Type
  22. Global FState()  As FormState
  23. Global document() As New frmNotePad
  24. Global ArrayNum As Integer
  25.  
  26. Global gfInsertMode As Integer ' insert mode : True=insert, False=Overwrite
  27. Global gfBlockType As Integer ' block type : 0=Stream, 1=Line, 2=Column
  28. Global gfRecursiveSearch As Integer
  29.  
  30.  
  31. ' API functions used to read and write to EMEDIT.INI.
  32. ' Used for handling the recent files list.
  33. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  34. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  35.  
  36. Global Const SM_CXBORDER = 5
  37. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  38.  
  39.  
  40.  
  41. ' Key Codes
  42. Global Const KEY_LBUTTON = &H1
  43. Global Const KEY_RBUTTON = &H2
  44. Global Const KEY_CANCEL = &H3
  45. Global Const KEY_MBUTTON = &H4    ' NOT contiguous with L & RBUTTON
  46. Global Const KEY_BACK = &H8
  47. Global Const KEY_TAB = &H9
  48. Global Const KEY_CLEAR = &HC
  49. Global Const KEY_RETURN = &HD
  50. Global Const KEY_SHIFT = &H10
  51. Global Const KEY_CONTROL = &H11
  52. Global Const KEY_MENU = &H12
  53. Global Const KEY_PAUSE = &H13
  54. Global Const KEY_CAPITAL = &H14
  55. Global Const KEY_ESCAPE = &H1B
  56. Global Const KEY_SPACE = &H20
  57. Global Const KEY_PRIOR = &H21
  58. Global Const KEY_NEXT = &H22
  59. Global Const KEY_END = &H23
  60. Global Const KEY_HOME = &H24
  61. Global Const KEY_LEFT = &H25
  62. Global Const KEY_UP = &H26
  63. Global Const KEY_RIGHT = &H27
  64. Global Const KEY_DOWN = &H28
  65. Global Const KEY_SELECT = &H29
  66. Global Const KEY_PRINT = &H2A
  67. Global Const KEY_EXECUTE = &H2B
  68. Global Const KEY_SNAPSHOT = &H2C
  69. Global Const KEY_INSERT = &H2D
  70. Global Const KEY_DELETE = &H2E
  71. Global Const KEY_HELP = &H2F
  72.  
  73. ' KEY_A thru KEY_Z are the same as their ASCII equivalents: 'A' thru 'Z'
  74. ' KEY_0 thru KEY_9 are the same as their ASCII equivalents: '0' thru '9'
  75.  
  76. Global Const KEY_NUMPAD0 = &H60
  77. Global Const KEY_NUMPAD1 = &H61
  78. Global Const KEY_NUMPAD2 = &H62
  79. Global Const KEY_NUMPAD3 = &H63
  80. Global Const KEY_NUMPAD4 = &H64
  81. Global Const KEY_NUMPAD5 = &H65
  82. Global Const KEY_NUMPAD6 = &H66
  83. Global Const KEY_NUMPAD7 = &H67
  84. Global Const KEY_NUMPAD8 = &H68
  85. Global Const KEY_NUMPAD9 = &H69
  86. Global Const KEY_MULTIPLY = &H6A
  87. Global Const KEY_ADD = &H6B
  88. Global Const KEY_SEPARATOR = &H6C
  89. Global Const KEY_SUBTRACT = &H6D
  90. Global Const KEY_DECIMAL = &H6E
  91. Global Const KEY_DIVIDE = &H6F
  92. Global Const KEY_F1 = &H70
  93. Global Const KEY_F2 = &H71
  94. Global Const KEY_F3 = &H72
  95. Global Const KEY_F4 = &H73
  96. Global Const KEY_F5 = &H74
  97. Global Const KEY_F6 = &H75
  98. Global Const KEY_F7 = &H76
  99. Global Const KEY_F8 = &H77
  100. Global Const KEY_F9 = &H78
  101. Global Const KEY_F10 = &H79
  102. Global Const KEY_F11 = &H7A
  103. Global Const KEY_F12 = &H7B
  104. Global Const KEY_F13 = &H7C
  105. Global Const KEY_F14 = &H7D
  106. Global Const KEY_F15 = &H7E
  107. Global Const KEY_F16 = &H7F
  108.  
  109. Global Const KEY_NUMLOCK = &H90
  110.  
  111. 'File Open/Save Dialog Flags
  112. Global Const OFN_READONLY = &H1&
  113. Global Const OFN_OVERWRITEPROMPT = &H2&
  114. Global Const OFN_HIDEREADONLY = &H4&
  115. Global Const OFN_NOCHANGEDIR = &H8&
  116. Global Const OFN_SHOWHELP = &H10&
  117. Global Const OFN_NOVALIDATE = &H100&
  118. Global Const OFN_ALLOWMULTISELECT = &H200&
  119. Global Const OFN_EXTENTIONDIFFERENT = &H400&
  120. Global Const OFN_PATHMUSTEXIST = &H800&
  121. Global Const OFN_FILEMUSTEXIST = &H1000&
  122. Global Const OFN_CREATEPROMPT = &H2000&
  123. Global Const OFN_SHAREAWARE = &H4000&
  124. Global Const OFN_NOREADONLYRETURN = &H8000&
  125.  
  126. Function AnyPadsLeft () As Integer
  127.     Dim I As Integer
  128.  
  129.     ' Cycle throught the document array.
  130.     ' Return True if there is at least one
  131.     ' open document remaining.
  132.     For I = 1 To UBound(document)
  133.     If Not FState(I).Deleted Then
  134.         AnyPadsLeft = True
  135.         Exit Function
  136.     End If
  137.     Next
  138.  
  139. End Function
  140.  
  141. Sub CenterForm (frmParent As Form, frmChild As Form)
  142. ' This procedure centers a child form over a parent form.
  143. ' Calling this routine loads the dialog. Use the Show method
  144. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  145.  
  146. Dim l, t
  147.   ' get left offset
  148.   l = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  149.   If (l + frmChild.Width > screen.Width) Then
  150.     l = screen.Width = frmChild.Width
  151.   End If
  152.  
  153.   ' get top offset
  154.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  155.   If (t + frmChild.Height > screen.Height) Then
  156.     t = screen.Height - frmChild.Height
  157.   End If
  158.  
  159.   ' center the child formfv
  160.   frmChild.Move l, t
  161.  
  162. End Sub
  163.  
  164. Sub DisplayError ()
  165.     MsgBox Error$, 48, App.Title ' 48=MB_OK+MB_ICONEXCLAMATION
  166. End Sub
  167.  
  168. Sub EditClearAllProc ()
  169.  
  170.     frmMDI.ActiveForm.Text1.Redraw = False
  171.  
  172.     ' Mark a block that starts with the first character in the first line and
  173.     ' ends with the last character in the last line...
  174.     frmMDI.ActiveForm.Text1.SelMark = 1 'make a stream block
  175.     frmMDI.ActiveForm.Text1.SelStartX = 1
  176.     frmMDI.ActiveForm.Text1.SelStartY = 1
  177.     frmMDI.ActiveForm.Text1.SelEndY = frmMDI.ActiveForm.Text1.Count
  178.     frmMDI.ActiveForm.Text1.TextIndex = frmMDI.ActiveForm.Text1.Count
  179.     frmMDI.ActiveForm.Text1.SelEndX = Len(frmMDI.ActiveForm.Text1.TextIndex) + 1
  180.  
  181.     frmMDI.ActiveForm.Text1.Action = 4  'clear
  182.  
  183.     frmMDI.ActiveForm.Text1.Redraw = True
  184.     
  185. End Sub
  186.  
  187. Sub EditCopyProc ()
  188.     ' copy selection to clipboard
  189.     frmMDI.ActiveForm.Text1.Action = 1
  190.  
  191.     ' Alternatively, we could cut selected text to
  192.     ' Clipboard by sending a Control-Insert key to the
  193.     ' active window...
  194.     'SendKeys "^{INSERT}", True 'wait for text to be cut
  195. End Sub
  196.  
  197. Sub EditCutProc ()
  198.     ' cut selection to clipboard
  199.     frmMDI.ActiveForm.Text1.Action = 3
  200. End Sub
  201.  
  202. Sub EditDeleteProc ()
  203.     ' cut selection to clipboard
  204.     frmMDI.ActiveForm.Text1.Action = 4 'clear
  205. End Sub
  206.  
  207. Sub EditPasteProc ()
  208.     ' Place text from Clipboard into active control.
  209.     frmMDI.ActiveForm.Text1.Action = 2 ' paste selection
  210. End Sub
  211.  
  212. Sub EditUndoProc ()
  213.     ' undo the last edit
  214.     frmMDI.ActiveForm.Text1.Action = 6 'undo
  215. End Sub
  216.  
  217. Sub EditWrapAutomaticallyProc ()
  218.     Dim bAuto As Integer
  219.     bAuto = Not frmMDI.ActiveForm.Text1.WrapAutomatically
  220.     frmMDI.ActiveForm.Text1.WrapAutomatically = bAuto
  221. End Sub
  222.  
  223. Sub EditWrapFormatProc ()
  224.     ' wrap any selected text to fit the current window
  225.     frmMDI.ActiveForm.Text1.WrapX = -1 'wrap to current window size
  226.     frmMDI.ActiveForm.Text1.Action = 5 'wrap selection
  227. End Sub
  228.  
  229. Sub FileNew ()
  230.     Dim fIndex As Integer
  231.  
  232.     fIndex = FindFreeIndex()
  233.     document(fIndex).Tag = fIndex
  234.     document(fIndex).Caption = "Untitled:" & fIndex
  235.     document(fIndex).Show
  236.  
  237.     UpdateToolBar
  238. End Sub
  239.  
  240. Function FindFreeIndex () As Integer
  241.     Static NotFirstTime As Integer
  242.     If NotFirstTime Then
  243.     Dim I As Integer
  244.     Dim ArrayCount As Integer
  245.     
  246.     ArrayCount = UBound(document)
  247.     
  248.     ' Cycle throught the document array. If one of the
  249.     ' documents has been deleted, then return that
  250.     ' index.
  251.     For I = 1 To ArrayCount
  252.         If FState(I).Deleted Then
  253.         FindFreeIndex = I
  254.         FState(I).Deleted = False
  255.         document(I).Tag = I
  256.         Exit Function
  257.         End If
  258.     Next
  259.     
  260.     ' If none of the elements in the document array have
  261.     ' been deleted, then increment the document and the
  262.     ' state arrays by one and return the index to the
  263.     ' new element.
  264.     
  265.     ReDim Preserve document(ArrayCount + 1)
  266.     ReDim Preserve FState(ArrayCount + 1)
  267.     Dim FreeIndex As Integer
  268.     FreeIndex = UBound(document)
  269.     document(FreeIndex).Tag = FreeIndex
  270.     FindFreeIndex = FreeIndex
  271.     Else
  272.     'Initialize document form arrays, and show first document.
  273.     ReDim document(1)
  274.     ReDim FState(1)
  275.     document(1).Tag = 1
  276.     FindFreeIndex = 1
  277.     NotFirstTime = True
  278.     End If
  279. End Function
  280.  
  281. Function FindIt (TargetText As String, MatchCase As Integer, WholeWordOnly As Integer, UpDirection As Integer, BeginScope As Integer, NewText As String, fReplace As Integer) As Integer
  282.     FindIt = False
  283.  
  284.     'make sure the current form's display is up to date...
  285.     frmMDI.ActiveForm.Refresh
  286.  
  287.     ' change mousepointer to an hourglass
  288.     Dim OldMousePointer As Integer
  289.     OldMousePointer = screen.MousePointer
  290.     screen.MousePointer = 11
  291.  
  292.     ' If we wern't given a string to look for then don't do anything...
  293.     If TargetText = "" Then Exit Function
  294.  
  295.     frmMDI.ActiveForm.Text1.SearchReplacement = NewText
  296.     frmMDI.ActiveForm.Text1.SearchTarget = TargetText
  297.  
  298.     If BeginScope Then
  299.       frmMDI.ActiveForm.Text1.SearchOrigin = 1 'search entire scope
  300.     Else
  301.       frmMDI.ActiveForm.Text1.SearchOrigin = 0 'search from cursor
  302.     End If
  303.  
  304.     If UpDirection Then
  305.       frmMDI.ActiveForm.Text1.SearchTo = 0 'search to top of file
  306.     Else
  307.       frmMDI.ActiveForm.Text1.SearchTo = 1 'search to bottom of file
  308.     End If
  309.  
  310.     If MatchCase Then
  311.       frmMDI.ActiveForm.Text1.SearchCaseSensitive = True
  312.     Else
  313.       frmMDI.ActiveForm.Text1.SearchCaseSensitive = False
  314.     End If
  315.  
  316.     If WholeWordOnly Then
  317.       frmMDI.ActiveForm.Text1.SearchWholeWordsOnly = True
  318.     Else
  319.       frmMDI.ActiveForm.Text1.SearchWholeWordsOnly = False
  320.     End If
  321.  
  322.     
  323.     If fReplace Then
  324.        frmMDI.ActiveForm.Text1.Action = 10 'replace
  325.     Else
  326.        frmMDI.ActiveForm.Text1.Action = 9 'search
  327.     End If
  328.  
  329.  
  330.     ' reset mouse pointer
  331.     screen.MousePointer = OldMousePointer
  332.  
  333.     ' If string is found
  334.     If frmMDI.ActiveForm.Text1.SearchResult Then
  335.     FindIt = True
  336.     Else
  337.     Dim Msg As String, response As Integer
  338.     Msg = "Cannot find " & Chr(34) & TargetText & Chr(34)
  339.     response = MsgBox(Msg, 0, App.Title)
  340.     End If
  341.  
  342.     UpdateStatusLine
  343.  
  344. End Function
  345.  
  346. Sub FindNextProc ()
  347.     'make sure the current form's display is up to date...
  348.     frmMDI.ActiveForm.Refresh
  349.  
  350.     ' change mousepointer to an hourglass
  351.     Dim OldMousePointer As Integer
  352.     OldMousePointer = screen.MousePointer
  353.     screen.MousePointer = 11
  354.  
  355.     frmMDI.ActiveForm.Text1.Action = 11 'repeat
  356.  
  357.     ' reset mouse pointer
  358.     screen.MousePointer = OldMousePointer
  359.  
  360.     ' If string is found
  361.     If frmMDI.ActiveForm.Text1.SearchResult = 0 Then
  362.     Dim Msg As String, response As Integer
  363.     Msg = "Cannot find " & Chr(34) & frmMDI.ActiveForm.Text1.SearchTarget & Chr(34)
  364.     response = MsgBox(Msg, 0, App.Title)
  365.     End If
  366.  
  367.     UpdateStatusLine
  368. End Sub
  369.  
  370. Sub FindProc ()
  371.  
  372.     ' 1st, before displaying the dialog that collects search parameters,
  373.     ' initialize the text that will be displayed in the Find form's
  374.     ' combo box...
  375.     If frmMDI.ActiveForm!Text1.SelMark <> 0 And frmMDI.ActiveForm!Text1.SelStartY = frmMDI.ActiveForm!Text1.SelEndY Then
  376.     Dim start As Long, length As Long
  377.     start = frmMDI.ActiveForm!Text1.SelStartX
  378.     length = frmMDI.ActiveForm!Text1.SelEndX - start
  379.     frmMDI.ActiveForm!Text1.TextIndex = frmMDI.ActiveForm!Text1.SelStartY
  380.     frmFind!comboText.Text = RTrim(Mid(frmMDI.ActiveForm!Text1.Text, start, length))
  381.     Else
  382.     frmFind!comboText.Text = frmMDI.ActiveForm!Text1.SearchTarget
  383.     End If
  384.  
  385.     ' Collect search parameters.  After the user presses the OK button
  386.     ' the Find dialog calls FindIt..
  387.     frmFind.Show
  388. End Sub
  389.  
  390. Sub FlipInsertMode ()
  391.     If gfInsertMode = True Then
  392.     gfInsertMode = False
  393.     Else
  394.     gfInsertMode = True
  395.     End If
  396.     SetInsertMode
  397. End Sub
  398.  
  399. Sub GetRecentFiles ()
  400.   Dim RetVal, key, I, J
  401.   Dim IniString As String
  402.  
  403.   ' This variable must be large enough to hold the return string
  404.   ' from the GetPrivateProfileString API.
  405.   IniString = String(255, 0)
  406.  
  407.   ' Get recent file strings from EMEDIT.INI
  408.   For I = 1 To 4
  409.     key = "RecentFile" & I
  410.     RetVal = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "EMEDIT.INI")
  411.     If RetVal And Left(IniString, 8) <> "Not Used" Then
  412.       ' Update the MDI form's menu.
  413.       frmMDI.mnuRecentFile(0).Visible = True
  414.       frmMDI.mnuRecentFile(I).Caption = IniString
  415.       frmMDI.mnuRecentFile(I).Visible = True
  416.   
  417.       ' Iterate through all the notepads and update each menu.
  418.       For J = 1 To UBound(document)
  419.     If Not FState(J).Deleted Then
  420.       document(J).mnuRecentFile(0).Visible = True
  421.       document(J).mnuRecentFile(I).Caption = IniString
  422.       document(J).mnuRecentFile(I).Visible = True
  423.     End If
  424.       Next J
  425.     End If
  426.   Next I
  427.  
  428. End Sub
  429.  
  430. Sub InitMDINOTE ()
  431.  
  432.     'Initialize document form arrays, and show first document.
  433. '    ReDim document(1)
  434. '    ReDim FState(1)
  435. '    document(1).Tag = 1
  436. '    document(1).Show
  437.  
  438.     gfInsertMode = True ' default is to insert text
  439.     gfBlockType = 1 'block type = Stream
  440. End Sub
  441.  
  442. Function IsBlankString (DaString As String) As Integer
  443.     Dim DaStringLen As Long, I As Long
  444.     DaStringLen = Len(DaString)
  445.     IsBlankString = True
  446.     For I = 1 To DaStringLen
  447.     If Mid(DaString, I, 1) <> " " And Mid(DaString, I, 1) <> Chr(9) Then
  448.         IsBlankString = False
  449.         Exit For
  450.     End If
  451.     Next
  452. End Function
  453.  
  454. Function IsWholeWord (SourceText As String, FoundX As Long, FoundLength As Long) As Integer
  455.     Dim BeginWholeWord As Integer
  456.     IsWholeWord = False
  457.     If FoundX <= 1 Then
  458.     BeginWholeWord = True
  459.     ElseIf IsBlankString(Mid(SourceText, FoundX - 1, 1)) Then
  460.     BeginWholeWord = True
  461.     End If
  462.     
  463.     If BeginWholeWord Then
  464.     If Len(SourceText) <= FoundX + FoundLength Then
  465.         IsWholeWord = True
  466.     ElseIf IsBlankString(Mid(SourceText, FoundX + FoundLength, 1)) Then
  467.         IsWholeWord = True
  468.     End If
  469.     End If
  470. End Function
  471.  
  472. Sub OptionsToolbarProc (CurrentForm As Form)
  473.     CurrentForm.mnuOToolbar.Checked = Not CurrentForm.mnuOToolbar.Checked
  474.     If TypeOf CurrentForm Is MDIForm Then
  475.     Else
  476.     frmMDI.mnuOToolbar.Checked = CurrentForm.mnuOToolbar.Checked
  477.     End If
  478.     If CurrentForm.mnuOToolbar.Checked Then
  479.     frmMDI.picToolbar.Visible = True
  480.     Else
  481.     frmMDI.picToolbar.Visible = False
  482.     End If
  483. End Sub
  484.  
  485. Sub ReleaseDocument (fIndex As Integer)
  486.     FState(fIndex).Deleted = True
  487. End Sub
  488.  
  489. Sub ReplaceProc ()
  490.     ' 1st, before displaying the dialog that collects search parameters,
  491.     ' initialize the text that will be displayed in the Find form's
  492.     ' combo box...
  493.     If frmMDI.ActiveForm!Text1.SelMark <> 0 And frmMDI.ActiveForm!Text1.SelStartY = frmMDI.ActiveForm!Text1.SelEndY Then
  494.     Dim start As Long, length As Long
  495.     start = frmMDI.ActiveForm!Text1.SelStartX
  496.     length = frmMDI.ActiveForm!Text1.SelEndX - start
  497.     frmMDI.ActiveForm!Text1.TextIndex = frmMDI.ActiveForm!Text1.SelStartY
  498.     frmReplace!comboText.Text = RTrim(Mid(frmMDI.ActiveForm!Text1.Text, start, length))
  499.     Else
  500.     frmReplace!comboText.Text = frmMDI.ActiveForm!Text1.SearchTarget
  501.     End If
  502.  
  503.     ' Collect search parameters.  After the user presses the OK button
  504.     ' the Find dialog calls FindIt..
  505.     frmReplace.Show
  506. End Sub
  507.  
  508. Sub SetBlockType (fBlockType As Integer)
  509.     If fBlockType = gfBlockType Then
  510.       Exit Sub
  511.     End If
  512.     On Error GoTo SetBlockTypeError
  513.     frmMDI.ActiveForm.Text1.SelDefaultType = fBlockType
  514.     gfBlockType = fBlockType
  515.     GoTo EndSetBlockType
  516. SetBlockTypeError:
  517.     DisplayError
  518.     Resume EndSetBlockType:
  519. EndSetBlockType:
  520.     
  521. End Sub
  522.  
  523. Sub SetFontProc ()
  524.     'set cancel to true
  525.     frmMDI.CMFontDialog.CancelError = True
  526.     On Error GoTo SetFontErrHandler
  527.  
  528.     ' set the CF_BOTH and CF_EFFECTS flags
  529.     frmMDI.CMFontDialog.Flags = &H3& Or &H100&
  530.     frmMDI.CMFontDialog.FontName = frmMDI.ActiveForm.Text1.FontName
  531.     frmMDI.CMFontDialog.FontSize = frmMDI.ActiveForm.Text1.FontSize
  532.     frmMDI.CMFontDialog.FontBold = frmMDI.ActiveForm.Text1.FontBold
  533.     frmMDI.CMFontDialog.FontItalic = frmMDI.ActiveForm.Text1.FontItalic
  534.     frmMDI.CMFontDialog.FontUnderLine = frmMDI.ActiveForm.Text1.FontUnderline
  535.     frmMDI.CMFontDialog.FontStrikeThru = frmMDI.ActiveForm.Text1.FontStrikethru
  536.     frmMDI.CMFontDialog.Color = frmMDI.ActiveForm.Text1.ForeColor
  537.  
  538.     'display the dialog box
  539.     frmMDI.CMFontDialog.Action = 4
  540.  
  541.     'set the properties according to the user's selections...
  542.     frmMDI.ActiveForm.Text1.Visible = False
  543.     frmMDI.ActiveForm.Text1.FontName = frmMDI.CMFontDialog.FontName
  544.     frmMDI.ActiveForm.Text1.FontSize = frmMDI.CMFontDialog.FontSize
  545.     frmMDI.ActiveForm.Text1.FontBold = frmMDI.CMFontDialog.FontBold
  546.     frmMDI.ActiveForm.Text1.FontItalic = frmMDI.CMFontDialog.FontItalic
  547.     frmMDI.ActiveForm.Text1.FontUnderline = frmMDI.CMFontDialog.FontUnderLine
  548.     frmMDI.ActiveForm.Text1.FontStrikethru = frmMDI.CMFontDialog.FontStrikeThru
  549.     frmMDI.ActiveForm.Text1.ForeColor = frmMDI.CMFontDialog.Color
  550.     frmMDI.ActiveForm.Text1.Visible = True
  551.  
  552. SetFontErrHandler: ' user pressed cancel button
  553.     Exit Sub
  554. End Sub
  555.  
  556. Sub SetInsertMode ()
  557.     'set insert mode
  558.     frmMDI.ActiveForm.Text1.InsertMode = gfInsertMode
  559.  
  560.     'change caret width based on insert mode
  561.     Dim CaretWidth%
  562.     CaretWidth% = -1
  563.     If Not gfInsertMode Then
  564.     CaretWidth% = GetSystemMetrics(SM_CXBORDER)
  565.     If CaretWidth% < 2 Then CaretWidth% = 2
  566.     CaretWidth% = CaretWidth% * 2
  567.     End If
  568.     frmMDI.ActiveForm.Text1.CaretWidth = CaretWidth%
  569.  
  570.     UpdateStatusLine
  571. End Sub
  572.  
  573. Sub UpdateComboList (comboCtrl As ComboBox, strTxt As String)
  574. ' If the given string does not exist in the control then
  575. '   Add the string to the beginning of the control's list
  576. ' otherwise
  577. '   Move the string to the beginning of the string's list
  578.     If strTxt <> "" Then
  579.     
  580.     Dim fTxtExists As Integer
  581.     fTxtExists = False
  582.     
  583.     'check to see if the given string is alreay in the list...
  584.     If 0 < comboCtrl.ListCount Then
  585.         Dim I As Integer
  586.         For I = 0 To comboCtrl.ListCount - 1
  587.         If comboCtrl.List(I) = strTxt Then
  588.             If I = 0 Then
  589.             fTxtExists = True
  590.             Else
  591.             ' The string exists in the list, so move it to the top
  592.             ' of the list if necessary
  593.             comboCtrl.RemoveItem I
  594.             End If
  595.             Exit For
  596.         End If
  597.         Next
  598.     End If
  599.     
  600.     'if not already in list then add string to top of list...
  601.     If fTxtExists = False Then
  602.         comboCtrl.AddItem strTxt, 0
  603.     End If
  604.     End If
  605. End Sub
  606.  
  607. Sub UpdateStatusLine ()
  608.     
  609.     'Hide toolbar edit buttons if no notepad windows
  610.     If Not AnyPadsLeft() Then
  611.     frmMDI!labelInsert = ""
  612.     frmMDI!labelPosition = ""
  613.     Else
  614.     If gfInsertMode = False Then
  615.         frmMDI.labelInsert = "Overwrite"
  616.     Else
  617.         frmMDI.labelInsert = "Insert"
  618.     End If
  619.  
  620.     Dim xpos As String, ypos As String, ysize As String
  621.     xpos = CStr(frmMDI.ActiveForm.Text1.CaretX)
  622.     ypos = CStr(frmMDI.ActiveForm.Text1.CaretY)
  623.     ysize = CStr(frmMDI.ActiveForm.Text1.Count)
  624.     frmMDI.labelPosition = "Line=" & ypos & " of " & ysize & " Column=" & xpos
  625.     End If
  626.  
  627. End Sub
  628.  
  629. Sub UpdateToolBar ()
  630.     
  631.     'Hide toolbar edit buttons if no notepad windows
  632.     If Not AnyPadsLeft() Then
  633.     frmMDI!imgCutButton.Visible = False
  634.     frmMDI!imgCopyButton.Visible = False
  635.     frmMDI!imgPasteButton.Visible = False
  636.     frmMDI!imgStreamButton.Visible = False
  637.     frmMDI!imgColumnButton.Visible = False
  638.     frmMDI!imgLineButton.Visible = False
  639.     frmMDI!imgUndoButton.Visible = False
  640.     frmMDI!imgLookButton.Visible = False
  641.     frmMDI!imgNextButton.Visible = False
  642.     End If
  643.  
  644.     Select Case gfBlockType
  645.     Case 0 'none
  646.     frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  647.     frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  648.     frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  649.     Case 1 'stream block
  650.     frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonPushed.Picture
  651.     frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  652.     frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  653.     Case 2 'line block
  654.     frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  655.     frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonPushed.Picture
  656.     frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  657.     Case 3 'column block
  658.     frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  659.     frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  660.     frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonPushed.Picture
  661.     End Select
  662.  
  663.     If AnyPadsLeft() Then
  664.     ' Make sure toolbar edit buttons are visible
  665.     frmMDI!imgCutButton.Visible = True
  666.     frmMDI!imgCopyButton.Visible = True
  667.     frmMDI!imgPasteButton.Visible = True
  668.     frmMDI!imgStreamButton.Visible = True
  669.     frmMDI!imgColumnButton.Visible = True
  670.     frmMDI!imgLineButton.Visible = True
  671.     frmMDI!imgUndoButton.Visible = True
  672.     frmMDI!imgLookButton.Visible = True
  673.     frmMDI!imgNextButton.Visible = True
  674.     End If
  675.  
  676. End Sub
  677.  
  678. Sub WriteRecentFiles (OpenFileName)
  679.   Dim I, J, key, RetVal
  680.   Dim IniString As String
  681.   IniString = String(255, 0)
  682.  
  683.   ' Copy RecentFile1 to RecentFile2, etc.
  684.   For I = 3 To 1 Step -1
  685.     key = "RecentFile" & I
  686.     RetVal = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "EMEDIT.INI")
  687.     If RetVal And Left(IniString, 8) <> "Not Used" Then
  688.       key = "RecentFile" & (I + 1)
  689.       RetVal = WritePrivateProfileString("Recent Files", key, IniString, "EMEDIT.INI")
  690.     End If
  691.   Next I
  692.   
  693.   ' Write openfile to first Recent File.
  694.     RetVal = WritePrivateProfileString("Recent Files", "RecentFile1", OpenFileName, "EMEDIT.INI")
  695.  
  696. End Sub
  697.  
  698.