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

Delphi控件源码

开发平台:

Delphi

  1. unit SelFaceFrm;
  2. interface
  3. uses
  4.   Windows, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls, StdCtrls,RealMessengerUnit,ChatingFrm,Global;
  6. type
  7.   TSelFaceForm = class(TForm)
  8.     ImgFace: TImage;
  9.     procedure FormDeactivate(Sender: TObject);
  10.     procedure ImgFaceMouseMove(Sender: TObject; Shift: TShiftState; X,
  11.       Y: Integer);
  12.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  13.     procedure ImgFaceClick(Sender: TObject);
  14.     procedure FormShow(Sender: TObject);
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.     MX,MY,IconIndex,LastIconIndex:Integer;
  18.   public
  19.     ParentForm:TChatingForm;
  20.     HintWindow:THintWindow;
  21.     { Public declarations }
  22.   end;
  23. Const
  24.   FaceCount=70;
  25.   FacesChar: array[1..FaceCount] of string =
  26.   (
  27.     ':)',':d',';)',':o',':p','(h)',':@',':s',':$',':(',
  28.     ':''(',':|','(a)','Bo|','B-|','+o(',':b','|-)','*-)',':-#',
  29.     ':-*','^o)','B-)','(6)',':^)','(v)','(@)','(&)','(sn)','(bah)',
  30.     '(S)','(*)','(#)','(r)','([)','(])','(k)','(f)','(w)','(o)',
  31.     '(g)','(^)','(p)','(i)','(c)','(t)','(mp)','(au)','(ap)','(co)',
  32.     '(mo)','(~)','(8)','(pi)','(so)','(e)','(z)','(x)','(ip)','(um)',
  33.     ':[','(n)','(y)','(ba)','(st)','(li)','(L)','(u)','($)','(he)'
  34.   );
  35.   
  36.   FacesHit: array[1..FaceCount] of string =
  37.   (
  38.     '笑脸','咧嘴笑脸','眨眼笑脸','惊讶的笑脸','吐舌笑脸','热烈的笑脸','生气的脸','困惑的笑脸','尴尬的笑脸','悲伤的脸',
  39.     '哭泣的脸','失望的脸','天使','咬牙切齿','书呆子','生病的脸','聚会笑脸','困了','正在思考','保守秘密',
  40.     '悄悄话','讽刺的脸','转动眼睛','恶魔','不知道','电视机','猫脸','狗脸','蜗牛','黑羊',
  41.     '沉睡的弯月','星星','太阳','彩虹','左侧拥抱','右侧拥抱','红唇','红玫瑰','凋谢的玫瑰','时钟',
  42.     '礼品盒','生日蛋糕','照相机','灯泡','咖啡','电话听筒','移动电话','汽车','飞机','计算机',
  43.     '金钱','电影胶片','音符','比萨','足球','电子邮件','男孩','女孩','有棕榈树的小岛','雨伞',
  44.     '吸血蝙蝠','太差了','太棒了','篮球','乌云','闪电','红心','破碎的心','美元','向日葵'
  45.   );
  46. var
  47.     FaceStream:TFileStream;
  48.     SelFaceForm: TSelFaceForm;
  49.     FaceHasGeted:Boolean;
  50.     Faces,FaceCodes: array[1..FaceCount] of string; //表情图标字符串
  51. implementation
  52. {$R *.dfm}
  53. {OnDeactivate时关闭窗口}
  54. procedure TSelFaceForm.FormDeactivate(Sender: TObject);
  55. begin
  56.   Close;
  57. end;
  58. {MouseMove时显示Mouse当前所指向的表情的相关信息}
  59. procedure TSelFaceForm.ImgFaceMouseMove(Sender: TObject;
  60.   Shift: TShiftState; X, Y: Integer);
  61. var
  62.   r : TRect;
  63. begin
  64.   MX:=X;
  65.   MY:=Y;
  66.   IconIndex:=(MY div 31)*10+(MX div 31+1);
  67.   if (IconIndex<=Length(Faces)) and (LastIconIndex<>IconIndex)   then
  68.   begin
  69.     r.left := Left +  ((IconIndex-1) mod 10)*30+30;
  70.     r.top  := Top + ((IconIndex-1) div 10)*30+30;
  71.     with HintWindow do
  72.     begin
  73.       r.right := r.left+Canvas.TextWidth(FacesHit[IconIndex]+' '+FacesChar[IconIndex])+10;
  74.       r.bottom := r.top+16;
  75.       Color := clInfoBk;
  76.       ReleaseHandle;
  77.       ActivateHint(r,FacesHit[IconIndex]+' '+FacesChar[IconIndex]);
  78.     end;
  79.     ImgFace.Canvas.Pen.Mode:=pmXor;
  80.     ImgFace.Canvas.Pen.Color:=clYellow;
  81.     ImgFace.Canvas.Pen.Width:=1;
  82.     ImgFace.Canvas.Brush.Style:=bsClear;
  83.     ImgFace.Canvas.Rectangle(((LastIconIndex-1) mod 10)*30+3,((LastIconIndex-1) div 10)*30+3,((LastIconIndex-1) mod 10)*30+30,((LastIconIndex-1) div 10)*30+30);
  84.     ImgFace.Canvas.Rectangle(((IconIndex-1) mod 10)*30+3,((IconIndex-1) div 10)*30+3,((IconIndex-1) mod 10)*30+30,((IconIndex-1) div 10)*30+30);
  85.     LastIconIndex:=IconIndex;
  86.   end;
  87. end;
  88. {窗口关闭时释放已分配的内存}
  89. procedure TSelFaceForm.FormClose(Sender: TObject;
  90.   var Action: TCloseAction);
  91. begin
  92.   HintWindow.ReleaseHandle;
  93.   HintWindow.Free;
  94.   Action:=caFree;
  95.   SelFaceForm:=nil;
  96. end;
  97. {选择并插入表情图标}
  98. procedure TSelFaceForm.ImgFaceClick(Sender: TObject);
  99. begin
  100.   if IconIndex<=Length(Faces) then
  101.   begin
  102.     ParentForm.MsgInput.SelText := Faces[IconIndex];
  103.     ParentForm.MsgInput.SelLength := 0;
  104.     ParentForm.MsgInput.SelStart := ParentForm.MsgInput.SelStart + 1;
  105.     ParentForm.MsgInput.SetFocus;
  106.   end;
  107. end;
  108. {OnShow事件,设置弹出的窗口的位置}
  109. procedure TSelFaceForm.FormShow(Sender: TObject);
  110. begin
  111.     SelFaceForm.Left:=ParentForm.Left + ParentForm.PnlLeftBottom.Left + ParentForm.ImgSelFace.Left+4;
  112.     SelFaceForm.Top:=ParentForm.Top + ParentForm.PnlLeftBottom.Top + ParentForm.ImgSelFace.Top - ImgFace.Height + 3;
  113.     LastIconIndex:=-1;
  114.     HintWindow:=THintWindow.Create(Self);
  115. end;
  116. {OnCreate事件,设置DoubleBuffered=True,以防止闪烁}
  117. procedure TSelFaceForm.FormCreate(Sender: TObject);
  118. begin
  119.     Self.DoubleBuffered:=True;
  120.     SetWindowLong( Handle, GWL_EXSTYLE,GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
  121. end;
  122. end.