⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 压缩算法测试程序(北理计算机系老浪字做)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include   <dos.h>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "A0Lib_OCX"
#pragma link "A1Lib_OCX"
#pragma link "HUFCTRLLib_OCX"
#pragma link "HUFDYNAMICAUTOSENSELib_OCX"
#pragma link "HUFDYNAMICGLOBALLib_OCX"
#pragma link "HUFSTATICLib_OCX"
#pragma link "LZWLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    this->RadioButton1->Checked = true;
    this->RadioButton1->OnClick;
    this->RadioButton3->Checked =true;
    this->RadioButton3->OnClick;
    this->RadioButton6->Checked =true;
    this->RadioButton6->OnClick;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
    Form1->OpenDialog1->Filter = "文本文件 (*.txt)|*.TXT|word文档 (*.doc)|*.DOC|图象文件 (*.bmp;*.jpeg;*.gif)|*.BMP;*.JPEG;*.GIF|所有文件 (*.*)|*.*";
    Form1->SaveDialog1->Filter = "压缩文件 (*.cpr)|*.CPR|所有文件 (*.*)|*.*";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    OpenDialog1->Title = "源文件";
    if(OpenDialog1->Execute())
    {
        Form1->Edit1->Text = OpenDialog1->FileName;
    };         
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
    SaveDialog1->Title ="目标文件";
    if (SaveDialog1->Execute())
    {
        Form1->Edit2->Text = SaveDialog1->FileName;
        if(Form1->RadioButton1->Checked)
        {
            Form1->Edit2->Text = ChangeFileExt(Form1->Edit2->Text,".cpr");
        }
    }        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
    Form1->OpenDialog1->Filter = "压缩文件 (*.cpr)|*.CPR|所有文件 (*.*)|*.*";
    Form1->SaveDialog1->Filter = "所有文件 (*.*)|*.*";
}
//---------------------------------------------------------------------------



void __fastcall TForm1::RadioButton7Click(TObject *Sender)
{
        this->RadioButton6->Enabled =true;
        this->RadioButton9->Enabled =true;
        this->GroupBox3->Enabled =true;
        this->RadioButton6->Checked =true;
        this->RadioButton6->OnClick;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::RadioButton9Click(TObject *Sender)
{
        this->Edit3->Enabled =true;
        this->Label3->Enabled =true;
        this->Hufdynamicautosense1->AutoSelectStep = false;
        this->Hufdynamicglobal1->AutoSelectStep =false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioButton6Click(TObject *Sender)
{
        this->Edit3->Enabled =false;
        this->Label3->Enabled =false;
        this->Hufdynamicautosense1->AutoSelectStep = true;
        this->Hufdynamicglobal1->AutoSelectStep =true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioButton8Click(TObject *Sender)
{
        this->RadioButton6->Enabled =true;
        this->RadioButton9->Enabled =true;
        this->GroupBox3->Enabled =true;
        this->RadioButton6->Checked =true;
        this->RadioButton6->OnClick;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioButton3Click(TObject *Sender)
{
        this->RadioButton6->Enabled =false;
        this->RadioButton9->Enabled =false;
        this->GroupBox3->Enabled =false;
        this->Edit3->Enabled =false;
        this->Label3->Enabled =false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioButton5Click(TObject *Sender)
{
        this->RadioButton6->Enabled =false;
        this->RadioButton9->Enabled =false;
        this->GroupBox3->Enabled =false;
        this->Edit3->Enabled =false;
        this->Label3->Enabled =false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioButton4Click(TObject *Sender)
{
        this->RadioButton6->Enabled =false;
        this->RadioButton9->Enabled =false;
        this->GroupBox3->Enabled =false;
        this->Edit3->Enabled =false;
        this->Label3->Enabled =false;
}
//---------------------------------------------------------------------------



void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int flag;
    long scrlen,dstlen,time_used;
    double ratio;
    struct  time t,priocomp,aftercomp;
    AnsiString scrfile,dstfile,tempstr; 
    if (Form1->RadioButton1->Checked)
    {
        if(!FileExists(Form1->Edit1->Text))
        {
                ShowMessage("源文件不存在!");
                return;
        }
        if(FileExists(Form1->Edit2->Text))
        {
                flag=Application->MessageBox("目标文件已存在!替换它吗?", "警告!",MB_OKCANCEL);
                if(flag==IDCANCEL)
                {
                ShowMessage("操作取消!压缩未完成!");
                return;
                }
        }
        if(Form1->RadioButton3->Checked)
        {
            Form1->Lzss1->sourcefile =Form1->Edit1->Text;
            Lzss1->destfile =Form1->Edit2->Text;
            gettime(&priocomp);
            flag=Lzss1->compress();
            gettime(&aftercomp);
            scrfile = Lzss1->sourcefile;
            dstfile = Lzss1->destfile ;
        }
        else
            {
            if(Form1->RadioButton4->Checked)
            {
                Form1->Hufctrl1->Sourcefile =Form1->Edit1->Text;
                Hufctrl1->Destfile =Form1->Edit2->Text;
                gettime(&priocomp);
                flag=Hufctrl1->compress();
                gettime(&aftercomp);
                scrfile = Hufctrl1->Sourcefile;
                dstfile = Hufctrl1->Destfile;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -