home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 October / pcp156b.iso / handson / files / copyvbwk.exe / examples / te1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-29  |  9.1 KB  |  315 lines

  1. VERSION 5.00
  2. Object = "{8AE029D0-08E3-11D1-BAA2-444553540000}#3.0#0"; "VSFLEX3.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Begin VB.Form Form1 
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   6510
  7.    ClientLeft      =   165
  8.    ClientTop       =   735
  9.    ClientWidth     =   7185
  10.    HelpContextID   =   1
  11.    KeyPreview      =   -1  'True
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   6510
  14.    ScaleWidth      =   7185
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton Command2 
  17.       Caption         =   "Command2"
  18.       Height          =   735
  19.       HelpContextID   =   2
  20.       Left            =   3000
  21.       TabIndex        =   1
  22.       Top             =   840
  23.       WhatsThisHelpID =   2
  24.       Width           =   1695
  25.    End
  26.    Begin VB.CommandButton Command1 
  27.       Caption         =   "Command1"
  28.       Height          =   735
  29.       HelpContextID   =   1
  30.       Left            =   960
  31.       TabIndex        =   0
  32.       Top             =   840
  33.       WhatsThisHelpID =   1
  34.       Width           =   1575
  35.    End
  36.    Begin MSComDlg.CommonDialog CommonDialog1 
  37.       Left            =   600
  38.       Top             =   2520
  39.       _ExtentX        =   847
  40.       _ExtentY        =   847
  41.       _Version        =   393216
  42.    End
  43.    Begin vsFlexLib.vsFlexString vsFlexString1 
  44.       Left            =   2520
  45.       Top             =   2520
  46.       _Version        =   196608
  47.       _ExtentX        =   847
  48.       _ExtentY        =   847
  49.       _StockProps     =   0
  50.    End
  51.    Begin VB.Menu mnuFile 
  52.       Caption         =   "File"
  53.       Begin VB.Menu mnuOpen 
  54.          Caption         =   "Open"
  55.       End
  56.       Begin VB.Menu mnuSave 
  57.          Caption         =   "Save"
  58.       End
  59.       Begin VB.Menu x 
  60.          Caption         =   "-"
  61.       End
  62.       Begin VB.Menu mnuRecentFile 
  63.          Caption         =   ""
  64.          Enabled         =   0   'False
  65.          Index           =   0
  66.          Visible         =   0   'False
  67.       End
  68.       Begin VB.Menu mnuRecentFile 
  69.          Caption         =   ""
  70.          Enabled         =   0   'False
  71.          Index           =   1
  72.          Visible         =   0   'False
  73.       End
  74.       Begin VB.Menu mnuRecentFile 
  75.          Caption         =   ""
  76.          Enabled         =   0   'False
  77.          Index           =   2
  78.          Visible         =   0   'False
  79.       End
  80.       Begin VB.Menu mnuRecentFile 
  81.          Caption         =   ""
  82.          Enabled         =   0   'False
  83.          Index           =   3
  84.          Visible         =   0   'False
  85.       End
  86.    End
  87.    Begin VB.Menu mnuEdit 
  88.       Caption         =   "Edit"
  89.       Begin VB.Menu mnuFind 
  90.          Caption         =   "Find"
  91.       End
  92.       Begin VB.Menu mnuReplace 
  93.          Caption         =   "Replace"
  94.       End
  95.       Begin VB.Menu mnuGotoLine 
  96.          Caption         =   "Goto Line"
  97.       End
  98.    End
  99.    Begin VB.Menu mnuFont 
  100.       Caption         =   "Font"
  101.    End
  102.    Begin VB.Menu mnuHelp 
  103.       Caption         =   "Help"
  104.       NegotiatePosition=   3  'Right
  105.    End
  106. Attribute VB_Name = "Form1"
  107. Attribute VB_GlobalNameSpace = False
  108. Attribute VB_Creatable = False
  109. Attribute VB_PredeclaredId = True
  110. Attribute VB_Exposed = False
  111. Option Explicit
  112. Const HH_DISPLAY_TOPIC = &H0
  113. Const HH_SET_WIN_TYPE = &H4
  114. Const HH_GET_WIN_TYPE = &H5
  115. Const HH_GET_WIN_HANDLE = &H6
  116. Const HH_DISPLAY_TEXT_POPUP = &HE
  117. Const HH_HELP_CONTEXT = &HF
  118. Const HH_TP_HELP_CONTEXTMENU = &H10
  119. Const HH_TP_HELP_WM_HELP = &H11
  120. Private fn(3) As String
  121. Private Declare Function WritePrivateProfileString Lib _
  122.     "kernel32" Alias "WritePrivateProfileStringA" _
  123.     (ByVal lpApplicationName As String, _
  124.      ByVal lpKeyName As Any, _
  125.      ByVal lpString As Any, _
  126.      ByVal lpFileName As String) As Long
  127. Private Declare Function GetPrivateProfileString Lib _
  128.     "kernel32" Alias "GetPrivateProfileStringA" _
  129.     (ByVal lpApplicationName As String, _
  130.      ByVal lpKeyName As Any, _
  131.      ByVal lpDefault As String, _
  132.      ByVal lpReturnedString As String, _
  133.      ByVal nSize As Long, ByVal lpFileName As String) As Long
  134. Private Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
  135.   (ByVal hwndCaller As Long, ByVal pszFile As String, _
  136.   ByVal uCommand As Long, ByVal dwData As Long) As Long
  137. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  138. Dim r As Long
  139. If KeyCode = vbKeyF1 Then
  140.    r = HtmlHelp(Me.ActiveControl.hWnd, _
  141.    App.Path & "\vbhelptest.chm", HH_HELP_CONTEXT, Me.ActiveControl.HelpContextID)
  142. End If
  143. End Sub
  144. Private Sub Form_Load()
  145. Dim r As Long, s As String
  146. s = String(255, 0)
  147. r = GetPrivateProfileString("VBMenu", "File0", "", s, 255, "menu.ini")
  148. If r <> 0 Then
  149.     mnuRecentFile(0).Caption = s
  150.     fn(0) = s
  151.     mnuRecentFile(0).Enabled = True
  152.     mnuRecentFile(0).Visible = True
  153. End If
  154. r = GetPrivateProfileString("VBMenu", "File1", "", s, 255, "menu.ini")
  155. If r <> 0 Then
  156.     mnuRecentFile(1).Caption = s
  157.     fn(1) = s
  158.     mnuRecentFile(1).Enabled = True
  159.     mnuRecentFile(1).Visible = True
  160. End If
  161. r = GetPrivateProfileString("VBMenu", "File2", "", s, 255, "menu.ini")
  162. If r <> 0 Then
  163.     mnuRecentFile(2).Caption = s
  164.     fn(2) = s
  165.     mnuRecentFile(2).Enabled = True
  166.     mnuRecentFile(2).Visible = True
  167. End If
  168. r = GetPrivateProfileString("VBMenu", "File3", "", s, 255, "menu.ini")
  169. If r <> 0 Then
  170.     mnuRecentFile(3).Caption = s
  171.     fn(3) = s
  172.     mnuRecentFile(3).Enabled = True
  173.     mnuRecentFile(3).Visible = True
  174. End If
  175. RTE1.HandleMouse
  176. End Sub
  177. Private Sub Form_Unload(Cancel As Integer)
  178. Dim r As Long
  179. If fn(0) <> "" Then
  180.     r = WritePrivateProfileString("VBmenu", "File0", fn(0), "menu.ini")
  181. End If
  182. If fn(1) <> "" Then
  183.     r = WritePrivateProfileString("VBmenu", "File1", fn(1), "menu.ini")
  184. End If
  185. If fn(2) <> "" Then
  186.     r = WritePrivateProfileString("VBmenu", "File2", fn(2), "menu.ini")
  187. End If
  188. If fn(3) <> "" Then
  189.     r = WritePrivateProfileString("VBmenu", "File3", fn(3), "menu.ini")
  190. End If
  191. End Sub
  192. Private Sub mnuFind_Click()
  193. Dim r As Long
  194. FindDialog.Show vbModal
  195. If FindDialog.SearchText <> "" Then
  196.     vsFlexString1.Pattern = FindDialog.SearchText
  197.     vsFlexString1.Text = RTE1.Text
  198.     If vsFlexString1.MatchCount > 0 Then
  199.         vsFlexString1.MatchIndex = 0
  200.         r = RTE1.HighlightText(vsFlexString1.MatchStart, Len(FindDialog.SearchText))
  201.     Else
  202.         MsgBox "String not found!"
  203.     End If
  204. End If
  205. End Sub
  206. Private Sub mnuFont_Click()
  207. RTE1.Font = ""
  208. End Sub
  209. Private Sub mnuGotoLine_Click()
  210. Dim x As Long, Lines As Long, posn As Long, r As Long
  211. GotoLineDialog.Show vbModal
  212. x = GotoLineDialog.LineNumber
  213. ' this is a quick way of finding the number of lines
  214. 'r = SendMessage(RTE1.hWnd, EM_GETLINECOUNT, 0, 0)
  215. If x > 1 Then
  216.     vsFlexString1.Pattern = Chr(13)
  217.     vsFlexString1.Text = RTE1.Text
  218.     If x > vsFlexString1.MatchCount + 1 Then
  219.         MsgBox "not enough lines!"
  220.     Else
  221.         ' Flex is zero based  ...
  222.         ' ... so we have to adjust a little
  223.         vsFlexString1.MatchIndex = x - 2
  224.         posn = vsFlexString1.MatchStart + 1
  225.         r = RTE1.HighlightText(posn, 0)
  226.     End If
  227. ElseIf x = 1 Then
  228. ' the first line is offset zero
  229.     r = RTE1.HighlightText(0, 0)
  230. End If
  231. End Sub
  232. Private Sub mnuHelp_Click()
  233. Dim hwndHelp As Long
  234. hwndHelp = HtmlHelp(hWnd, App.Path & "\vbhelptest.chm", HH_DISPLAY_TOPIC, 0)
  235. If hwndHelp = 0 Then
  236.     MsgBox "No help!"
  237. End If
  238. End Sub
  239. Private Sub mnuOpen_Click()
  240. Dim s As String, t As String, u As String
  241. On Error GoTo ExitSub
  242. CommonDialog1.CancelError = True
  243. CommonDialog1.ShowOpen
  244. s = CommonDialog1.filename
  245. Open s For Input As #1
  246. Do Until EOF(1)
  247.     Line Input #1, t
  248.     u = u + t + Chr(13)
  249. Close #1
  250. RTE1.Text = u
  251. ExitSub:
  252. End Sub
  253. Private Sub mnuRecentFile_Click(Index As Integer)
  254. Dim s As String, t As String, u As String
  255. On Error GoTo Error1
  256. s = mnuRecentFile(Index).Caption
  257. Open s For Input As #1
  258. Do Until EOF(1)
  259.     Line Input #1, t
  260.     u = u + t + Chr(13)
  261. Close #1
  262. RTE1.Text = u
  263. Exit Sub
  264. Error1:
  265. MsgBox "File " & s & " not found"
  266. End Sub
  267. Private Sub mnuReplace_Click()
  268. Dim r As Long
  269. ReplaceDialog.Show vbModal
  270. If ReplaceDialog.SearchText <> "" Then
  271.     vsFlexString1.Text = RTE1.Text
  272.     vsFlexString1.Pattern = ReplaceDialog.SearchText
  273.     If vsFlexString1.MatchCount > 0 Then
  274.         vsFlexString1.Replace = ReplaceDialog.ReplaceText
  275.         RTE1.Text = vsFlexString1.Text
  276.     Else
  277.         MsgBox "String not found!"
  278.     End If
  279. End If
  280. End Sub
  281. Private Sub mnuSave_Click()
  282. Dim s As String, u As String
  283. On Error GoTo ExitSub
  284. CommonDialog1.CancelError = True
  285. CommonDialog1.ShowSave
  286. s = CommonDialog1.filename
  287. Open s For Output As #1
  288. u = RTE1.Text
  289. Print #1, u
  290. Close #1
  291. 'fixup recently used file menus
  292. fn(3) = fn(2)
  293. fn(2) = fn(1)
  294. fn(1) = fn(0)
  295. fn(0) = s
  296. If fn(0) <> "" Then
  297.     UpdateMenu 0
  298. End If
  299. If fn(1) <> "" Then
  300.     UpdateMenu 1
  301. End If
  302. If fn(2) <> "" Then
  303.     UpdateMenu 2
  304. End If
  305. If fn(3) <> "" Then
  306.     UpdateMenu 3
  307. End If
  308. ExitSub:
  309. End Sub
  310. Sub UpdateMenu(i As Integer)
  311.     mnuRecentFile(i).Caption = fn(i)
  312.     mnuRecentFile(i).Enabled = True
  313.     mnuRecentFile(i).Visible = True
  314. End Sub
  315.