home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / 3d_tabs / iniview.frm < prev    next >
Text File  |  1994-06-02  |  14KB  |  513 lines

  1. VERSION 2.00
  2. Begin Form Iniviewer 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "IniViewer"
  6.    ClientHeight    =   3870
  7.    ClientLeft      =   330
  8.    ClientTop       =   825
  9.    ClientWidth     =   7095
  10.    Height          =   4560
  11.    Icon            =   INIVIEW.FRX:0000
  12.    Left            =   270
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   258
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   473
  18.    Top             =   195
  19.    Visible         =   0   'False
  20.    Width           =   7215
  21.    Begin PictureBox page 
  22.       Height          =   5580
  23.       Left            =   240
  24.       ScaleHeight     =   5550
  25.       ScaleWidth      =   8985
  26.       TabIndex        =   6
  27.       Top             =   720
  28.       Width           =   9015
  29.       Begin TextBox t 
  30.          FontBold        =   0   'False
  31.          FontItalic      =   0   'False
  32.          FontName        =   "MS Sans Serif"
  33.          FontSize        =   8.25
  34.          FontStrikethru  =   0   'False
  35.          FontUnderline   =   0   'False
  36.          Height          =   5300
  37.          HideSelection   =   0   'False
  38.          Index           =   1
  39.          Left            =   4485
  40.          MultiLine       =   -1  'True
  41.          ScrollBars      =   3  'Both
  42.          TabIndex        =   0
  43.          Top             =   255
  44.          Width           =   4530
  45.       End
  46.       Begin TextBox t 
  47.          FontBold        =   0   'False
  48.          FontItalic      =   0   'False
  49.          FontName        =   "MS Sans Serif"
  50.          FontSize        =   8.25
  51.          FontStrikethru  =   0   'False
  52.          FontUnderline   =   0   'False
  53.          ForeColor       =   &H00000000&
  54.          Height          =   5300
  55.          HideSelection   =   0   'False
  56.          Index           =   0
  57.          Left            =   0
  58.          MultiLine       =   -1  'True
  59.          ScrollBars      =   3  'Both
  60.          TabIndex        =   1
  61.          Top             =   255
  62.          Width           =   4500
  63.       End
  64.       Begin Label ttl 
  65.          BackColor       =   &H00C0C0C0&
  66.          BorderStyle     =   1  'Fixed Single
  67.          FontBold        =   0   'False
  68.          FontItalic      =   0   'False
  69.          FontName        =   "MS Sans Serif"
  70.          FontSize        =   8.25
  71.          FontStrikethru  =   0   'False
  72.          FontUnderline   =   0   'False
  73.          Height          =   255
  74.          Index           =   1
  75.          Left            =   4485
  76.          TabIndex        =   4
  77.          Top             =   0
  78.          Width           =   4530
  79.       End
  80.       Begin Label ttl 
  81.          BackColor       =   &H00C0C0C0&
  82.          BorderStyle     =   1  'Fixed Single
  83.          FontBold        =   0   'False
  84.          FontItalic      =   0   'False
  85.          FontName        =   "MS Sans Serif"
  86.          FontSize        =   8.25
  87.          FontStrikethru  =   0   'False
  88.          FontUnderline   =   0   'False
  89.          Height          =   255
  90.          Index           =   0
  91.          Left            =   0
  92.          TabIndex        =   5
  93.          Top             =   0
  94.          Width           =   4500
  95.       End
  96.    End
  97.    Begin PictureBox tabbox 
  98.       BackColor       =   &H00C0C0C0&
  99.       BorderStyle     =   0  'None
  100.       ClipControls    =   0   'False
  101.       Height          =   495
  102.       Left            =   0
  103.       ScaleHeight     =   33
  104.       ScaleMode       =   3  'Pixel
  105.       ScaleWidth      =   529
  106.       TabIndex        =   2
  107.       Top             =   0
  108.       Width           =   7935
  109.       Begin PictureBox invbox 
  110.          AutoRedraw      =   -1  'True
  111.          BackColor       =   &H00C0C0C0&
  112.          BorderStyle     =   0  'None
  113.          ClipControls    =   0   'False
  114.          Height          =   255
  115.          Left            =   1800
  116.          ScaleHeight     =   17
  117.          ScaleMode       =   3  'Pixel
  118.          ScaleWidth      =   81
  119.          TabIndex        =   3
  120.          Top             =   120
  121.          Visible         =   0   'False
  122.          Width           =   1215
  123.       End
  124.    End
  125.    Begin CommonDialog cd 
  126.       CancelError     =   -1  'True
  127.       DefaultExt      =   ".ini"
  128.       Filter          =   "All Files (*.*)|*.*|Ini Files (*.ini)|*.ini"
  129.       InitDir         =   "c:\"
  130.       Left            =   0
  131.       Top             =   360
  132.    End
  133.    Begin Menu zFile 
  134.       Caption         =   "&File"
  135.       Begin Menu zf 
  136.          Caption         =   "&Open..."
  137.          Index           =   1
  138.       End
  139.       Begin Menu zf 
  140.          Caption         =   "&Save"
  141.          Index           =   2
  142.       End
  143.       Begin Menu zf 
  144.          Caption         =   "Save &As..."
  145.          Index           =   3
  146.       End
  147.       Begin Menu zf 
  148.          Caption         =   "Backup Ini Files"
  149.          Index           =   4
  150.       End
  151.       Begin Menu zf 
  152.          Caption         =   "-"
  153.          Index           =   5
  154.       End
  155.       Begin Menu zf 
  156.          Caption         =   "E&xit"
  157.          Index           =   6
  158.       End
  159.       Begin Menu zi 
  160.          Caption         =   "-"
  161.          Index           =   0
  162.       End
  163.       Begin Menu zi 
  164.          Caption         =   "autoexec.bat"
  165.          Index           =   1
  166.          Shortcut        =   {F5}
  167.       End
  168.       Begin Menu zi 
  169.          Caption         =   "config.sys"
  170.          Index           =   2
  171.          Shortcut        =   {F6}
  172.       End
  173.       Begin Menu zi 
  174.          Caption         =   "system.ini"
  175.          Index           =   3
  176.          Shortcut        =   {F7}
  177.       End
  178.       Begin Menu zi 
  179.          Caption         =   "win.ini"
  180.          Index           =   4
  181.          Shortcut        =   {F8}
  182.       End
  183.    End
  184.    Begin Menu zedit 
  185.       Caption         =   "&Edit"
  186.       Begin Menu ze 
  187.          Caption         =   "Cu&t"
  188.          Index           =   0
  189.          Shortcut        =   ^X
  190.       End
  191.       Begin Menu ze 
  192.          Caption         =   "&Copy"
  193.          Index           =   1
  194.          Shortcut        =   ^C
  195.       End
  196.       Begin Menu ze 
  197.          Caption         =   "&Paste"
  198.          Index           =   2
  199.          Shortcut        =   ^V
  200.       End
  201.       Begin Menu ze 
  202.          Caption         =   "De&lete"
  203.          Index           =   3
  204.          Shortcut        =   {DEL}
  205.       End
  206.       Begin Menu ze 
  207.          Caption         =   "-"
  208.          Index           =   4
  209.       End
  210.       Begin Menu ze 
  211.          Caption         =   "Select &All"
  212.          Index           =   5
  213.       End
  214.       Begin Menu ze 
  215.          Caption         =   "-"
  216.          Index           =   6
  217.       End
  218.       Begin Menu ze 
  219.          Caption         =   "Time/&Date"
  220.          Index           =   7
  221.       End
  222.    End
  223.    Begin Menu zo 
  224.       Caption         =   "&Font"
  225.       Index           =   3
  226.       Begin Menu zFontName 
  227.          Caption         =   "FontName"
  228.          Index           =   0
  229.       End
  230.    End
  231. End
  232. Option Explicit
  233. Dim i%, r%, s$
  234. Dim dirty%(0 To 1)
  235. Dim inifile$(0 To 1)
  236. Dim tlines%(0 To 1)
  237. Dim showlist%
  238. 'tab
  239. Dim tb As TabData
  240. Dim captions$()
  241. Dim ftb As TabData
  242.  
  243. Sub BackupIni ()
  244. Dim f$
  245. screen.MousePointer = 11
  246. s$ = App.Path & "\backup"
  247. If Dir(s$, 16) = "" Then MkDir s$
  248. CopyFile "c:\autoexec.bat", "autoexec.xxx"
  249. CopyFile "c:\config.sys", "config.xxx"
  250. CopyFile "c:\windows\system.ini", "system.xxx"
  251. CopyFile "c:\windows\win.ini", "win.xxx"
  252. screen.MousePointer = 0
  253. End Sub
  254.  
  255. Sub CopyFile (Filename$, temp$)
  256. Dim fnum%, lng&, f$, t$
  257. On Error GoTo cerr
  258.     
  259. fnum = FreeFile ' get next handle number
  260. Open Filename$ For Binary As #fnum%
  261.     lng& = LOF(fnum)
  262.     s$ = String$(lng, " ")
  263.     Get #fnum%, , s$
  264. Close #fnum%
  265. fnum = FreeFile ' get next handle number
  266. f$ = App.Path & "\backup\" & temp$
  267. t$ = Dir(f$)
  268. If t$ <> "" Then
  269.     Kill f$
  270. End If
  271. Open f$ For Binary As #fnum%
  272.     Put #fnum, , s$
  273. Close #fnum
  274. Exit Sub
  275.  
  276. cerr:
  277. Close #fnum
  278. MsgBox "Error copying " & Filename$
  279. Exit Sub
  280. End Sub
  281.  
  282. Sub Form_Load ()
  283. crlf$ = Chr$(13) + Chr$(10)
  284. zFontName(0).Caption = screen.Fonts(0)
  285. For i = 1 To screen.FontCount - 1
  286.     Load zFontName(i)
  287.     zFontName(0).Caption = screen.Fonts(i)
  288. Next
  289. Initialize
  290. iniviewer.Show
  291. zi_click 1
  292. End Sub
  293.  
  294. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  295. Dim msg, Filename
  296. Dim response As Integer
  297. For i = 0 To 1
  298. If dirty(i) Then
  299.     Filename = inifile(i)
  300.     msg = "The text in [" & Filename & "] has changed."
  301.     msg = msg & crlf$
  302.     msg = msg & "Do you want to save the changes?"
  303.     r = MsgBox(msg, 51, "IniViewer")
  304.     Select Case r
  305.     ' Yes
  306.     Case 6
  307.     Filename = GetFName(2)
  308.     'If the user did notspecify a file name,
  309.     'cancel the unload; otherwise, save it.
  310.     If Filename = "" Then
  311.     Cancel = True
  312.     Else
  313.     SaveFileAs (Filename)
  314.     End If
  315.     ' User selects No
  316.     ' Ok to unload
  317.     Case 7
  318.     GoTo skip
  319.     ' User selects Cancel
  320.     ' Cancel the unload
  321.     Case 2
  322.     Cancel = True
  323.     Exit For
  324.     End Select
  325. skip:
  326. End If
  327. Next
  328. End Sub
  329.  
  330. Function GetFName (n%)
  331. On Error Resume Next
  332.     cd.Action = n%
  333.     If Err <> 32755 Then      'User cancelled dialog
  334.     GetFName = cd.Filename
  335.     Else
  336.     GetFName = ""
  337.     End If
  338. End Function
  339.  
  340. Sub Initialize ()
  341. '===create an array of controls=======
  342. ReDim captions(0 To 3)
  343. captions(0) = "autoexec.bat"
  344. captions(1) = "config.sys"
  345. captions(2) = "system.ini"
  346. captions(3) = "win.ini"
  347. '===fill in the fields of the struct=====================
  348. tb.num = 3              'number of tabs
  349. tb.active = 0           'initial focus
  350. tb.cols = 4             'number of tabs in each row
  351. tb.insetx = 4
  352. tb.insety = 4
  353. DefineControl Me, tabbox, invbox, page, tb
  354. End Sub
  355.  
  356. Sub OpenIniFile (f$, ndx%)
  357. Dim fnum%, lng&
  358. 'If lbox.Visible Then zb_click 13
  359. On Error GoTo ierr
  360.     
  361. fnum = FreeFile ' get next handle number
  362. Open f$ For Binary As #fnum%
  363.     lng& = LOF(fnum)
  364.     s$ = String$(lng, " ")
  365.     Get #fnum%, , s$
  366. Close #fnum%
  367. t(ndx%) = s$
  368. tlines(ndx) = SendMessage(t(ndx).hWnd, EM_GETLINECOUNT, 0, 0&)
  369. ttl(ndx%) = Format(tlines(ndx), "@@@@") & " : " & LCase(f$)
  370. dirty(ndx%) = 0
  371. Exit Sub
  372.  
  373. ierr:
  374. MsgBox "Can't open " & f$
  375. Exit Sub
  376. End Sub
  377.  
  378. Sub SaveFileAs (Filename)
  379. On Error Resume Next
  380. s = Dir(Filename)
  381. If s <> "" Then
  382.     If MsgBox("[" & UCase(Filename) & "]" & "already exists." & crlf & crlf & " Overwrite?", 36, "INIVIEWER") <> 6 Then Exit Sub
  383. End If
  384. Open Filename For Output As #1
  385. s = t(active)
  386. screen.MousePointer = 11
  387. Print #1, s
  388. Close #1
  389. screen.MousePointer = 0
  390. If Err Then MsgBox Error, 48, App.Title
  391. End Sub
  392.  
  393. Sub t_Change (Index As Integer)
  394. dirty(Index) = True
  395. End Sub
  396.  
  397. Sub t_GotFocus (Index As Integer)
  398. Dim other%
  399. active = Index
  400. If active = 0 Then other = 1
  401. t(active).ForeColor = QBColor(0)'black
  402. t(other).ForeColor = QBColor(8)
  403. End Sub
  404.  
  405. Sub tabbox_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  406. TabClick Button, X, Y, tabbox, captions(), tb
  407. zi_click tb.active + 1
  408. t(0).SetFocus
  409. End Sub
  410.  
  411. Sub tabbox_Paint ()
  412. DrawText tabbox, captions(), tb
  413. End Sub
  414.  
  415. Sub ttl_Click (Index As Integer)
  416. 'caption labels for the files
  417. End Sub
  418.  
  419. Sub ze_click (Index As Integer) 'edit
  420. Select Case Index
  421. Case 0
  422.     ClipBoard.SetText t(active).SelText
  423.     t(active).SelText = ""
  424. Case 1
  425.     ClipBoard.SetText t(active).SelText
  426. Case 2
  427.     t(active).SelText = ClipBoard.GetText()
  428. Case 3
  429.   If t(active).SelStart <> Len(t(active).Text) Then
  430.     ' If nothing is selected, extend selection by one.
  431.     If t(active).SelLength = 0 Then
  432.       t(active).SelLength = 1
  433.       ' If cursor is on a blank line, extend selection by two.
  434.       If Asc(t(active).SelText) = 13 Then
  435.     t(active).SelLength = 2
  436.       End If
  437.     End If
  438.     ' Delete selected text.
  439.     t(active).SelText = ""
  440.   End If
  441. Case 5
  442.     t(active).SelStart = 0
  443.     t(active).SelLength = Len(t(active).Text)
  444. Case 7
  445. t(active).SelStart = 0: t(active).SelLength = 0
  446. If Right$(t(active).Tag, 3) = "ini" Then
  447.     s = "; "
  448. Else
  449.     s = "REM "
  450. End If
  451. t(active).SelText = s & Now & crlf$
  452. End Select
  453. End Sub
  454.  
  455. Sub zf_click (Index As Integer)
  456. Select Case Index
  457. Case 1'open
  458.     s = GetFName(1)
  459.     If s$ <> "" Then
  460.     t(active).Tag = s$
  461.     OpenIniFile s$, active
  462.     End If
  463. Case 2'save
  464.     s = t(active).Tag
  465.     If s = "" Then Beep: Exit Sub
  466.     If Not dirty(active) Then MsgBox "[" & UCase(s$) & "]" & crlf$ & crlf$ & "is up to date.", , "INIVIEWER": Exit Sub
  467.     If s$ <> "" Then SaveFileAs (s$)
  468. Case 3'saveas
  469.     s = t(active).Tag
  470.     If s = "" Then Beep: Exit Sub
  471.     cd.Filename = s
  472.     s = GetFName(2)
  473.     If s <> "" Then
  474.     t(active).Tag = s
  475.     SaveFileAs (s)
  476.     End If
  477. Case 4
  478.     BackupIni
  479. Case 6'exit
  480. Unload Me
  481. End Select
  482. End Sub
  483.  
  484. Sub zFontName_Click (Index As Integer)
  485. For i = 0 To 1
  486.     t(i).FontName = zFontName(Index).Caption
  487. Next
  488. End Sub
  489.  
  490. Sub zi_click (Index As Integer)
  491. Select Case Index
  492. Case 1
  493.     t(0).Tag = "c:\autoexec.bat"
  494.     t(1).Tag = App.Path & "\backup\autoexec.xxx"
  495. Case 2
  496.     t(0).Tag = "c:\config.sys"
  497.     t(1).Tag = App.Path & "\backup\config.xxx"
  498. Case 3
  499.     t(0).Tag = "c:\windows\system.ini"
  500.     t(1).Tag = App.Path & "\backup\system.xxx"
  501. Case 4
  502.     t(0).Tag = "c:\windows\win.ini"
  503.     t(1).Tag = App.Path & "\backup\win.xxx"
  504. End Select
  505. OpenIniFile CStr(t(0).Tag), 0
  506. OpenIniFile CStr(t(1).Tag), 1
  507. t(0).SetFocus
  508. End Sub
  509.  
  510. Sub zo_click (Index As Integer) 'font
  511. End Sub
  512.  
  513.