clnMain.pas
上传用户:juxian
上传日期:2013-04-01
资源大小:38k
文件大小:3k
源码类别:

驱动编程

开发平台:

Delphi

  1. unit clnMain;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   ScrSpy, Menus;
  6. type
  7.   TForm1 = class(TForm)
  8.     ScreenPlayer1: TScreenPlayer;
  9.     PopupMenu1: TPopupMenu;
  10.     FullScreen1: TMenuItem;
  11.     Restore1: TMenuItem;
  12.     procedure ScreenPlayer1HeaderUpdate(Sender: TObject);
  13.     procedure ScreenPlayer1ScreenBitmap(Sender: TObject;
  14.       const Block: TScreenBlock);
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure ScreenPlayer1FrameEnd(Sender: TObject;
  17.       const FrameCount: Cardinal; const IsIFrame, HasBitmapEvent: Boolean);
  18.     procedure FormResize(Sender: TObject);
  19.     procedure FullScreen1Click(Sender: TObject);
  20.     procedure Restore1Click(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.     XRate, YRate: Extended;
  24.     HasServer: Boolean;
  25.     BMP: array of TBitmap;
  26.     BMPBound: array of TRect;
  27.     Updated: array of Boolean;
  28.     Count: Integer;
  29.   public
  30.     { Public declarations }
  31.   end;
  32. var
  33.   Form1: TForm1;
  34. implementation
  35. {$R *.DFM}
  36. procedure TForm1.ScreenPlayer1HeaderUpdate(Sender: TObject);
  37. Var
  38.   i: Integer;
  39. begin
  40.   HasServer:= True;
  41.   XRate:= ClientWidth / ScreenPlayer1.ScreenWidth;
  42.   YRate:= ClientHeight / ScreenPlayer1.ScreenHeight;
  43.   For i:=0 to Count-1 do
  44.     BMP[i].Free;
  45.   Count:= ScreenPlayer1.BlockCount;
  46.   SetLength(BMP, Count);
  47.   SetLength(Updated, Count);
  48.   SetLength(BMPBound, Count);
  49.   For i:=0 to Count-1 do
  50.   Begin
  51.     BMP[i]:= TBitmap.Create;
  52.     BMP[i].HandleType:= bmDIB;
  53.     BMP[i].Width:= ScreenPlayer1.ScreenWidth;
  54.     BMP[i].Height:= ScreenPlayer1.ScreenHeight;
  55.     BMP[i].PixelFormat:= ScreenPlayer1.PixelFormat;
  56.   End;
  57. end;
  58. procedure TForm1.ScreenPlayer1ScreenBitmap(Sender: TObject;
  59.   const Block: TScreenBlock);
  60. begin
  61.   BMP[Block.BlockIndex].Assign(Block.BMP);
  62.   BMPBound[Block.BlockIndex]:= Block.Bound;
  63.   Updated[Block.BlockIndex]:= True;
  64. end;
  65. procedure TForm1.FormCreate(Sender: TObject);
  66. begin
  67.   HasServer:= False;
  68.   Count:= 0;
  69. end;
  70. procedure TForm1.ScreenPlayer1FrameEnd(Sender: TObject;
  71.   const FrameCount: Cardinal; const IsIFrame, HasBitmapEvent: Boolean);
  72. Var
  73.   i: Integer;
  74.   R: TRect;
  75. begin
  76.   If HasBitmapEvent then
  77.   Begin
  78.     For i:=0 to Count-1 do
  79.       If Updated[i] then
  80.       Begin
  81.         R:= Rect(Round(BMPBound[i].Left*XRate), Round(BMPBound[i].Top*YRate), Round(BMPBound[i].Right*XRate), Round(BMPBound[i].Bottom*YRate));
  82.         Canvas.StretchDraw(R, BMP[i]);
  83.         Updated[i]:= False;
  84.       End;
  85.   End;
  86. end;
  87. procedure TForm1.FormResize(Sender: TObject);
  88. begin
  89.   If HasServer then
  90.   Begin
  91.     XRate:= ClientWidth / ScreenPlayer1.ScreenWidth;
  92.     YRate:= ClientHeight / ScreenPlayer1.ScreenHeight;
  93.   End;
  94. end;
  95. procedure TForm1.FullScreen1Click(Sender: TObject);
  96. begin
  97.   BorderStyle:= bsNone;
  98.   WindowState:= wsMaximized;
  99. end;
  100. procedure TForm1.Restore1Click(Sender: TObject);
  101. begin
  102.   BorderStyle:= bsSizeable;
  103.   WindowState:= wsNormal;
  104. end;
  105. end.