home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / PGUIDE / MDI / MDINOTE.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-01-17  |  6.7 KB  |  216 lines

  1. Attribute VB_Name = "Module1"
  2. '*** MDI ╝╟╩┬▒╛╙ª╙├│╠╨≥╩╛└²╚½╛╓─ú┐Θ               ***
  3. '****************************************************
  4. Option Explicit
  5.  
  6. ' ┤µ┤ó╣╪╙┌╫╙┤░╠σ╨┼╧ó╡─╙├╗º╫╘╢¿╥σ└α╨═
  7. Type FormState
  8.     Deleted As Integer
  9.     Dirty As Integer
  10.     Color As Long
  11. End Type
  12.  
  13. Public FState()  As FormState           ' ╙├╗º╫╘╢¿╥σ╨═╩²╫Θ
  14. Public Document() As New frmNotePad     ' ╫╙┤░╠σ╢╘╧≤╩²╫Θ
  15. Public gFindString As String            ' ▒ú┤µ╦╤╦≈╬─▒╛
  16. Public gFindCase As Integer             ' ╟°╖╓┤≤╨í╨┤▒Ω╓╛
  17. Public gFindDirection As Integer        ' ╦╤╦≈╖╜╧≥▒Ω╓╛
  18. Public gCurPos As Integer               ' ▒ú┤µ╡▒╟░╣Γ▒Ω╬╗╓├
  19. Public gFirstTime As Integer            ' ╞≡╩╝╬╗╓├
  20. Public gToolsHidden As Boolean          ' ▒ú┤µ╣ñ╛▀└╕╫┤╠¼
  21. Public Const ThisApp = "MDINote"        ' ThisApp │ú╩²
  22. Public Const ThisKey = "Recent Files"   ' ThisKey │ú╩²
  23.  
  24.  
  25. Function AnyPadsLeft() As Integer
  26.     Dim i As Integer        ' ╝╞╩²╞≈▒Σ┴┐
  27.  
  28.     ' ▒Θ└·╬─╡╡╩²╫Θ
  29.     ' ╚τ╣√╓┴╔┘╙╨╥╗╕÷┤≥┐¬╡─╬─╡╡ú¼╖╡╗╪ True
  30.     For i = 1 To UBound(Document)
  31.         If Not FState(i).Deleted Then
  32.             AnyPadsLeft = True
  33.             Exit Function
  34.         End If
  35.     Next
  36. End Function
  37.  
  38.  
  39. Sub EditCopyProc()
  40.     ' ╕┤╓╞╤í╢¿╬─▒╛╡╜╝⌠╠∙░σ
  41.     Clipboard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  42. End Sub
  43.  
  44. Sub EditCutProc()
  45.     ' ╕┤╓╞╤í╢¿╬─▒╛╡╜╝⌠╠∙░σ
  46.     Clipboard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  47.     ' ╔╛│²╤í╢¿╬─▒╛
  48.     frmMDI.ActiveForm.ActiveControl.SelText = ""
  49. End Sub
  50.  
  51. Sub EditPasteProc()
  52.     ' ╜½╬─▒╛┤╙╝⌠╠∙░σ╒│╠∙╡╜╗ε╢»┐╪╝■
  53.     frmMDI.ActiveForm.ActiveControl.SelText = Clipboard.GetText()
  54. End Sub
  55.  
  56. Sub FileNew()
  57.     Dim fIndex As Integer
  58.  
  59.     ' ╒╥╡╜╧┬╥╗╕÷┐╔╙├╡─╦≈╥²▓ó╧╘╩╛╕├╫╙┤░╠σ
  60.     fIndex = FindFreeIndex()
  61.     Document(fIndex).Tag = fIndex
  62.     Document(fIndex).Caption = "╬▐▒Ω╠Γú║" & fIndex
  63.     Document(fIndex).Show
  64.  
  65.     ' ╩╣╣ñ╛▀└╕╓╨▒α╝¡░┤┼Ñ┐╔╝√
  66.     frmMDI.imgCutButton.Visible = True
  67.     frmMDI.imgCopyButton.Visible = True
  68.     frmMDI.imgPasteButton.Visible = True
  69. End Sub
  70.  
  71. Function FindFreeIndex() As Integer
  72.     Dim i As Integer
  73.     Dim ArrayCount As Integer
  74.  
  75.     ArrayCount = UBound(Document)
  76.  
  77.     ' ▒Θ└·╬─╡╡╩²╫Θ
  78.     ' ╚τ╣√╥╤╔╛│²╞Σ╓╨╥╗╕÷╬─╡╡ú¼╖╡╗╪╞Σ╦≈╥²
  79.     For i = 1 To ArrayCount
  80.         If FState(i).Deleted Then
  81.             FindFreeIndex = i
  82.             FState(i).Deleted = False
  83.             Exit Function
  84.         End If
  85.     Next
  86.  
  87.     ' ╚τ╣√╫╙┤░╠σ╢╘╧≤╩²╫Θ╓╨╡─╥╗╕÷╘¬╦╪╢╝├╗╙╨╔╛│²ú¼
  88.     ' ╬─╡╡╩²╫Θ╙δ╫┤╠¼╩²╫Θ╛∙╝╙ 1 ▓ó╖╡╗╪╨┬╘¬╦╪╡─╦≈╥²
  89.     ReDim Preserve Document(ArrayCount + 1)
  90.     ReDim Preserve FState(ArrayCount + 1)
  91.     FindFreeIndex = UBound(Document)
  92. End Function
  93.  
  94. Sub FindIt()
  95.     Dim intStart As Integer
  96.     Dim intPos As Integer
  97.     Dim strFindString As String
  98.     Dim strSourceString As String
  99.     Dim strMsg As String
  100.     Dim intResponse As Integer
  101.     Dim intOffset As Integer
  102.     
  103.     ' ╕∙╛▌╡▒╟░╣Γ▒Ω╬╗╓├╔Φ╓├╞½╥╞┴┐▒Σ┴┐
  104.     If (gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart) Then
  105.         intOffset = 1
  106.     Else
  107.         intOffset = 0
  108.     End If
  109.  
  110.     ' ╬¬╞≡╩╝╬╗╓├╢┴╚½╛╓▒Σ┴┐
  111.     If gFirstTime Then intOffset = 0
  112.     ' ╕°╦╤╦≈╞≡╩╝╬╗╓├╕│╓╡
  113.     intStart = frmMDI.ActiveForm.ActiveControl.SelStart + intOffset
  114.         
  115.     ' ╚τ╣√▓╗╞Ñ┼Σ┤≤╨í╨┤ú¼╜½╫╓╖√┤«╫¬╗╗│╔┤≤╨┤
  116.     If gFindCase Then
  117.         strFindString = gFindString
  118.         strSourceString = frmMDI.ActiveForm.ActiveControl.Text
  119.     Else
  120.         strFindString = UCase(gFindString)
  121.         strSourceString = UCase(frmMDI.ActiveForm.ActiveControl.Text)
  122.     End If
  123.             
  124.     ' ╦╤╦≈╫╓╖√┤«
  125.     If gFindDirection = 1 Then
  126.         intPos = InStr(intStart + 1, strSourceString, strFindString)
  127.     Else
  128.         For intPos = intStart - 1 To 0 Step -1
  129.             If intPos = 0 Then Exit For
  130.             If Mid(strSourceString, intPos, Len(strFindString)) = strFindString Then Exit For
  131.         Next
  132.     End If
  133.  
  134.     ' ╚τ╣√╒╥╡╜┴╦╫╓╖√┤«...
  135.     If intPos Then
  136.         frmMDI.ActiveForm.ActiveControl.SelStart = intPos - 1
  137.         frmMDI.ActiveForm.ActiveControl.SelLength = Len(strFindString)
  138.     Else
  139.         strMsg = "╒╥▓╗╡╜ " & Chr(34) & gFindString & Chr(34)
  140.         intResponse = MsgBox(strMsg, 0, App.Title)
  141.     End If
  142.     
  143.     ' ╓╪╨┬╔Φ╓├╚½╛╓▒Σ┴┐
  144.     gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart
  145.     gFirstTime = False
  146. End Sub
  147.  
  148. Sub GetRecentFiles()
  149.     ' ▒╛╣²│╠╤▌╩╛ GetAllSettings ║»╩²╡─╙├╖¿ú¼╦ⁿ┤╙ Windows ╫ó▓ß▒φ╓╨╖╡╗╪╓╡╡─╩²╫Θíú
  150. ' ╘┌╒Γ╓╓╟Θ┐÷╧┬ú¼╫ó▓ß▒φ░ⁿ║¼╫ε╜ⁿ┤≥┐¬╡─╬─╝■┴╨▒φíú
  151. ' ╩╣╙├ SaveSetting ╙∩╛Σ╝╟╧┬╫ε╜ⁿ╩╣╙├╡─╬─╝■├√íú
  152.     ' ╕├╙∩╛Σ╘┌ WriteRecentFiles ╣²│╠╓╨íú
  153.     Dim i, j As Integer
  154.     Dim varFiles As Variant ' ┤µ┤ó╖╡╗╪╡─╩²╫Θ
  155.     
  156.     ' ╙├ GetAllSettings ╙∩╛Σ┤╙╫ó▓ß▒φ╓╨╖╡╗╪╫ε╜ⁿ╩╣╙├╡─╬─╝■íú
  157.     ' ─ú┐Θ╓╨╢¿╥σ│ú╩² ThisApp ║═ ThisKey
  158.     If GetSetting(ThisApp, ThisKey, "RecentFile1") = Empty Then Exit Sub
  159.     
  160.     varFiles = GetAllSettings(ThisApp, ThisKey)
  161.     
  162.     For i = 0 To UBound(varFiles, 1)
  163.         
  164.         frmMDI.mnuRecentFile(0).Visible = True
  165.         frmMDI.mnuRecentFile(i).Caption = varFiles(i, 1)
  166.         frmMDI.mnuRecentFile(i).Visible = True
  167.             ' ▒Θ└·╦∙╙╨╬─╡╡▓ó╕ⁿ╨┬├┐╕÷▓╦╡Ñ
  168.             For j = 1 To UBound(Document)
  169.                 If Not FState(j).Deleted Then
  170.                     Document(j).mnuRecentFile(0).Visible = True
  171.                     Document(j).mnuRecentFile(i + 1).Caption = varFiles(i, 1)
  172.                     Document(j).mnuRecentFile(i + 1).Visible = True
  173.                 End If
  174.             Next j
  175.     Next i
  176.  
  177. End Sub
  178.  
  179. Sub OptionsToolbarProc(CurrentForm As Form)
  180.     ' ╟╨╗╗ Checked ╩⌠╨╘
  181.     CurrentForm.mnuOptionsToolbar.Checked = Not CurrentForm.mnuOptionsToolbar.Checked
  182.     ' ╚τ╣√▓╗╩╟ MDI ┤░╠σú¼╔Φ╓├ MDI ┤░╠σ╡─ Checked ╩⌠╨╘
  183.     If Not TypeOf CurrentForm Is MDIForm Then
  184.         frmMDI.mnuOptionsToolbar.Checked = CurrentForm.mnuOptionsToolbar.Checked
  185.     End If
  186.     ' ╗∙╙┌╓╡╟╨╗╗╣ñ╛▀└╕
  187.     If CurrentForm.mnuOptionsToolbar.Checked Then
  188.         frmMDI.picToolbar.Visible = True
  189.     Else
  190.         frmMDI.picToolbar.Visible = False
  191.     End If
  192. End Sub
  193.  
  194. Sub WriteRecentFiles(OpenFileName)
  195.     ' ▒╛╣²│╠╩╣╙├ SaveSettings ╙∩╛Σ╜½╫ε╜ⁿ╩╣╙├╡─╬─╝■├√╨┤╚δ╧╡═│╫ó▓ß▒φíú
  196.     ' SaveSettings ╙∩╛Σ╥¬╟≤╚²╕÷▓╬╩²╞Σ╓╨┴╜╕÷┤µ┤ó╬¬│ú╩²▓ó╘┌▒╛─ú┐Θ─┌╢¿╥σíú
  197.     ' GetRecentFiles ╣²│╠╓╨╩╣╙├ GetAllSettings ║»╩²└┤╝∞╦≈╘┌╒Γ╕÷╣²│╠╓╨┤µ┤ó╡─╬─╝■├√íú
  198.     
  199.     Dim i, j As Integer
  200.     Dim strFile, key As String
  201.  
  202.     ' ╜½╬─╝■ RecentFile1 ╕┤╓╞╕° RecentFile2ú¼╡╚╡╚
  203.     For i = 3 To 1 Step -1
  204.         key = "RecentFile" & i
  205.         strFile = GetSetting(ThisApp, ThisKey, key)
  206.         If strFile <> "" Then
  207.             key = "RecentFile" & (i + 1)
  208.             SaveSetting ThisApp, ThisKey, key, strFile
  209.         End If
  210.     Next i
  211.   
  212.     ' ╜½╒²╘┌┤≥┐¬╡─╬─╝■╨┤╡╜╫ε╜ⁿ╩╣╙├╡─╬─╝■┴╨▒φ╡─╡┌╥╗╧ε
  213.     SaveSetting ThisApp, ThisKey, "RecentFile1", OpenFileName
  214. End Sub
  215.  
  216.