SelColorFrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:8k
- unit SelColorFrm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls,RealMessengerUnit,MSHtml,ActiveX, ExtDlgs,UrlMon,Global,ChatingFrm,Registry;
- type
- TSelColorForm = class(TForm)
- ImgDraw: TImage;
- ImageCustom: TImage;
- Image1: TImage;
- Image2: TImage;
- Image4: TImage;
- Image5: TImage;
- Image3: TImage;
- Image6: TImage;
- Image7: TImage;
- Image9: TImage;
- Image10: TImage;
- Image11: TImage;
- Image12: TImage;
- Image14: TImage;
- Shape1: TShape;
- Timer1: TTimer;
- ColorDialog1: TColorDialog;
- ImageDefault: TImage;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormDeactivate(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Timer1Timer(Sender: TObject);
- procedure Image1Click(Sender: TObject);
- procedure ImageCustomClick(Sender: TObject);
- procedure ImageDefaultClick(Sender: TObject);
- procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- private
- ImgIndex,LastImgIndex:Integer;
- public
- ParentForm:TChatingForm;
- end;
- var
- SelColorForm: TSelColorForm;
- implementation
- {$R *.dfm}
- {onClose事件,释放内存}
- procedure TSelColorForm.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- Action:=caFree;
- SelColorForm:=nil;
- end;
- {OnDeactivate时关闭窗口}
- procedure TSelColorForm.FormDeactivate(Sender: TObject);
- begin
- Close;
- end;
- {OnCreate事件,设置DoubleBuffered=True,以防止闪烁}
- procedure TSelColorForm.FormCreate(Sender: TObject);
- begin
- Self.DoubleBuffered:=True;
- SetWindowLong( Handle, GWL_EXSTYLE,GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
- end;
- {OnShow事件,显示系统提供的N种基本颜色}
- procedure TSelColorForm.FormShow(Sender: TObject);
- begin
- Image1.Canvas.Brush.Color:=$00d2d2d2;
- Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
- Image2.Canvas.Brush.Color:=$00EFD0C1;
- Image2.Canvas.Rectangle(0,0,Image2.Width,Image2.Height);
- Image3.Canvas.Brush.Color:=$00D7C0A7;
- Image3.Canvas.Rectangle(0,0,Image3.Width,Image3.Height);
- Image4.Canvas.Brush.Color:=$00D7B3C4;
- Image4.Canvas.Rectangle(0,0,Image4.Width,Image4.Height);
- Image5.Canvas.Brush.Color:=$00E5A5DB;
- Image5.Canvas.Rectangle(0,0,Image5.Width,Image5.Height);
- Image6.Canvas.Brush.Color:=$00E9B1D4;
- Image6.Canvas.Rectangle(0,0,Image6.Width,Image6.Height);
- Image7.Canvas.Brush.Color:=$00A6DFAB;
- Image7.Canvas.Rectangle(0,0,Image7.Width,Image7.Height);
- Image9.Canvas.Brush.Color:=$00A5D1FF;
- Image9.Canvas.Rectangle(0,0,Image9.Width,Image9.Height);
- Image10.Canvas.Brush.Color:=$00A7C7DD;
- Image10.Canvas.Rectangle(0,0,Image10.Width,Image10.Height);
- Image11.Canvas.Brush.Color:=$00A5C8CA;
- Image11.Canvas.Rectangle(0,0,Image11.Width,Image11.Height);
- Image12.Canvas.Brush.Color:=$00A7A7DF;
- Image12.Canvas.Rectangle(0,0,Image12.Width,Image12.Height);
- Image14.Canvas.Brush.Color:=$00BBCDA5;
- Image14.Canvas.Rectangle(0,0,Image14.Width,Image14.Height);
- ImageCustom.Canvas.Pen.Color:=$00781E1D;
- ImageCustom.Canvas.TextOut(4,4,'更多颜色...');
- ImageDefault.Canvas.Pen.Color:=$00781E1D;
- ImageDefault.Canvas.TextOut(4,4,'取消自定义颜色');
- SelColorForm.Left:=ParentForm.Left + ParentForm.PnlLeftBottom.Left + ParentForm.ImgSelColor.Left+4;
- SelColorForm.Top:=ParentForm.Top + ParentForm.PnlLeftBottom.Top + ParentForm.ImgSelColor.Top - Height + 3;
- end;
- {模拟按钮按下}
- procedure TSelColorForm.Image1MouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- Img:TImage;
- begin
- Img:=(Sender as TImage);
- With ImgDraw.Canvas do
- begin
- Pen.Mode :=pmCopy;
- Pen.Style:=psClear;
- Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
- Pen.Style:=psSolid;
- Pen.Color:=EndColor;
- Pen.Width:=1;
- MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
- LineTo(PenPos.X-((Sender as TImage).Width+4),PenPos.Y);
- LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
- Pen.Color:=$00F5F5F5;
- LineTo(PenPos.X+(Sender as TImage).Width+4,PenPos.Y);
- LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
- Refresh;
- end;
- LastImgIndex:=ImgIndex;
- Timer1.Enabled:=False;
- Img.Left:=Img.Left+1;
- Img.Top:=Img.Top+1;
- end;
- {恢复按钮的状态}
- procedure TSelColorForm.Image1MouseUp(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- Img:TImage;
- begin
- Img:=(Sender as TImage);
- Img.Left:=Img.Left-1;
- Img.Top:=Img.Top-1;
- With ImgDraw.Canvas do
- begin
- Pen.Mode :=pmCopy;
- Pen.Style:=psClear;
- Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
- Pen.Style:=psSolid;
- Pen.Color:=$00F5F5F5;
- Pen.Width:=1;
- MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
- LineTo(PenPos.X-((Sender as TImage).Width+4),PenPos.Y);
- LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
- Pen.Color:=EndColor;
- LineTo(PenPos.X+(Sender as TImage).Width+4,PenPos.Y);
- LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
- Refresh;
- end;
- LastImgIndex:=ImgIndex;
- Timer1.Enabled:=True;
- end;
- {检查Mouse是否还在指定的范围之内,不在则恢复所有按钮的状态}
- procedure TSelColorForm.Timer1Timer(Sender: TObject);
- var
- p : TPoint;
- begin
- GetCursorPos(p);
- if (P.X < Left) or
- (P.X > Left + Width) or
- (P.Y < Top) or
- (P.Y > Top + Height) then
- begin
- With ImgDraw.Canvas do
- begin
- Pen.Mode :=pmCopy;
- Pen.Style:=psClear;
- Rectangle(0,0,ImgDraw.Width+1,Shape1.Height+1);
- end;
- ImgIndex:=-1;
- LastImgIndex:=-1;
- Timer1.Enabled:=False;
- end;
- end;
- {选择了某个颜色}
- procedure TSelColorForm.Image1Click(Sender: TObject);
- var
- TempReg:TRegistry;
- begin
- EndColor:=(Sender as TImage).Canvas.Pixels[1,1];
- ChangeAllColor(EndColor);
- TempReg:=TRegistry.Create;
- try
- TempReg.RootKey:=HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey+''+LoginName+'Init', True) then
- begin
- TempReg.WriteString('CustomColor',IntToStr(EndColor));
- end;
- finally
- TempReg.Free;
- end;
- Close;
- end;
- {打开自定义颜色对话框,以供用户选择更多的颜色}
- procedure TSelColorForm.ImageCustomClick(Sender: TObject);
- var
- TempReg:TRegistry;
- begin
- ColorDialog1.Color:=EndColor;
- if ColorDialog1.Execute then
- begin
- EndColor:=ColorDialog1.Color;
- ChangeAllColor(EndColor);
- TempReg:=TRegistry.Create;
- try
- TempReg.RootKey:=HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey+''+LoginName+'Init', True) then
- begin
- TempReg.WriteString('CustomColor',IntToStr(EndColor));
- end;
- finally
- TempReg.Free;
- end;
- Close;
- end;
- end;
- {取消自定义颜色,显示系统默认颜色}
- procedure TSelColorForm.ImageDefaultClick(Sender: TObject);
- var
- TempReg:TRegistry;
- begin
- EndColor:=DefaultColor;
- ChangeAllColor(EndColor);
- TempReg:=TRegistry.Create;
- try
- TempReg.RootKey:=HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey+''+LoginName+'Init', True) then
- begin
- TempReg.WriteString('CustomColor','');
- end;
- finally
- TempReg.Free;
- end;
- Close;
- end;
- {MouseMove时使平面的按钮变为凸起状态}
- procedure TSelColorForm.Image1MouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- var
- Img:TImage;
- begin
- Img:=(Sender as TImage);
- ImgIndex:=Img.Tag;
- if ImgIndex=LastImgIndex then exit;
- With ImgDraw.Canvas do
- begin
- Pen.Mode :=pmCopy;
- Pen.Style:=psClear;
- Rectangle(0,0,ImgDraw.Width+1,ImgDraw.Height+1);
- Pen.Style:=psSolid;
- Pen.Width:=1;
- Pen.Color:=$00F5F5F5;
- MoveTo(Img.Left+Img.Width-ImgDraw.Left+2,Img.Top-ImgDraw.Top-2);
- LineTo(PenPos.X-(Img.Width+4),PenPos.Y);
- LineTo(PenPos.X,PenPos.Y+(Img.Height+4));
- Pen.Color:=EndColor;
- LineTo(PenPos.X+Img.Width+4,PenPos.Y);
- LineTo(PenPos.X,PenPos.Y-(Img.Height+4));
- Refresh;
- end;
- LastImgIndex:=ImgIndex;
- Timer1.Enabled:=True;
- end;
- end.