HistoryFrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit HistoryFrm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ToolWin, ComCtrls, OleCtrls, SHDocVw,MSHTML,ActiveX,WNDES,ChatingFrm,
  6.   ExtCtrls, ImgList,Global,StrUtils;
  7. type
  8.   THistoryForm = class(TForm)
  9.     Panel1: TPanel;
  10.     WebBrowser1: TWebBrowser;
  11.     ImageList1: TImageList;
  12.     CoolBar1: TCoolBar;
  13.     ToolBar1: TToolBar;
  14.     TBCopy: TToolButton;
  15.     TBFind: TToolButton;
  16.     TBPrint: TToolButton;
  17.     TBDel: TToolButton;
  18.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  19.     procedure TBFindClick(Sender: TObject);
  20.     procedure TBPrintClick(Sender: TObject);
  21.     procedure TBDelClick(Sender: TObject);
  22.     procedure FormShow(Sender: TObject);
  23.     procedure TBCopyClick(Sender: TObject);
  24.   private
  25.   public
  26.     ID:Integer;
  27.     Name:String;
  28.   end;
  29.   
  30. var
  31.   HistoryForm: THistoryForm;
  32.   
  33. implementation
  34. uses
  35.   RealMessengerUnit;
  36. {$R *.dfm}
  37. {窗口关闭时,释放窗口}
  38. procedure THistoryForm.FormClose(Sender: TObject;
  39.   var Action: TCloseAction);
  40. begin
  41.   Action:=caFree;
  42.   HistoryForm:=nil;
  43. end;
  44. {查找}
  45. procedure THistoryForm.TBFindClick(Sender: TObject);
  46. const
  47. CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
  48. var
  49.   CmdTarget : IOleCommandTarget;
  50.   vaIn, vaOut: OleVariant;
  51.   PtrGUID: PGUID;
  52. begin
  53.   New(PtrGUID);
  54.   PtrGUID^ := CGID_WebBrowser;
  55.   if WebBrowser1.Document <> nil then
  56.    try
  57.      WebBrowser1.Document.QueryInterface(IOleCommandTarget, CmdTarget);
  58.      if CmdTarget <> nil then
  59.       try
  60.         CmdTarget.Exec( PtrGUID, 1, 0, vaIn, vaOut);
  61.        finally
  62.          CmdTarget._Release;
  63.        end;
  64.    except
  65.     // Nothing
  66.     end;
  67.   Dispose(PtrGUID);
  68. end;
  69. {打印}
  70. procedure THistoryForm.TBPrintClick(Sender: TObject);
  71. begin
  72.   try
  73.     WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
  74.   except
  75.   end;
  76. end;
  77. {删除}
  78. procedure THistoryForm.TBDelClick(Sender: TObject);
  79. begin
  80.   if MessageBox(Handle,PChar('确定要删除与 '+Name+' 的对话历史记录吗?'),'确认删除',MB_ICONQUESTION or MB_OKCANCEL )=ID_OK then
  81.   try
  82.     DeleteFile(HistoryPath+''+IntToStr(Me.ID)+''+IntToStr(ID)+'.xml');
  83.     Hide;
  84.     MessageBox(Handle,'历史记录已被删除!','提示',MB_ICONINFORMATION);
  85.     Close;
  86.   except
  87.     MessageBox(Handle,'未能删除历史记录!','错误',MB_ICONERROR);
  88.   end;
  89. end;
  90. procedure THistoryForm.FormShow(Sender: TObject);
  91. var
  92.   HistoryFile,MyHistoryPath:String;
  93.   FileStream:TFileStream;
  94.   DoC: IHTMLDocument2;
  95.   CBMessage:TCBMessage;
  96.   Employee:PEmployee;
  97.   iLoop:Integer;
  98. begin
  99.   MyHistoryPath:=HistoryPath+''+IntToStr(Me.ID);
  100.   if not DirectoryExists(MyHistoryPath) then CreateDir(MyHistoryPath);
  101.   HistoryFile:=MyHistoryPath+''+IntToStr(ID)+'.xml';
  102.   if not FileExists(HistoryFile) then
  103.   begin
  104.     MessageBox(Handle,PChar('没有找到任何与 '+Name+' 有关的对话历史记录!'),'提示',MB_ICONINFORMATION);
  105.     Width:=0;
  106.     Height:=0;
  107.     Left:=-100;
  108.     Top:=-100;
  109.     Close;
  110.     Exit;
  111.   end;
  112.   Caption:=Name+' 的历史记录';
  113.   WebBrowser1.Navigate('file://'+AnsiReplaceStr(AnsiReplaceStr(HistoryFile,'\',''),'','/'));
  114. end;
  115. procedure THistoryForm.TBCopyClick(Sender: TObject);
  116. begin
  117.   try
  118.     WebBrowser1.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_PROMPTUSER);
  119.   except
  120.   end;
  121. end;
  122. end.