Unit1.pas
上传用户:brightee
上传日期:2009-12-07
资源大小:160k
文件大小:4k
源码类别:

GDI/图象编程

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, SysUtils, Graphics, Forms, gifimage, ComCtrls,inifiles, Classes,
  5.   ExtCtrls, Controls;
  6. type
  7.   TForm1 = class(TForm)
  8.     Timer1: TTimer;
  9.     ProgressBar: TProgressBar;
  10.     procedure FormCreate(Sender: TObject);
  11.     procedure Timer1Timer(Sender: TObject);
  12.   private
  13.   procedure OnProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18. var
  19.   Form1: TForm1;
  20.   half:tbitmap;
  21.   dc:hdc;
  22.   halfcanvas:tcanvas;
  23.   i,j:integer;
  24.   sys:tinifile;
  25. implementation
  26.   function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external 'KERNEL32.DLL';
  27. {$R *.DFM}
  28. procedure Convert2Gray(Cnv: TCanvas);
  29. var X, Y: Integer;
  30.   Color: LongInt;
  31.   R, G, B, Gr : Byte;
  32. begin
  33.   with Cnv do
  34.     for X := Cliprect.Left to Cliprect.Right do
  35.       for Y := Cliprect.Top to Cliprect.Bottom do
  36.       begin
  37.         Color := ColorToRGB(Pixels[X, Y]);
  38.         B := (Color and $FF0000) shr 16;
  39.         G := (Color and $FF00) shr 8;
  40.         R := (Color and $FF);
  41.         Gr := HiByte(R * 77 + G * 151 + B * 28);
  42.         // Gr := Trunc(B*0.11+G*0.59+R*0.3);
  43.         Pixels[X, Y] := RGB(Gr, Gr, Gr);
  44.       end;
  45. end;
  46. function RGB(R, G, B: Byte): TColor;
  47. begin
  48.   Result := B shl 16 or G shl 8 or R;
  49. end;
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52. sys:=tinifile.Create('system.ini');
  53. RegisterServiceProcess(GetCurrentProcessID, 1);
  54. i:=0;
  55. j:=0;
  56. end;
  57. procedure TForm1.Timer1Timer(Sender: TObject);
  58. var
  59.   Bitmap : TBitmap;
  60.   GIF  : TGIFImage;
  61.   rgn:hwnd;
  62.   fileattr:string;
  63. begin
  64. timer1.Enabled:=false;
  65.   i:=i+1;
  66.       if i=sys.ReadInteger('Howlong','seconds',300) then
  67.    begin j:=j+1;
  68.       half:=tbitmap.Create;
  69.       half.Width:=screen.width;
  70.       half.Height:=screen.Height;
  71.       dc:=getdc(0);
  72.       halfCanvas:=tcanvas.Create;
  73.       halfcanvas.Handle:=dc;
  74.       half.Canvas.CopyRect(rect(0,0,screen.width,screen.height),halfcanvas,rect(0,0,screen.Width,screen.Height));
  75.       halfcanvas.Free;
  76.       releasedc(0,dc);
  77.       if not sys.ReadBool('color','color',false) then
  78.         begin
  79.           half.PixelFormat:=pf4bit;
  80.           Convert2Gray(half.Canvas);
  81.         end;
  82.       half.SaveToFile(sys.ReadString('where','folder','d:temp')+inttostr(j)+'.bmp');
  83.       filesetattr(sys.readstring('where','folder','d:temp')+inttostr(j)+'.bmp',fahidden);
  84.       half.Free;
  85.       try
  86.         Bitmap := TBitmap.Create;
  87.           try
  88.           if sys.ReadBool('type','gif',true) then
  89.           begin
  90.               // Load the bitmap that will be converted
  91.               Bitmap.LoadFromFile(sys.readstring('where','folder','d:temp')+inttostr(j)+'.bmp');
  92.               if sys.ReadBool('time','recorde',true) then
  93.                  begin
  94.                    setbkmode(bitmap.canvas.Handle,transparent);
  95.                    bitmap.Canvas.Font.Size:=12;
  96.                    bitmap.Canvas.Font.Color:=clred;
  97.                    bitmap.Canvas.Font.Name:='system';
  98.                    bitmap.Canvas.Textout(bitmap.Width-bitmap.Canvas.TextWidth('这是'+formatdatetime('yyyy''年''m''月''d''日''dddd',date)+timetostr(now)+'时屏幕的内容'),8,'这是'+formatdatetime('yyyy''年''m''月''d''日''dddd',date)+timetostr(now)+'时屏幕的内容');
  99.                  end;
  100.               GIF := TGIFImage.Create;
  101.               try
  102.                 GIF.OnProgress := OnProgress;
  103.                 GIF.Assign(Bitmap);
  104.                 gif.SaveToFile(sys.ReadString('where','folder','d:temp')+inttostr(j)+'.gif');
  105.                 filesetattr(sys.readstring('where','folder','d:temp')+inttostr(j)+'.gif', fahidden);
  106.                 deletefile(sys.ReadString('where','folder','d:temp')+inttostr(j)+'.bmp');
  107.              finally
  108.                GIF.Free;
  109.              end;
  110.             end; 
  111.            finally
  112.              Bitmap.Free;
  113.            end;
  114.          finally
  115.          end;
  116.    end else if i>sys.ReadInteger('Howlong','seconds',300) then i:=0;
  117.    timer1.Enabled:=true;
  118. end;
  119. procedure tform1.OnProgress(Sender: TObject; Stage: TProgressStage;
  120.   PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
  121. begin
  122. if (Stage= psEnding) then
  123.     ProgressBar.Position := 0
  124.   else
  125.     ProgressBar.Position := PercentDone;
  126. end;
  127. end.