home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets (4th Edition) / Windows95Secrets4thEdition.iso / tools / spellers / spelmate / mdinote.bas < prev    next >
Encoding:
BASIC Source File  |  1994-11-11  |  7.1 KB  |  231 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. Type FormState
  10.     Deleted As Integer
  11.     Dirty As Integer
  12.     Color As Long
  13. End Type
  14. Global FState()  As FormState
  15. Global Document() As New frmNotePad
  16. Global gFindString, gFindCase As Integer, gFindDirection As Integer
  17. Global gCurPos As Integer, gFirstTime As Integer
  18. Global ArrayNum As Integer
  19.  
  20. ' API functions used to read and write to MDINOTE.INI.
  21. ' Used for handling the recent files list.
  22. 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
  23. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  24. Declare Sub SpellEdit Lib "Spelmate.dll" (ByVal hWnd As Integer)
  25.  
  26. Function AnyPadsLeft () As Integer
  27.     Dim i As Integer
  28.  
  29.     ' Cycle throught the document array.
  30.     ' Return True if there is at least one
  31.     ' open document remaining.
  32.     For i = 1 To UBound(Document)
  33.         If Not FState(i).Deleted Then
  34.             AnyPadsLeft = True
  35.             Exit Function
  36.         End If
  37.     Next
  38.  
  39. End Function
  40.  
  41. Sub CenterForm (frmParent As Form, frmChild As Form)
  42. ' This procedure centers a child form over a parent form.
  43. ' Calling this routine loads the dialog. Use the Show method
  44. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  45.  
  46. Dim l, t
  47.   ' get left offset
  48.   l = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  49.   If (l + frmChild.Width > screen.Width) Then
  50.     l = screen.Width = frmChild.Width
  51.   End If
  52.  
  53.   ' get top offset
  54.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  55.   If (t + frmChild.Height > screen.Height) Then
  56.     t = screen.Height - frmChild.Height
  57.   End If
  58.  
  59.   ' center the child formfv
  60.   frmChild.Move l, t
  61.  
  62. End Sub
  63.  
  64. Sub EditCopyProc ()
  65.     ' Copy selected text to Clipboard.
  66.     ClipBoard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  67. End Sub
  68.  
  69. Sub EditCutProc ()
  70.     ' Copy selected text to Clipboard.
  71.     ClipBoard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  72.     ' Delete selected text.
  73.     frmMDI.ActiveForm.ActiveControl.SelText = ""
  74. End Sub
  75.  
  76. Sub EditPasteProc ()
  77.     ' Place text from Clipboard into active control.
  78.     frmMDI.ActiveForm.ActiveControl.SelText = ClipBoard.GetText()
  79. End Sub
  80.  
  81. Sub FileNew ()
  82.     Dim fIndex As Integer
  83.  
  84.     fIndex = FindFreeIndex()
  85.     Document(fIndex).Tag = fIndex
  86.     Document(fIndex).Caption = "Untitled:" & fIndex
  87.     Document(fIndex).Show
  88.  
  89.     ' Make sure toolbar edit buttons are visible
  90.     frmMDI!imgCutButton.Visible = True
  91.     frmMDI!imgCopyButton.Visible = True
  92.     frmMDI!imgPasteButton.Visible = True
  93.     
  94. End Sub
  95.  
  96. Function FindFreeIndex () As Integer
  97.     Dim i As Integer
  98.     Dim ArrayCount As Integer
  99.  
  100.     ArrayCount = UBound(Document)
  101.  
  102.     ' Cycle throught the document array. If one of the
  103.     ' documents has been deleted, then return that
  104.     ' index.
  105.     For i = 1 To ArrayCount
  106.         If FState(i).Deleted Then
  107.             FindFreeIndex = i
  108.             FState(i).Deleted = False
  109.             Exit Function
  110.         End If
  111.     Next
  112.  
  113.     ' If none of the elements in the document array have
  114.     ' been deleted, then increment the document and the
  115.     ' state arrays by one and return the index to the
  116.     ' new element.
  117.  
  118.     ReDim Preserve Document(ArrayCount + 1)
  119.     ReDim Preserve FState(ArrayCount + 1)
  120.     FindFreeIndex = UBound(Document)
  121. End Function
  122.  
  123. Sub FindIt ()
  124.     Dim start, pos, findstring, sourcestring, msg, response, Offset
  125.     
  126.     If (gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart) Then
  127.         Offset = 1
  128.     Else
  129.         Offset = 0
  130.     End If
  131.  
  132.     If gFirstTime Then Offset = 0
  133.  
  134.     start = frmMDI.ActiveForm.ActiveControl.SelStart + Offset
  135.         
  136.     If gFindCase Then
  137.         findstring = gFindString
  138.         sourcestring = frmMDI.ActiveForm.ActiveControl.Text
  139.     Else
  140.         findstring = UCase(gFindString)
  141.         sourcestring = UCase(frmMDI.ActiveForm.ActiveControl.Text)
  142.     End If
  143.             
  144.     If gFindDirection = 1 Then
  145.         pos = InStr(start + 1, sourcestring, findstring)
  146.     Else
  147.         For pos = start - 1 To 0 Step -1
  148.             If pos = 0 Then Exit For
  149.             If Mid(sourcestring, pos, Len(findstring)) = findstring Then Exit For
  150.         Next
  151.     End If
  152.  
  153.     ' If string is found
  154.     If pos Then
  155.         frmMDI.ActiveForm.ActiveControl.SelStart = pos - 1
  156.         frmMDI.ActiveForm.ActiveControl.SelLength = Len(findstring)
  157.     Else
  158.         msg = "Cannot find " & Chr(34) & gFindString & Chr(34)
  159.         response = MsgBox(msg, 0, App.Title)
  160.     End If
  161.     
  162.     gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart
  163.     gFirstTime = False
  164.  
  165. End Sub
  166.  
  167. Sub GetRecentFiles ()
  168.   Dim retval, key, i, j
  169.   Dim IniString As String
  170.  
  171.   ' This variable must be large enough to hold the return string
  172.   ' from the GetPrivateProfileString API.
  173.   IniString = String(255, 0)
  174.  
  175.   ' Get recent file strings from MDINOTE.INI
  176.   For i = 1 To 4
  177.     key = "RecentFile" & i
  178.     retval = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "MDINOTE.INI")
  179.     If retval And Left(IniString, 8) <> "Not Used" Then
  180.       ' Update the MDI form's menu.
  181.       frmMDI.mnuRecentFile(0).Visible = True
  182.       frmMDI.mnuRecentFile(i).Caption = IniString
  183.       frmMDI.mnuRecentFile(i).Visible = True
  184.   
  185.       ' Iterate through all the notepads and update each menu.
  186.       For j = 1 To UBound(Document)
  187.         If Not FState(j).Deleted Then
  188.           Document(j).mnuRecentFile(0).Visible = True
  189.           Document(j).mnuRecentFile(i).Caption = IniString
  190.           Document(j).mnuRecentFile(i).Visible = True
  191.         End If
  192.       Next j
  193.     End If
  194.   Next i
  195.  
  196. End Sub
  197.  
  198. Sub OptionsToolbarProc (CurrentForm As Form)
  199.     CurrentForm.mnuOToolbar.Checked = Not CurrentForm.mnuOToolbar.Checked
  200.     If TypeOf CurrentForm Is MDIForm Then
  201.     Else
  202.         frmMDI.mnuOToolbar.Checked = CurrentForm.mnuOToolbar.Checked
  203.     End If
  204.     If CurrentForm.mnuOToolbar.Checked Then
  205.         frmMDI.picToolbar.Visible = True
  206.     Else
  207.         frmMDI.picToolbar.Visible = False
  208.     End If
  209. End Sub
  210.  
  211. Sub WriteRecentFiles (OpenFileName)
  212.   Dim i, j, key, retval
  213.   Dim IniString As String
  214.   IniString = String(255, 0)
  215.  
  216.   ' Copy RecentFile1 to RecentFile2, etc.
  217.   For i = 3 To 1 Step -1
  218.     key = "RecentFile" & i
  219.     retval = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "MDINOTE.INI")
  220.     If retval And Left(IniString, 8) <> "Not Used" Then
  221.       key = "RecentFile" & (i + 1)
  222.       retval = WritePrivateProfileString("Recent Files", key, IniString, "MDINOTE.INI")
  223.     End If
  224.   Next i
  225.   
  226.   ' Write openfile to first Recent File.
  227.     retval = WritePrivateProfileString("Recent Files", "RecentFile1", OpenFileName, "MDINOTE.INI")
  228.  
  229. End Sub
  230.  
  231.