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

Delphi控件源码

开发平台:

Delphi

  1. unit SelBackFrm;
  2. interface
  3. uses
  4.   Windows, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ChatingFrm, ExtCtrls,RealMessengerUnit,MSHtml,ActiveX, ExtDlgs,UrlMon,Global;
  6. type
  7.   TSelBackForm = class(TForm)
  8.     Shape1: TShape;
  9.     Image1: TImage;
  10.     Image2: TImage;
  11.     Image3: TImage;
  12.     Image4: TImage;
  13.     Image5: TImage;
  14.     Image6: TImage;
  15.     ImageCustom: TImage;
  16.     Timer1: TTimer;
  17.     ImgDraw: TImage;
  18.     ImageCancel: TImage;
  19.     OpenPictureDialog1: TOpenPictureDialog;
  20.     procedure FormShow(Sender: TObject);
  21.     procedure FormDeactivate(Sender: TObject);
  22.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure Timer1Timer(Sender: TObject);
  25.     procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  26.       Y: Integer);
  27.     procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
  28.       Shift: TShiftState; X, Y: Integer);
  29.     procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
  30.       Shift: TShiftState; X, Y: Integer);
  31.     procedure Image1Click(Sender: TObject);
  32.     procedure ImageCancelClick(Sender: TObject);
  33.     procedure ImageCustomClick(Sender: TObject);
  34.   private
  35.     ImgIndex,LastImgIndex:Integer;
  36.   public
  37.     ParentForm:TChatingForm;
  38.   end;
  39. var
  40.   SelBackForm: TSelBackForm;
  41. implementation
  42. {$R *.dfm}
  43. {OnShow事件}
  44. procedure TSelBackForm.FormShow(Sender: TObject);
  45. begin
  46.     ImageCustom.Canvas.Pen.Color:=$00781E1D;
  47.     ImageCustom.Canvas.TextOut(4,4,'自定义聊天场景...');
  48.     ImageCancel.Canvas.Pen.Color:=$00781E1D;
  49.     ImageCancel.Canvas.TextOut(4,4,'取消聊天场景');
  50.     SelBackForm.Left:=ParentForm.Left + ParentForm.PnlLeftBottom.Left + ParentForm.ImgSelBack.Left+4;
  51.     SelBackForm.Top:=ParentForm.Top + ParentForm.PnlLeftBottom.Top + ParentForm.ImgSelBack.Top - Height + 3;
  52. end;
  53. {OnDeactivate时关闭窗口}
  54. procedure TSelBackForm.FormDeactivate(Sender: TObject);
  55. begin
  56.   Close;
  57. end;
  58. {onClose事件,释放内存}
  59. procedure TSelBackForm.FormClose(Sender: TObject;
  60.   var Action: TCloseAction);
  61. begin
  62.   Action:=caFree;
  63.   SelBackForm:=nil;
  64. end;
  65. {OnCreate事件,设置DoubleBuffered=True,以防止闪烁}
  66. procedure TSelBackForm.FormCreate(Sender: TObject);
  67. begin
  68.     Self.DoubleBuffered:=True;
  69.     SetWindowLong( Handle, GWL_EXSTYLE,GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
  70. end;
  71. {检查Mouse是否还在指定的范围之内,不在则恢复所有按钮的状态}
  72. procedure TSelBackForm.Timer1Timer(Sender: TObject);
  73. var
  74.    p : TPoint;
  75. begin
  76.    GetCursorPos(p);
  77.    if (P.X < Left) or
  78.       (P.X > Left + Width) or
  79.       (P.Y < Top) or
  80.       (P.Y > Top + Height) then
  81.    begin
  82.       With ImgDraw.Canvas do
  83.       begin
  84.         Pen.Mode :=pmCopy;
  85.         Pen.Style:=psClear;
  86.         Rectangle(0,0,ImgDraw.Width+1,Shape1.Height+1);
  87.       end;
  88.       ImgIndex:=-1;
  89.       LastImgIndex:=-1;
  90.       Timer1.Enabled:=False;
  91.    end;
  92. end;
  93. {MouseMove时使平面的按钮变为凸起状态}
  94. procedure TSelBackForm.Image1MouseMove(Sender: TObject; Shift: TShiftState;
  95.   X, Y: Integer);
  96. var
  97.     Img:TImage;
  98. begin
  99.     Img:=(Sender as TImage);
  100.     ImgIndex:=Img.Tag;
  101.     if ImgIndex=LastImgIndex then exit;
  102.     With ImgDraw.Canvas do
  103.     begin
  104.       Pen.Mode :=pmCopy;
  105.       Pen.Style:=psClear;
  106.       Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
  107.       Pen.Style:=psSolid;
  108.       Pen.Width:=1;
  109.       Pen.Color:=$00F5F5F5;
  110.       MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
  111.       LineTo(PenPos.X-(Img.Width+4),PenPos.Y);
  112.       LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
  113.       Pen.Color:=EndColor;
  114.       LineTo(PenPos.X+Img.Width+4,PenPos.Y);
  115.       LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
  116.       Refresh;
  117.     end;
  118.     LastImgIndex:=ImgIndex;
  119.     Timer1.Enabled:=True;
  120. end;
  121. {模拟按钮按下}
  122. procedure TSelBackForm.Image1MouseDown(Sender: TObject;
  123.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  124. var
  125.     Img:TImage;
  126. begin
  127.     Img:=(Sender as TImage);
  128.     With ImgDraw.Canvas do
  129.     begin
  130.       Pen.Mode :=pmCopy;
  131.       Pen.Style:=psClear;
  132.       Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
  133.       Pen.Style:=psSolid;
  134.       Pen.Color:=EndColor;
  135.       Pen.Width:=1;
  136.       MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
  137.       LineTo(PenPos.X-((Sender as TImage).Width+4),PenPos.Y);
  138.       LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
  139.       Pen.Color:=$00F5F5F5;
  140.       LineTo(PenPos.X+(Sender as TImage).Width+4,PenPos.Y);
  141.       LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
  142.       Refresh;
  143.     end;
  144.     LastImgIndex:=ImgIndex;
  145.     Timer1.Enabled:=False;
  146.     Img.Left:=Img.Left+1;
  147.     Img.Top:=Img.Top+1;
  148. end;
  149. {恢复按钮的状态}
  150. procedure TSelBackForm.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  151.   Shift: TShiftState; X, Y: Integer);
  152. var
  153.     Img:TImage;
  154. begin
  155.     Img:=(Sender as TImage);
  156.     Img.Left:=Img.Left-1;
  157.     Img.Top:=Img.Top-1;
  158.     With ImgDraw.Canvas do
  159.     begin
  160.       Pen.Mode :=pmCopy;
  161.       Pen.Style:=psClear;
  162.       Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
  163.       Pen.Style:=psSolid;
  164.       Pen.Color:=$00F5F5F5;
  165.       Pen.Width:=1;
  166.       MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
  167.       LineTo(PenPos.X-((Sender as TImage).Width+4),PenPos.Y);
  168.       LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
  169.       Pen.Color:=EndColor;
  170.       LineTo(PenPos.X+(Sender as TImage).Width+4,PenPos.Y);
  171.       LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
  172.       Refresh;
  173.     end;
  174.     LastImgIndex:=ImgIndex;
  175.     Timer1.Enabled:=True;
  176. end;
  177. {选择了某个背景}
  178. procedure TSelBackForm.Image1Click(Sender: TObject);
  179. begin
  180.   ParentForm.SetBrowserBg(ResPath+'/Back/'+IntToStr((Sender as TImage).Tag)+'.jpg');
  181.   ParentForm.MsgInput.SetFocus;
  182. end;
  183. {取消背景}
  184. procedure TSelBackForm.ImageCancelClick(Sender: TObject);
  185. begin
  186.   ParentForm.SetBrowserBg('');
  187.   ParentForm.MsgInput.SetFocus;
  188. end;
  189. {自定义背景}
  190. procedure TSelBackForm.ImageCustomClick(Sender: TObject);
  191. begin
  192.   if OpenPictureDialog1.Execute then
  193.   begin
  194.     ParentForm.SetBrowserBg(OpenPictureDialog1.Files.Strings[0]);
  195.     ParentForm.MsgInput.SetFocus;
  196.   end;
  197. end;
  198. end.