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

📄 form1.h

📁 《VC++2005编程实例》第三章的源代码
💻 H
字号:
#pragma once


namespace Example {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	using namespace System::IO;
	using namespace System::IO::Compression;

	/// <summary>
	/// Form1 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::GroupBox^  groupBox1;
	protected: 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::TextBox^  textBox2;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::GroupBox^  groupBox2;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::TextBox^  textBox4;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::Label^  label3;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->textBox4 = (gcnew System::Windows::Forms::TextBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->groupBox1->SuspendLayout();
			this->groupBox2->SuspendLayout();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->button2);
			this->groupBox1->Controls->Add(this->textBox2);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->button1);
			this->groupBox1->Controls->Add(this->textBox1);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Location = System::Drawing::Point(13, 13);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(365, 85);
			this->groupBox1->TabIndex = 0;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"压缩文件";
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(286, 47);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(75, 23);
			this->button2->TabIndex = 5;
			this->button2->Text = L"压缩文件";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// textBox2
			// 
			this->textBox2->Location = System::Drawing::Point(94, 47);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(186, 21);
			this->textBox2->TabIndex = 4;
			this->textBox2->Text = L"C:\\luobinCompressed.zip";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(6, 52);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(89, 12);
			this->label2->TabIndex = 3;
			this->label2->Text = L"压缩后文件名:";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(286, 20);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 2;
			this->button1->Text = L"浏览文件";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(94, 20);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(186, 21);
			this->textBox1->TabIndex = 1;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(6, 25);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(89, 12);
			this->label1->TabIndex = 0;
			this->label1->Text = L"未压缩文件名:";
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->button4);
			this->groupBox2->Controls->Add(this->textBox4);
			this->groupBox2->Controls->Add(this->label4);
			this->groupBox2->Controls->Add(this->button3);
			this->groupBox2->Controls->Add(this->textBox3);
			this->groupBox2->Controls->Add(this->label3);
			this->groupBox2->Location = System::Drawing::Point(13, 105);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(365, 83);
			this->groupBox2->TabIndex = 1;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"解压文件";
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(286, 47);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(75, 23);
			this->button4->TabIndex = 5;
			this->button4->Text = L"解压文件";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// textBox4
			// 
			this->textBox4->Location = System::Drawing::Point(103, 47);
			this->textBox4->Name = L"textBox4";
			this->textBox4->Size = System::Drawing::Size(177, 21);
			this->textBox4->TabIndex = 4;
			this->textBox4->Text = L"C:\\luobinUnCompressed.mdb";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(7, 52);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(89, 12);
			this->label4->TabIndex = 3;
			this->label4->Text = L"解压后文件名:";
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(286, 20);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(75, 23);
			this->button3->TabIndex = 2;
			this->button3->Text = L"浏览文件";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// textBox3
			// 
			this->textBox3->Location = System::Drawing::Point(103, 20);
			this->textBox3->Name = L"textBox3";
			this->textBox3->Size = System::Drawing::Size(177, 21);
			this->textBox3->TabIndex = 1;
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(7, 25);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(89, 12);
			this->label3->TabIndex = 0;
			this->label3->Text = L"未解压文件名:";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(390, 199);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Name = L"Form1";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"演示压缩和解压缩大尺寸文件";
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->groupBox2->ResumeLayout(false);
			this->groupBox2->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion
	//浏览文件(压缩)
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			OpenFileDialog^ MyDlg = gcnew OpenFileDialog();
			if (MyDlg->ShowDialog() == System::Windows::Forms::DialogResult::OK)
			{
				this->textBox1->Text = MyDlg->FileName;
			}
		}
	   //压缩文件
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			String^ MyInFile = this->textBox1->Text;
			if (!File::Exists(MyInFile))
			{
				MessageBox::Show(MyInFile+"文件不存在!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
			String^ MyOutFile = this->textBox2->Text;
			try
			{
				FileStream^ MyInStream=gcnew FileStream(MyInFile, FileMode::Open, FileAccess::Read, FileShare::Read);
				array<unsigned char>^  MyBuffer = gcnew array<unsigned char>(MyInStream->Length);
				int MyCount = MyInStream->Read(MyBuffer, 0, MyBuffer->Length);
				MyInStream->Close();
				FileStream^ MyOutStream = gcnew FileStream(MyOutFile, FileMode::OpenOrCreate, FileAccess::Write);
				GZipStream^ MyCompressedzipStream = gcnew GZipStream(MyOutStream, CompressionMode::Compress, true);
				MyCompressedzipStream->Write(MyBuffer, 0, MyBuffer->Length);
				MyCompressedzipStream->Close();
				MyOutStream->Close();
				MessageBox::Show("成功压缩文件:"+MyInFile, "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
			catch (Exception^ MyEx)
			{
				MessageBox::Show(MyEx->Message, "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
		 }
		 //浏览文件(解压)
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 OpenFileDialog^ MyDlg = gcnew OpenFileDialog();
			 if (MyDlg->ShowDialog() ==System::Windows::Forms::DialogResult::OK)
			 {
				this->textBox3->Text = MyDlg->FileName;
			  }
		 }
		 //解压文件
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
		    String^ MyInFile = this->textBox3->Text;
			if (!File::Exists(MyInFile))
			{
				MessageBox::Show(MyInFile + "文件不存在!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
		    String^ MyOutFile=this->textBox4->Text;
			try
			{
				FileStream^ MyInStream = gcnew FileStream(MyInFile, FileMode::Open, FileAccess::Read, FileShare::Read);
				GZipStream^ MyZipStream = gcnew GZipStream(MyInStream, CompressionMode::Decompress);
				FileStream^ MyOutStream = gcnew FileStream(MyOutFile, FileMode::OpenOrCreate, FileAccess::Write);
				array<unsigned char>^  MyBuffer = gcnew array<unsigned char>(1024);
				int MyCount = 0;
				while ((MyCount=MyZipStream->Read(MyBuffer, 0, 1024)) > 0)
				{
					MyOutStream->Write(MyBuffer, 0, MyCount);
				}
				MyInStream->Close();
				MyZipStream->Close();
				MyOutStream->Close();
				MessageBox::Show("成功解压缩文件:" + MyInFile, "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
			catch (Exception^ MyEx)
			{
				MessageBox::Show(MyEx->Message, "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
			}
		 }
};
}

⌨️ 快捷键说明

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