程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi圖象截取編程示例(7)

Delphi圖象截取編程示例(7)

編輯:Delphi

  (七)抓取窗體或控件圖片窗體
  創建一個新的Form2,保存為Capture2.pas。設置屬性BorderIcons的四個屬性為false.
  BorderStyle設為bsNone,FormStyle設為fsStayOnTop.
  兩個公共變量:fRect:TRect,fBmp:TBitmap;

  unit Capture2;

  interface

  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs;

  type
    TForm2 = class(TForm)
      procedure FormCreate(Sender: TObject);
      procedure ForMactivate(Sender: TObject);
      procedure FormDestroy(Sender: TObject);
      procedure FormPaint(Sender: TObject);
      procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
    private
      { Private declarations }
    public
      fRect:TRect;
      fBmp:TBitmap;
    end;

  var
    Form2: TForm2;

  implementation

  {$R *.dfm}

  //創建一個新的自定義光標CURSOR_1,放在Capture2.res資源
  //文件中.是32*32的白色矩形邊框,用來指示抓圖的范圍.

  procedure TForm2.FormCreate(Sender: TObject);
  var aDC:HDC;
  const crHand = -18;
  begin
    Screen.Cursors[crHand]:=LoadCursor(hInstance,'CURSOR_1');
    Cursor:=crHand;
    fBmp:= TBitmap.Create ;
    fBmp.Width := Screen.Width ;
    fBmp.Height:= Screen.Height ;
    aDC := GetDC(0);
    BitBlt(fBmp.Canvas.Handle,0,0,Screen.Width,Screen.Height,aDC,0,0,srcCopy);
    ReleaseDC(0,aDC);
    SetBounds(0,0,Screen.Width,Screen.Height);
  end;

  procedure TForm2.ForMactivate(Sender: TObject);
  const crHand=-18;
  begin
    Screen.Cursors[crHand]:=LoadCursor(hInstance,pChar('CURSOR_1'));
    Cursor:=crHand;
  end;

  procedure TForm2.FormDestroy(Sender: TObject);
  begin
    fBmp.Free;
    Screen.Cursor := crDefault;
  end;

  procedure TForm2.FormPaint(Sender: TObject);
  begin
    Canvas.Draw(0,0,fBmp);
  end;

  procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
    ModalResult:=mrOK;
  end;

  end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved