home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 44 / IOPROG_44.ISO / soft / c++ / NCTDataCompress.exe / Main / frmDialog.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-12-19  |  14.7 KB  |  458 lines

  1. VERSION 5.00
  2. Object = "{EF6969B1-01FE-4CE1-A234-66D7A60863F2}#1.0#0"; "NCTDataCompress.dll"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  5. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
  6. Begin VB.Form frmDialog 
  7.    Caption         =   "Test VB 6.0 NCTDataCompress ActiveX Control"
  8.    ClientHeight    =   3285
  9.    ClientLeft      =   60
  10.    ClientTop       =   345
  11.    ClientWidth     =   5295
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3285
  16.    ScaleWidth      =   5295
  17.    StartUpPosition =   2  'CenterScreen
  18.    Begin MSComctlLib.ProgressBar ProgressBar1 
  19.       Height          =   195
  20.       Left            =   0
  21.       TabIndex        =   24
  22.       Top             =   3060
  23.       Width           =   5235
  24.       _ExtentX        =   9234
  25.       _ExtentY        =   344
  26.       _Version        =   393216
  27.       Appearance      =   1
  28.    End
  29.    Begin VB.TextBox Text7 
  30.       Alignment       =   1  'Right Justify
  31.       Height          =   315
  32.       Left            =   3780
  33.       TabIndex        =   23
  34.       Text            =   "5"
  35.       Top             =   2160
  36.       Width           =   435
  37.    End
  38.    Begin MSComCtl2.UpDown UpDown4 
  39.       Height          =   315
  40.       Left            =   4200
  41.       TabIndex        =   22
  42.       Top             =   2160
  43.       Width           =   240
  44.       _ExtentX        =   423
  45.       _ExtentY        =   556
  46.       _Version        =   393216
  47.       Value           =   5
  48.       BuddyControl    =   "Text7"
  49.       BuddyDispid     =   196609
  50.       OrigLeft        =   4980
  51.       OrigTop         =   1860
  52.       OrigRight       =   5220
  53.       OrigBottom      =   2295
  54.       Max             =   12
  55.       Min             =   1
  56.       SyncBuddy       =   -1  'True
  57.       BuddyProperty   =   65547
  58.       Enabled         =   -1  'True
  59.    End
  60.    Begin MSComCtl2.UpDown UpDown3 
  61.       Height          =   315
  62.       Left            =   2415
  63.       TabIndex        =   21
  64.       Top             =   2160
  65.       Width           =   240
  66.       _ExtentX        =   423
  67.       _ExtentY        =   556
  68.       _Version        =   393216
  69.       Value           =   10
  70.       BuddyControl    =   "Text6"
  71.       BuddyDispid     =   196610
  72.       OrigLeft        =   2520
  73.       OrigTop         =   2340
  74.       OrigRight       =   2760
  75.       OrigBottom      =   2655
  76.       Max             =   40
  77.       Min             =   4
  78.       SyncBuddy       =   -1  'True
  79.       BuddyProperty   =   65547
  80.       Enabled         =   -1  'True
  81.    End
  82.    Begin VB.TextBox Text6 
  83.       Alignment       =   1  'Right Justify
  84.       Height          =   315
  85.       Left            =   1620
  86.       TabIndex        =   20
  87.       Text            =   "10"
  88.       Top             =   2160
  89.       Width           =   795
  90.    End
  91.    Begin VB.OptionButton Option2 
  92.       Caption         =   "BWT"
  93.       Height          =   255
  94.       Left            =   2460
  95.       TabIndex        =   17
  96.       Top             =   1440
  97.       Width           =   795
  98.    End
  99.    Begin VB.OptionButton Option1 
  100.       Caption         =   "PPM"
  101.       Height          =   255
  102.       Left            =   1620
  103.       TabIndex        =   16
  104.       Top             =   1440
  105.       Value           =   -1  'True
  106.       Width           =   795
  107.    End
  108.    Begin VB.TextBox Text5 
  109.       Alignment       =   1  'Right Justify
  110.       Height          =   315
  111.       Left            =   3780
  112.       Locked          =   -1  'True
  113.       TabIndex        =   13
  114.       Text            =   "1"
  115.       Top             =   1800
  116.       Width           =   435
  117.    End
  118.    Begin MSComCtl2.UpDown UpDown2 
  119.       Height          =   315
  120.       Left            =   4200
  121.       TabIndex        =   14
  122.       Top             =   1800
  123.       Width           =   240
  124.       _ExtentX        =   423
  125.       _ExtentY        =   556
  126.       _Version        =   393216
  127.       Value           =   1
  128.       BuddyControl    =   "Text5"
  129.       BuddyDispid     =   196613
  130.       OrigLeft        =   4380
  131.       OrigTop         =   1440
  132.       OrigRight       =   4620
  133.       OrigBottom      =   1785
  134.       Max             =   65535
  135.       Min             =   1
  136.       SyncBuddy       =   -1  'True
  137.       BuddyProperty   =   65547
  138.       Enabled         =   -1  'True
  139.    End
  140.    Begin VB.TextBox Text4 
  141.       Alignment       =   1  'Right Justify
  142.       Height          =   315
  143.       Left            =   1620
  144.       Locked          =   -1  'True
  145.       TabIndex        =   10
  146.       Text            =   "1024"
  147.       Top             =   1800
  148.       Width           =   795
  149.    End
  150.    Begin MSComCtl2.UpDown UpDown1 
  151.       Height          =   315
  152.       Left            =   2415
  153.       TabIndex        =   9
  154.       Top             =   1800
  155.       Width           =   240
  156.       _ExtentX        =   423
  157.       _ExtentY        =   556
  158.       _Version        =   393216
  159.       Value           =   1024
  160.       BuddyControl    =   "Text4"
  161.       BuddyDispid     =   196614
  162.       OrigLeft        =   2580
  163.       OrigTop         =   1320
  164.       OrigRight       =   2820
  165.       OrigBottom      =   1605
  166.       Increment       =   10
  167.       Max             =   4096
  168.       SyncBuddy       =   -1  'True
  169.       BuddyProperty   =   65547
  170.       Enabled         =   -1  'True
  171.    End
  172.    Begin VB.TextBox Text3 
  173.       Height          =   345
  174.       Left            =   1620
  175.       TabIndex        =   7
  176.       Top             =   960
  177.       Width           =   3075
  178.    End
  179.    Begin MSComDlg.CommonDialog CommonDialog1 
  180.       Left            =   4680
  181.       Top             =   1440
  182.       _ExtentX        =   847
  183.       _ExtentY        =   847
  184.       _Version        =   393216
  185.    End
  186.    Begin VB.CommandButton UncompressButton 
  187.       Caption         =   "Uncompress"
  188.       Height          =   375
  189.       Left            =   2700
  190.       TabIndex        =   6
  191.       Top             =   2580
  192.       Width           =   2055
  193.    End
  194.    Begin VB.CommandButton CompressButton 
  195.       Caption         =   "Compress"
  196.       Height          =   375
  197.       Left            =   540
  198.       TabIndex        =   5
  199.       Top             =   2580
  200.       Width           =   2055
  201.    End
  202.    Begin VB.CommandButton Button1 
  203.       Caption         =   "..."
  204.       Height          =   315
  205.       Left            =   4800
  206.       TabIndex        =   4
  207.       Top             =   120
  208.       Width           =   315
  209.    End
  210.    Begin VB.TextBox Text2 
  211.       Height          =   345
  212.       Left            =   1620
  213.       TabIndex        =   3
  214.       Top             =   540
  215.       Width           =   3075
  216.    End
  217.    Begin VB.TextBox Text1 
  218.       Height          =   345
  219.       Left            =   1620
  220.       TabIndex        =   0
  221.       Text            =   "Enter input file"
  222.       Top             =   120
  223.       Width           =   3075
  224.    End
  225.    Begin VB.Label Label8 
  226.       Caption         =   "PPMMemSize (mB):"
  227.       Height          =   255
  228.       Left            =   60
  229.       TabIndex        =   19
  230.       Top             =   2220
  231.       Width           =   1455
  232.    End
  233.    Begin VB.Label Label7 
  234.       Caption         =   "PPMOrder:"
  235.       Height          =   255
  236.       Left            =   2820
  237.       TabIndex        =   18
  238.       Top             =   2220
  239.       Width           =   915
  240.    End
  241.    Begin VB.Label Label6 
  242.       Caption         =   "Algorithm:"
  243.       Height          =   285
  244.       Left            =   60
  245.       TabIndex        =   15
  246.       Top             =   1440
  247.       Width           =   1155
  248.    End
  249.    Begin VB.Label Label5 
  250.       Caption         =   "Reorder:"
  251.       Height          =   285
  252.       Left            =   2820
  253.       TabIndex        =   12
  254.       Top             =   1860
  255.       Width           =   735
  256.    End
  257.    Begin VB.Label Label4 
  258.       Caption         =   "Buffer size (kB) :"
  259.       Height          =   285
  260.       Left            =   60
  261.       TabIndex        =   11
  262.       Top             =   1860
  263.       Width           =   1395
  264.    End
  265.    Begin VB.Label Label3 
  266.       Caption         =   "Original file:"
  267.       Height          =   255
  268.       Left            =   60
  269.       TabIndex        =   8
  270.       Top             =   180
  271.       Width           =   1395
  272.    End
  273.    Begin VB.Label Label2 
  274.       Caption         =   "Compressed file:"
  275.       Height          =   285
  276.       Left            =   60
  277.       TabIndex        =   2
  278.       Top             =   600
  279.       Width           =   1395
  280.    End
  281.    Begin VB.Label Label1 
  282.       Caption         =   "Uncompressed file:"
  283.       Height          =   285
  284.       Left            =   60
  285.       TabIndex        =   1
  286.       Top             =   1020
  287.       Width           =   1395
  288.    End
  289.    Begin NCTDATACOMPRESSLibCtl.DataCompress DataCompress1 
  290.       Left            =   1800
  291.       OleObjectBlob   =   "frmDialog.frx":0000
  292.       Top             =   2520
  293.    End
  294. Attribute VB_Name = "frmDialog"
  295. Attribute VB_GlobalNameSpace = False
  296. Attribute VB_Creatable = False
  297. Attribute VB_PredeclaredId = True
  298. Attribute VB_Exposed = False
  299. Dim T1 As Double
  300. Dim T2 As Double
  301. Dim InputDir As String
  302. Dim OutputDir As String
  303. Dim byteArray() As Byte
  304. Private Sub Form_Load()
  305.     InputDir = GetSetting("NCT", "TestNCTDataCompress", "InputDir", "c:\")
  306.     OutputDir = GetSetting("NCT", "TestNCTDataCompress", "OutputDir", "c:\")
  307. End Sub
  308. Private Sub Button1_Click()
  309.     Dim sFile As String
  310.     With CommonDialog1
  311.         .FileName = ""
  312.         .InitDir = InputDir
  313.         .DialogTitle = "Open"
  314.         .CancelError = False
  315.         .Filter = "All files (*.*)|*.*"
  316.         .ShowOpen
  317.         If Len(.FileName) = 0 Then Exit Sub
  318.         sFile = .FileName
  319.     End With
  320.     CurDir CommonDialog1.FileName
  321.     InputDir = CurDir
  322.     SaveSetting "NCT", "TestNCTDataCompress", "InputDir", InputDir
  323.     Text1.Text = sFile
  324.     Dim fs As Variant
  325.     Set fs = CreateObject("Scripting.FileSystemObject")
  326.     Text2.Text = fs.GetParentFolderName(sFile) + "\" + fs.GetBaseName(sFile) + ".enc"
  327.     Text3.Text = fs.GetParentFolderName(sFile) + "\" + fs.GetBaseName(sFile) + ".dec"
  328. End Sub
  329. Private Sub CompressButton_Click()
  330.     Dim tmpArray(3) As Byte
  331.     Dim inpSize As Long
  332.     Dim outSize As Long
  333.     Dim bufSize As Long
  334.     Dim tmpSize As Long
  335.     Dim curPos As Long
  336.     Dim Ratio As Double
  337.     Dim CRCCode As Long
  338.     If Dir(Text1.Text) = "" Then
  339.         MsgBox "Invalid file name: " & Text1.Text, vbCritical
  340.         Exit Sub
  341.     End If
  342.     ProgressBar1.Value = 0
  343.     bufSize = UpDown1.Value * 1024
  344.     curPos = 0
  345.     outSize = 0
  346.     If Option1.Value = True Then DataCompress1.Algorithm = 1
  347.     If Option2.Value = True Then DataCompress1.Algorithm = 2
  348.     DataCompress1.Reorder = UpDown2.Value
  349.     DataCompress1.PPMMemSize = UpDown3.Value
  350.     DataCompress1.PPMOrder = UpDown4.Value
  351.     T1 = Now
  352.     inpSize = DataCompress1.OpenInputFile(Text1.Text)
  353.     DataCompress1.CreateOutputFile Text2.Text
  354.     tmpArray(0) = DataCompress1.Algorithm
  355.     tmpArray(1) = DataCompress1.Reorder
  356.     tmpArray(2) = DataCompress1.PPMMemSize
  357.     tmpArray(3) = DataCompress1.PPMOrder
  358.     DataCompress1.WriteOutputFile tmpArray()
  359.     outSize = outSize + 4
  360.     Do While curPos < inpSize
  361.         If (inpSize - curPos) < bufSize Then bufSize = inpSize - curPos
  362.         
  363.         byteArray() = DataCompress1.ReadInputFile(curPos, bufSize)
  364.         
  365.         CRCCode = Abs(DataCompress1.GetCRCCodeArray(byteArray()))
  366.         
  367.         byteArray() = DataCompress1.CompressByteArray(byteArray())
  368.         tmpSize = DataCompress1.GetArraySize(byteArray())
  369.         
  370.         WriteLong CRCCode
  371.         WriteLong tmpSize
  372.         DataCompress1.WriteOutputFile byteArray()
  373.         
  374.         curPos = curPos + bufSize
  375.         outSize = outSize + tmpSize + 8
  376.         
  377.     Loop
  378.     DataCompress1.CloseOutputFile
  379.     DataCompress1.CloseInputFile
  380.     T2 = Now
  381.     ProgressBar1.Value = 0
  382.     Ratio = (inpSize - outSize) / inpSize
  383.     MsgBox "Input size: " & inpSize & ". Packed size: " & outSize & ". Compression ratio: " & Format(Ratio, "#0.00%") & ". Time: " & Format((T2 - T1) * 100000, "#0.000") & " sec", vbInformation, "Compression result"
  384. End Sub
  385. Private Sub UncompressButton_Click()
  386.     Dim tmpArray() As Byte
  387.     Dim inpSize As Long
  388.     Dim outSize As Long
  389.     Dim tmpSize As Long
  390.     Dim Ratio As Double
  391.     Dim CRCCode As Long
  392.     If Dir(Text2.Text) = "" Or Len(Text2.Text) = 0 Then
  393.         MsgBox "Invalid file name: " & Text2.Text, vbCritical
  394.         Exit Sub
  395.     End If
  396.     ProgressBar1.Value = 0
  397.     curPos = 0
  398.     outSize = 0
  399.     T1 = Now
  400.     inpSize = DataCompress1.OpenInputFile(Text2.Text)
  401.     DataCompress1.CreateOutputFile Text3.Text
  402.     tmpArray() = DataCompress1.ReadInputFile(curPos, 4)
  403.     DataCompress1.Algorithm = tmpArray(0)
  404.     DataCompress1.Reorder = tmpArray(1)
  405.     DataCompress1.PPMMemSize = tmpArray(2)
  406.     DataCompress1.PPMOrder = tmpArray(3)
  407.     curPos = curPos + 4
  408.     Do While curPos < inpSize
  409.         CRCCode = ReadLong(curPos)
  410.         curPos = curPos + 4
  411.         tmpSize = ReadLong(curPos)
  412.         curPos = curPos + 4
  413.         
  414.         byteArray() = DataCompress1.ReadInputFile(curPos, tmpSize)
  415.         curPos = curPos + tmpSize
  416.         
  417.         byteArray() = DataCompress1.DecompressByteArray(byteArray())
  418.        
  419.         If CRCCode <> Abs(DataCompress1.GetCRCCodeArray(byteArray())) Then
  420.             MsgBox "Error input data. Operation canceled!", vbCritical, "Error"
  421.             Exit Do
  422.         End If
  423.         
  424.         outSize = outSize + DataCompress1.GetArraySize(byteArray())
  425.         DataCompress1.WriteOutputFile byteArray()
  426.     Loop
  427.     DataCompress1.CloseOutputFile
  428.     DataCompress1.CloseInputFile
  429.     T2 = Now
  430.     ProgressBar1.Value = 0
  431.     Ratio = (outSize - inpSize) / outSize
  432.     MsgBox "Output size: " & outSize & ". Packed size: " & inpSize & ". Compression ratio: " & Format(Ratio, "#0.00%") & ". Time: " & Format((T2 - T1) * 100000, "#0.000") & " sec", vbInformation, "Compression result"
  433. End Sub
  434. Private Sub WriteLong(ByVal L As Long)
  435.     Dim tmpArray(3) As Byte
  436.     Dim i As Long
  437.     For i = 0 To 3
  438.         tmpArray(i) = L Mod 256
  439.         L = (L - L Mod 256) / 256
  440.     Next i
  441.     DataCompress1.WriteOutputFile tmpArray()
  442. End Sub
  443. Private Function ReadLong(ByVal curPos As Long) As Long
  444.     Dim tmpArray() As Byte
  445.     tmpArray() = DataCompress1.ReadInputFile(curPos, 4)
  446.     ReadLong = 0
  447.     For i = 3 To 0 Step -1
  448.         ReadLong = ReadLong * 256
  449.         ReadLong = tmpArray(i) + ReadLong
  450.     Next i
  451. End Function
  452. Private Sub DataCompress1_CompressBlock(ByVal Percent As Long)
  453.      ProgressBar1.Value = Percent
  454. End Sub
  455. Private Sub DataCompress1_DecompressBlock(ByVal Percent As Long)
  456.      ProgressBar1.Value = Percent
  457. End Sub
  458.