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

📄 setting.cpp

📁 OA客户端工具
💻 CPP
字号:
#include <vcl.h>
#pragma hdrstop

#include "Setting.h"
#include "Global.h"

#pragma package(smart_init)
#pragma resource "*.dfm"
TSettingForm *SettingForm;

__fastcall TSettingForm::TSettingForm(TComponent* Owner)
	: TForm(Owner)
{
}

void __fastcall TSettingForm::btn_DefaultClick(TObject *Sender)
{
	edt_HostName->Text = "192.168.0.1";
	edt_Port->Text = "8270";
	cb_NotifyPopwin->Checked = true;
	cb_NotifyIconFlash->Checked = false;
	cb_NotifyPlaySound->Checked = false;
	edt_SoundFile->Enabled = false;
	btn_Open->Enabled = false;
	btn_Open->Enabled = false;

	tb_RefreshTime->Position = 5;
	cb_EncryptTrans->Checked = true;
	cb_AutoRun->Checked = true;
}

void __fastcall TSettingForm::FormCreate(TObject *Sender)
{
	edt_HostName->Text = Global.RemoteHost;
	edt_Port->Text = IntToStr(Global.Port);

	if(Global.GetNotifyMode(NOTIFY_POPWIN))
		cb_NotifyPopwin->Checked = true;
	if(Global.GetNotifyMode(NOTIFY_ICONFLASH))
		cb_NotifyIconFlash->Checked = true;

	tb_RefreshTime->Position = Global.TimerInterval;
	cb_EncryptTrans->Checked = Global.EncryptTrans;

	TRegIniFile *Reg = new TRegIniFile("SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
	//Reg->RootKey = HKEY_LOCAL_MACHINE;
	AnsiString szRun = Reg->ReadString("Run","Hroa_Client","");
	cb_AutoRun->Checked = (szRun == Application->ExeName)?true:false;
	delete Reg;

    edt_SoundFile->Text = Global.SoundFile;
    cb_NotifyPlaySound->Checked = Global.GetNotifyMode(NOTIFY_PLAYSOUND);

    if(SoundCardExists() && cb_NotifyPlaySound->Checked)
	{	btn_Open->Enabled = true;
		btn_Play->Enabled = true;
       	edt_SoundFile->Enabled = true;
	}
    else
    {	btn_Open->Enabled = false;
		btn_Play->Enabled = false;
	   	edt_SoundFile->Enabled = false;
	}
}

void __fastcall TSettingForm::btn_OpenClick(TObject *Sender)
{
	if(OpenDlg->Execute())	edt_SoundFile->Text = OpenDlg->FileName;
}

void __fastcall TSettingForm::cb_NotifyPlaySoundClick(TObject *Sender)
{
	if(cb_NotifyPlaySound->Checked)
	{	edt_SoundFile->Enabled = true;
		btn_Open->Enabled = true;
		btn_Play->Enabled = true;
	}
	else
	{	edt_SoundFile->Enabled = false;
		btn_Open->Enabled = false;
		btn_Play->Enabled = false;
	}
}

void __fastcall TSettingForm::btn_CancelClick(TObject *Sender)
{
	Close();	
}

void __fastcall TSettingForm::btn_OkClick(TObject *Sender)
{
	if(!(cb_NotifyPopwin->Checked || cb_NotifyIconFlash->Checked || cb_NotifyPlaySound->Checked))
	{	MessageBox(Handle,"必须选择一种提醒方法!","提示",MB_ICONWARNING);
		return;
	}

	if(SoundCardExists())
	{	if(cb_NotifyPlaySound->Checked)		//检查声音文件是否存在
		{	if(!FileExists(edt_SoundFile->Text))
			{	MessageBox(Handle,"声音文件不存在!","提示",MB_ICONERROR);
				return;
			}
		}
	}
	
	Global.SetRemoteHost(edt_HostName->Text.c_str());
	Global.Port = edt_Port->Text.ToInt();

	Global.NotifyMode = 0;
	
	if(cb_NotifyPopwin->Checked)	Global.SetNotifyMode(NOTIFY_POPWIN);
	if(cb_NotifyIconFlash->Checked)	Global.SetNotifyMode(NOTIFY_ICONFLASH);
	if(cb_NotifyPlaySound->Checked)
	{	Global.SetNotifyMode(NOTIFY_PLAYSOUND);
		Global.SetSoundFile(edt_SoundFile->Text.c_str());
	}

	Global.TimerInterval = tb_RefreshTime->Position;
	Global.EncryptTrans = cb_EncryptTrans->Checked;

	AnsiString szIniName = ExtractFilePath(Application->ExeName) + ChangeFileExt(ExtractFileName(Application->ExeName),".ini");
	TIniFile *IniFile = new TIniFile(szIniName);
	IniFile->WriteString("Config","HostName",Global.RemoteHost);
	IniFile->WriteInteger("Config","Port",Global.Port);
	IniFile->WriteInteger("Config","NotifyMode",Global.NotifyMode);
	IniFile->WriteString("Config","SoundFile",Global.SoundFile);
	IniFile->WriteBool("Config","EncryptTrans",Global.EncryptTrans);
	IniFile->WriteInteger("Config","TimerInterval",Global.TimerInterval);
	delete IniFile;

	//自动运行
	TRegIniFile *Reg = new TRegIniFile("SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
	//Reg->RootKey = HKEY_LOCAL_MACHINE;
	if(cb_AutoRun->Checked)
		Reg->WriteString("Run","Hroa_Client",Application->ExeName);
	else
		Reg->DeleteKey("Run","Hroa_Client");
	delete Reg;

	Close();
}

void __fastcall TSettingForm::btn_PlayClick(TObject *Sender)
{
	if(SoundCardExists()&&FileExists(edt_SoundFile->Text))
		PlaySound(edt_SoundFile->Text.c_str(), NULL, SND_ASYNC|SND_FILENAME);
}


⌨️ 快捷键说明

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