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

📄 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 Microsoft::Win32;

	/// <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:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->SuspendLayout();
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(390, 177);
			this->Name = L"Form1";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"演示限制用户使用软件次数";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
//限制软件使用次数
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
	RegistryKey ^MyRootKey,^MyRegKey;
	MyRootKey = Registry::CurrentUser->OpenSubKey ("Software",true);
	//打开子项:HKEY_CURRENT_USER\Software\MyRegDataApp
	if ((MyRegKey = MyRootKey->OpenSubKey ("MyRegDataApp",true)) == nullptr)
	{
		//不存在,则创建子项
		MyRootKey->CreateSubKey("MyRegDataApp");
		MyRegKey = MyRootKey->OpenSubKey ("MyRegDataApp",true);
		//创建键值,存储可使用次数
		MyRegKey->SetValue ("MyUseTimes",(System::Object^)9);
		MessageBox::Show ("您可以免费使用本软件10次!","信息提示",MessageBoxButtons::OK,MessageBoxIcon::Information);
		return;
	}
	try
	{
		//读取键值,可使用次数
		System::Object^ MyUseTimes = MyRegKey->GetValue ("MyUseTimes");
		int MyNewTimes = Int32::Parse (MyUseTimes->ToString()) -1;
		if (MyNewTimes<0)
		{
			MessageBox::Show ("试用次数已经用完,继续使用,请购买本软件!\n 联系EMail binluobin@163.com","信息提示",MessageBoxButtons::OK ,MessageBoxIcon::Information );
			this->Close();
			return;
		}
		this->Text="演示限制用户使用软件次数-"+"剩余使用次数:"+ MyUseTimes->ToString ()+ "次!";
		//更新键值,可使用次数减1
		MyRegKey->SetValue ("MyUseTimes",(System::Object^)MyNewTimes);
	}
	catch(Exception^ MyEx)
	{
		//创建键值,存储可使用次数
		MyRegKey->SetValue ("MyUseTimes",(System::Object^)10);
		MessageBox::Show ("您可以免费使用本软件10次!","信息提示",
			MessageBoxButtons::OK,MessageBoxIcon::Information);
		return;
	}
 }
	};
}

⌨️ 快捷键说明

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