home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / inpv10 / inotepad.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  16.6 KB  |  610 lines

  1. VERSION 2.00
  2. Begin Form form1 
  3.    Caption         =   "INOTEPAD"
  4.    ClientHeight    =   4635
  5.    ClientLeft      =   120
  6.    ClientTop       =   1245
  7.    ClientWidth     =   8865
  8.    Height          =   5325
  9.    Icon            =   INOTEPAD.FRX:0000
  10.    Left            =   60
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4635
  14.    ScaleWidth      =   8865
  15.    Top             =   615
  16.    Width           =   8985
  17.    Begin TextBox searchbut 
  18.       BorderStyle     =   0  'None
  19.       Height          =   200
  20.       Left            =   8400
  21.       TabIndex        =   1
  22.       TabStop         =   0   'False
  23.       Top             =   0
  24.       Width           =   100
  25.    End
  26.    Begin TextBox Text1 
  27.       BorderStyle     =   0  'None
  28.       Height          =   3980
  29.       Left            =   0
  30.       MultiLine       =   -1  'True
  31.       ScrollBars      =   2  'Vertical
  32.       TabIndex        =   0
  33.       Top             =   0
  34.       Width           =   5775
  35.    End
  36.    Begin Menu filemenu 
  37.       Caption         =   "&File"
  38.       Begin Menu newfilemenu 
  39.          Caption         =   "&New"
  40.          Shortcut        =   ^N
  41.       End
  42.       Begin Menu openfilemenu 
  43.          Caption         =   "&Open"
  44.       End
  45.       Begin Menu savefilemenu 
  46.          Caption         =   "&Save"
  47.          Shortcut        =   ^S
  48.       End
  49.       Begin Menu saveasfilemenu 
  50.          Caption         =   "Save &As"
  51.       End
  52.       Begin Menu choosefontmenu 
  53.          Caption         =   "&Choose Font"
  54.       End
  55.       Begin Menu printfilemenu 
  56.          Caption         =   "&Print"
  57.       End
  58.       Begin Menu sep1 
  59.          Caption         =   "-"
  60.       End
  61.       Begin Menu exitmenu 
  62.          Caption         =   "E&xit"
  63.       End
  64.    End
  65.    Begin Menu editmenu 
  66.       Caption         =   "&Edit"
  67.       Begin Menu undoeditmenu 
  68.          Caption         =   "&Undo"
  69.       End
  70.       Begin Menu sep2 
  71.          Caption         =   "-"
  72.       End
  73.       Begin Menu cuteditmenu 
  74.          Caption         =   "Cu&t"
  75.          Shortcut        =   ^X
  76.       End
  77.       Begin Menu copyeditmenu 
  78.          Caption         =   "&Copy"
  79.          Shortcut        =   ^C
  80.       End
  81.       Begin Menu pasteeditmenu 
  82.          Caption         =   "Pas&te"
  83.          Shortcut        =   ^V
  84.       End
  85.       Begin Menu deleditmenu 
  86.          Caption         =   "De&l"
  87.       End
  88.       Begin Menu sep3 
  89.          Caption         =   "-"
  90.       End
  91.       Begin Menu selectalleditmenu 
  92.          Caption         =   "Select &All"
  93.       End
  94.       Begin Menu stripcrlfmenu 
  95.          Caption         =   "&Strip CrLf"
  96.          Shortcut        =   ^Z
  97.       End
  98.       Begin Menu sep4 
  99.          Caption         =   "-"
  100.       End
  101.       Begin Menu macromenu 
  102.          Caption         =   "Edit &Macros"
  103.       End
  104.    End
  105.    Begin Menu searchmenu 
  106.       Caption         =   "&Search"
  107.       Begin Menu findsearchmenu 
  108.          Caption         =   "&Find"
  109.       End
  110.       Begin Menu findnextsearchmenu 
  111.          Caption         =   "Find &Next"
  112.          Shortcut        =   {F3}
  113.       End
  114.    End
  115.    Begin Menu macroexecutemenu 
  116.       Caption         =   "&Macros"
  117.    End
  118.    Begin Menu spacer1 
  119.       Caption         =   "                "
  120.       Enabled         =   0   'False
  121.    End
  122.    Begin Menu helpmenu 
  123.       Caption         =   "&Help"
  124.    End
  125. DefInt A-Z
  126. Dim EditFile As String, EditFileName As String
  127. Dim Textfile(0) As String
  128. Dim Temp() As String
  129. Dim Changed As Integer
  130. Dim DlgFlags As Long
  131. Dim FindText As String
  132. Dim StartPos As Integer
  133. Dim PrinterHdc As Integer
  134. Dim WindowsDir As String
  135. Dim GetFileType As MhGetFileType
  136. Dim FileFilterType() As MhFileFilterType
  137. Dim PrintDlgType As MhPrintDlgType
  138. Sub choosefontmenu_Click ()
  139. '---------------------------
  140. Dim ChooseFontType As MhChooseFontType
  141. Dim LogFontType As MhLogFontType
  142. Dim FontFlags As Long
  143. ChooseFontType.hWnd = 0
  144. ChooseFontType.pointSize = 100
  145. FontFlags = CF_ANSIONLY + CF_BOTH + CF_LIMITSIZE + CF_SCALABLEONLY + CF_WYSIWYG
  146. ChooseFontType.Flags = FontFlags
  147. ChooseFontType.MinSize = 8
  148. ChooseFontType.MaxSize = 12
  149. ChooseFontType.FontType = Printer_Font
  150. Result% = MhChooseFont%(LogFontType, ChooseFontType)
  151. If Result% <> 0 And MhECode%() = 0 Then Exit Sub
  152. If Result% <> 0 And MhECode%() <> 0 Then
  153.     MsgBox "Error # " + Str$(MhECode%()) + "in selecting font"
  154.     Exit Sub
  155. End If
  156. PrtFontName = RTrim$(LogFontType.FontFaceName)
  157. PrtFontSize = LogFontType.FontHeight * -1
  158. h = MhCtrlHwnd%(Text1)
  159. Result% = MhSetFont%(h, 1, LogFontType)
  160. End Sub
  161. Sub copyeditmenu_Click ()
  162. '-------------------------
  163. ClipBoard.Clear
  164. ClipBoard.SetText Text1.SelText
  165. End Sub
  166. Sub cuteditmenu_Click ()
  167. '---------------------------
  168. ClipBoard.Clear
  169. ClipBoard.SetText Text1.SelText
  170. Text1.SelText = ""
  171. End Sub
  172. Sub deleditmenu_Click ()
  173. '-----------------------
  174. Text1.SelText = ""
  175. Text1.SetFocus
  176. End Sub
  177. Sub exitmenu_click ()
  178. '-----------------------
  179. SaveIniData
  180. If Changed = True Then
  181.     Check% = MsgBox("Do You need to save the file?  (Select Cancel to return to the Program.)", 3, "File Warning")
  182.     If Check% = 2 Then Exit Sub
  183.     If Check% = 6 Then savefilemenu_click
  184. End If
  185. End Sub
  186. Sub findnextsearchmenu_Click ()
  187. '------------------------------
  188. tmp$ = Text1.Text
  189. K = MhFwdInstrS%(StartPos, tmp$, FindText)
  190. If K = 0 Then
  191.     MsgBox " reached the end of the document"
  192.     Exit Sub
  193. End If
  194. Text1.SelStart = K - 1
  195. StartPos = K + Len(FindText)
  196. End Sub
  197. Sub findsearchmenu_Click ()
  198. '------------------------------
  199. StartPos = 0
  200. MyKeyCode% = 255
  201. MyHWnd% = MhCtrlHwnd(Searchbut)
  202. DlgFlags = FR_DOWN + FR_NOWHOLEWORD + FR_NOUPDOWN + FR_MATCHCASE + FR_NOMATCHCASE
  203. Find$ = FindText
  204. Result% = MhFindText%(MyKeyCode%, MyHWnd%, DlgFlags, Find$)
  205. If Result% < 0 Then
  206.     MsgBox "Find Routine Failed"
  207.     Exit Sub
  208. End If
  209. End Sub
  210. Sub Form_Load ()
  211. '---------------------
  212. On Error Resume Next
  213. WindowsDir = MhWinDir$()
  214. IniFile = WindowsDir + "\inotepad.ini"
  215. Dim P As Long
  216. If MhFileExists%(IniFile) Then
  217.     Open IniFile For Binary As #1
  218.     P = 7
  219.     Get #1, P, L%
  220.     P = P + 2
  221.     PrtFontName = Space$(L%)
  222.     Get #1, P, PrtFontName
  223.     P = P + L%
  224.     Get #1, P, PrtFontSize
  225.     P = P + 2
  226.     For i% = 0 To 24
  227.     Get #1, P, Macros(i%).Title
  228.     P = P + 30
  229.     Get #1, P, Macros(i%).Text
  230.     P = P + 2000
  231.     Next i%
  232.     Close #1
  233.     PuHandle = 99
  234. End If
  235. If RTrim$(PrtFontName) = "" Then
  236.     Version% = MhWinVersion(Major%, Minor%)
  237.     If Minor% = 10 Then
  238.     PrtFontName = "Arial"
  239.     Else
  240.     PrtFontName = "Helv"
  241.     End If
  242.     PrtFontSize = 10
  243. End If
  244. Changed = False
  245. Text1.FontName = PrtFontName
  246. Text1.FontSize = PrtFontSize
  247. If Command$ <> "" Then
  248.     EditFile = Command$
  249.     EditFileName = Right$(EditFile, 12)
  250.     Open EditFile For Binary As #1
  251.     filelength& = LOF(1)
  252.     If filelength& > 64000 Then
  253.     MsgBox "File is too long to edit", 16
  254.     Close #1
  255.     Exit Sub
  256.     End If
  257.     Textfile(0) = String$(filelength&, 0)
  258.     Get #1, , Textfile(0)
  259.     Close #1
  260.     Form1.caption = "INOTEPAD - " + EditFile
  261.     Text1.Text = Textfile(0)
  262.     Text1.SetFocus
  263. End If
  264. Text1.SetFocus
  265. TextLimit% = &HFFFF
  266. retVal = SendMessage&(GetFocus(), EM_LIMITTEXT, TextLimit%, 0)
  267. MakePuMenus
  268. End Sub
  269. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  270. If (Button And 2) Then
  271.     Result% = MhPUTrack%((Form1.hWnd), PuHandle, 0, 0)
  272.     If Result% < 0 Then
  273.     MsgBox "Pop up Menu Execute Error"
  274.     Exit Sub
  275.     End If
  276.     PuExecute Result%
  277. End If
  278. End Sub
  279. Sub Form_Resize ()
  280. '--------------------
  281. If WindowState <> 1 Then
  282. Text1.Move 0, 0, ScaleWidth, ScaleHeight
  283. End If
  284. End Sub
  285. Sub Form_Unload (Cancel As Integer)
  286. '-----------------------------------
  287. If Changed = True Then
  288.     Check% = MsgBox("Do You need to save the file?", 4, "File Warning")
  289.     If Check% = 6 Then savefilemenu_click
  290. End If
  291. SaveIniData
  292. End Sub
  293. Sub helpmenu_Click ()
  294. '----------------------
  295. Form1.Mousepointer = 11
  296. helpfile$ = "C:\windows\inotepad.hlp"
  297. Tp% = Winhelp(hWnd, helpfile$, Help_Index, "0")
  298. Form1.Mousepointer = 0
  299. End Sub
  300. Sub macroexecutemenu_Click ()
  301. '----------------------------
  302. Text1_Keyup 16, 2
  303. End Sub
  304. Sub macromenu_Click ()
  305. '----------------------
  306. Form2.Show
  307. End Sub
  308. Sub newfilemenu_Click ()
  309. '--------------------------
  310. If Changed = True Then
  311.     Check% = MsgBox("Do You need to save the file?", 4, "File Warning")
  312.     If Check% = 6 Then savefilemenu_click
  313. End If
  314. EditFile = ""
  315. EditFileName = ""
  316. Form1.caption = "INOTEPAD - <New File>"
  317. Text1.SetFocus
  318. Text1.Text = ""
  319. Changed = False
  320. End Sub
  321. Sub openfilemenu_Click ()
  322. '-------------------------
  323. If Changed = True Then
  324.     Check% = MsgBox("Do You need to save the file?", 4, "File Warning")
  325.     If Check% = 6 Then savefilemenu_click
  326. End If
  327. On Error Resume Next
  328. ReDim FileFilterType(1 To 5)  As MhFileFilterType
  329. FileFilterType(1).Description = "Text Files (*.txt)"
  330. FileFilterType(1).Mask = "*.txt"
  331. FileFilterType(2).Description = "All Files(*.*)"
  332. FileFilterType(2).Mask = "*.*"
  333. FileFilterType(3).Description = "INI Files(*.ini)"
  334. FileFilterType(3).Mask = "*.ini"
  335. FileFilterType(4).Description = "System Files(*.sys)"
  336. FileFilterType(4).Mask = "*.sys"
  337. FileFilterType(5).Description = "Doc Files(*.doc;*.txt;*.bak"
  338. FileFilterType(5).Mask = "*.doc;*.txt;*.bak"
  339. GetFileType.FilterIndex = 1
  340. GetFileType.InitDir = "C:\"
  341. GetFileType.DefaultExtension = "txt"
  342. GetFileType.HowManyFilters = UBound(FileFilterType)
  343. GetFileType.hWnd = 0
  344. EditFile = MhGetOpenFileNAme$(GetFileType, FileFilterType(1))
  345. If EditFile = "" And MhECode%() = 0 Then Exit Sub
  346. If EditFile = "" And MhECode%() < 0 Then
  347.     MsgBox "Error # " + EditFile + " Opening file"
  348.     Exit Sub
  349. End If
  350. EditFileName = MhGetFileTitle(EditFile)
  351. Form1.caption = "INOTEPAD - " + EditFileName
  352. On Error GoTo fileopentrouble
  353.     Open EditFile For Binary As #1
  354. On Error GoTo 0
  355.     filelength& = LOF(1)
  356.     If filelength& > 64000 Then
  357.     MsgBox "File is too long to edit", 16
  358.     Close #1
  359.     Exit Sub
  360.     End If
  361.     Textfile(0) = String$(filelength&, 0)
  362.     Get #1, , Textfile(0)
  363.     On Error GoTo 0
  364.     Close #1
  365.     Form1.caption = "INOTEPAD - " + EditFileName
  366.     Text1.Text = Textfile(0)
  367.     Text1.SetFocus
  368.     Changed = False
  369.     Exit Sub
  370. fileopentrouble:
  371.      MsgBox "Unable to open file!!", 48, "File Error"
  372.      Close #1
  373.      Exit Sub
  374.      Resume Next
  375. End Sub
  376. Sub pasteeditmenu_Click ()
  377. '-----------------------
  378. Text1.SelText = ClipBoard.GetText()
  379. Text1.SetFocus
  380. End Sub
  381. Sub printfilemenu_Click ()
  382. '---------------------------
  383. Const LM = 1000
  384. Const TM = 1000
  385. Dim Curpos As Long
  386. Dim Totalprint As Long
  387. Dim Segment As String
  388. ReDim Temp(0) As String
  389. Dim TestChar As Integer
  390. Dim Ptext As String
  391. Dim PrintText As String
  392. Dim FirstPageHead As String
  393. Dim Testpos As Integer
  394. Dim BreakPos As Integer
  395. Dim PrtPos As Integer
  396. Dim Lines As Integer
  397. Dim MaxLines As Integer
  398. Screen.Mousepointer = 11
  399. Printer.FontName = PrtFontName
  400. Printer.FontSize = PrtFontSize
  401. Select Case PrtFontSize
  402.     Case Is < 10
  403.     TextPrintWidth = 100
  404.     MaxLines = 62
  405.     Case Is = 10
  406.     TextPrintWidth = 85
  407.     MaxLines = 56
  408.     Case Is > 10
  409.     TextPrintWidth = 72
  410.     MaxLines = 48
  411. End Select
  412. FirstPageHead = EditFileName
  413. If Len(Text1.SelText) = 0 Then
  414.     Temp(0) = RTrim$(Text1.Text)
  415.     PrintDlgType.hWnd = 0
  416.     Flags& = PD_NOPAGENUMS + PD_USEDEVMODECOPIES
  417.     PrintDlgType.Flags = Flags&
  418.     Result% = MhPrintDlg%(PrintDlgType)
  419.     If Result% <> 0 Then
  420.     If MhECode%() = 0 Then
  421.         GoTo exitlabel
  422.     Else
  423.         MsgBox "Error # " + Str$(Result%) + " in printing"
  424.         GoTo exitlabel
  425.     End If
  426.     End If
  427.     If (PrintDlgType.Flags And PD_SELECTION) Then
  428.     Temp(0) = Text1.SelText
  429.     If Temp(0) = "" Then
  430.         Check% = MsgBox("No Text has been selected to print", 48, "Print Alert")
  431.         GoTo exitlabel
  432.     End If
  433.     Else
  434.     Temp(0) = RTrim$(Text1.Text)
  435.     End If
  436. End If
  437. Screen.Mousepointer = 11
  438. On Error GoTo Printproblem
  439. Printer.FontBold = True
  440. Printer.CurrentX = LM
  441. Printer.CurrentY = TM
  442. PrintText = FirstPageHead + " - Page < " + Str$(Printer.Page) + " >"
  443. Printer.Print PrintText
  444. Printer.Print
  445. Printer.FontBold = False
  446. Totalprint = Len(Temp(0))
  447. Curpos = 1
  448. Lines = 1
  449. Segment = Space$(TextPrintWidth)
  450. Do While Curpos < Totalprint
  451.     Segment = Mid$(Temp(0), Curpos, TextPrintWidth)
  452.     Testpos = 1
  453.     TestChar = 13
  454.     Result% = MhFwdInstrChar%(Testpos, TestChar, Segment)
  455.     If Result% <> 0 Then
  456.     BreakPos = Result% + 1
  457.     PrtPos = Result% - 1
  458.     GoTo ReadytoPrint
  459.     End If
  460.     TestChar = 32
  461.     Result% = MhBkwdInstrChar%(TextPrintWidth, TestChar, Segment)
  462.     If Result% = 0 Then
  463.     BreakPos = TextPrintWidth
  464.     PrtPos = TextPrintWidth
  465.     Else
  466.     BreakPos = Result%
  467.     PrtPos = Result%
  468.     End If
  469. ReadytoPrint:
  470.     Ptext = Mid$(Segment, 1, PrtPos)
  471.     Printer.CurrentX = LM
  472.     Printer.Print LTrim$(Ptext)
  473.     Curpos = Curpos + BreakPos
  474.     Lines = Lines + 1
  475.     If Lines > MaxLines Then
  476.     Printer.NewPage
  477.     Printer.FontBold = True
  478.     Printer.CurrentX = LM
  479.     Printer.CurrentY = TM
  480.     PrintText = FirstPageHead + " - Page < " + Str$(Printer.Page) + " >"
  481.     Printer.Print PrintText
  482.     Printer.Print
  483.     Printer.FontBold = False
  484.     Lines = 1
  485.     End If
  486. Printer.EndDoc
  487. GoTo exitlabel
  488. Printproblem:
  489.     MsgBox "Print error: " + Error$
  490.     Resume Next
  491. exitlabel:
  492. Screen.Mousepointer = 0
  493. End Sub
  494. Sub saveasfilemenu_click ()
  495. '-----------------------------
  496. On Error Resume Next
  497. Dim EditFileTemp As String
  498. ReDim FileFilterType(1 To 5)  As MhFileFilterType
  499. FileFilterType(1).Description = "Text FIles (*.txt)"
  500. FileFilterType(1).Mask = "*.txt"
  501. FileFilterType(2).Description = "All Files(*.*)"
  502. FileFilterType(2).Mask = "*.*"
  503. FileFilterType(3).Description = "INI Files(*.ini)"
  504. FileFilterType(3).Mask = "*.ini"
  505. FileFilterType(4).Description = "System Files(*.sys)"
  506. FileFilterType(4).Mask = "*.sys"
  507. FileFilterType(5).Description = "Doc Files(*.doc;*.txt;*.bak"
  508. FileFilterType(5).Mask = "*.doc;*.txt;*.bak"
  509. GetFileType.FilterIndex = 1
  510. GetFileType.InitDir = "C:\"
  511. GetFileType.InitFileName = EditFileName
  512. GetFileType.DefaultExtension = "txt"
  513. GetFileType.HowManyFilters = UBound(FileFilterType)
  514. GetFileType.hWnd = 0
  515. EditFileTemp = MhGetSaveFileNAme$(GetFileType, FileFilterType(1))
  516. If EditFileTemp = "" And MhECode%() = 0 Then Exit Sub
  517. If EditFileTemp = "" And MhECode%() < 0 Then
  518.     MsgBox "Error # " + EditFileTemp + " Opening file"
  519.     Exit Sub
  520. End If
  521. Result% = MhFileExists%(EditFileTemp)
  522. If Result% = True Then
  523.     Check% = MsgBox("File already exists.  Replace?", 260, "File Warning")
  524.     If Check% = 7 Then Exit Sub
  525. End If
  526. EditFile = EditFileTemp
  527. EditFileName = MhGetFileTitle(EditFile)
  528. Form1.caption = "INOTEPAD - " + EditFileName
  529. On Error GoTo Filetrouble
  530. Open EditFile For Output As #1
  531. Print #1, Text1.Text,
  532. Close #1
  533. On Error GoTo 0
  534. Changed = False
  535. Exit Sub
  536. Filetrouble:
  537.     MsgBox "Could Not Save the File"
  538.     Resume Next
  539. End Sub
  540. Sub savefilemenu_click ()
  541. '--------------------------
  542. On Error GoTo Filesavetrouble
  543. If EditFile = "" Then
  544.     saveasfilemenu_click
  545.     Exit Sub
  546.     Open EditFile For Output As #1
  547.     Print #1, Text1.Text,
  548.     Close #1
  549. End If
  550. Changed = False
  551. Exit Sub
  552. Filesavetrouble:
  553.     MsgBox "Could Not Save the File"
  554.     Resume Next
  555. End Sub
  556. Sub searchbut_KeyDown (Keycode As Integer, Shift As Integer)
  557. '-------------------------------------------------------
  558. If Keycode = 255 Then
  559.     Replace$ = ""
  560.     Result% = MhGetTextDialog%(Replace$, DlgFlags, FindText)
  561.     If Result% <> 0 Then
  562.     MsgBox "Find Operation Failed"
  563.     Exit Sub
  564.     End If
  565.     StartPos = 1
  566.     Textfile(0) = Text1.Text
  567.     K = MhFwdInstrS%(StartPos, Textfile(0), FindText)
  568. '    k = InStr(StartPos, TextFile(0), FindText)
  569.     Text1.SelStart = K - 1
  570.     StartPos = K + Len(FindText)
  571.     MhKillDialog
  572.     End If
  573. End Sub
  574. Sub selectalleditmenu_Click ()
  575. '------------------------
  576. Text1.SelStart = 0
  577. Text1.SelLength = Len(RTrim$(Text1.Text))
  578. End Sub
  579. Sub stripcrlfmenu_Click ()
  580. '----------------------
  581. Dim Crlf As String
  582. Dim Spacer As String
  583. Dim Tp As String
  584. Spacer = Space$(1)
  585. Crlf = Chr$(13) + Chr$(10)
  586. Tp = Text1.SelText
  587. Text1.SelText = MhReplaceStr$(Count%, Tp, Crlf, Spacer)
  588. End Sub
  589. Sub Text1_Change ()
  590. '----------------------------------------
  591. Changed = True
  592. End Sub
  593. Sub Text1_Keyup (Keycode As Integer, Shift As Integer)
  594. If Keycode = 16 And Shift = 2 Then
  595.     Result% = MhPUTrack%((Form1.hWnd), PuHandle, 0, 200)
  596.     If Result% < 0 Then
  597.     MsgBox "Pop up Menu Execute Error"
  598.     Exit Sub
  599.     End If
  600.     If Result% = 0 Then Exit Sub
  601.     PuExecute Result%
  602. End If
  603. End Sub
  604. Sub undoeditmenu_Click ()
  605. '-------------------------
  606. 'MsgBox "NotYet Implemented"
  607. Text1.SetFocus
  608. retVal = SendMessage&(GetFocus(), EM_UNDO, 0, 0)
  609. End Sub
  610.