程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> WinAPI: SelectClipRgn、ExtSelectClipRgn、SelectClipPath - 定義剪切區域

WinAPI: SelectClipRgn、ExtSelectClipRgn、SelectClipPath - 定義剪切區域

編輯:Delphi

 剪切區域也是區域的一種, 窗口在重繪時只會重繪剪切區域中的內容.

  SelectClipRgn 和 ExtSelectClipRgn 是通過指定區域來定義剪切區域;

  SelectClipPath 是通過指定路徑來定義剪切區域;

  ExtSelectClipRgn 和 SelectClipPath 比 SelectClipRgn 多出一個與原剪切區域混合方式的參數:

RGN_AND = 1; 
RGN_OR  = 2; 
RGN_XOR = 3; 
RGN_DIFF = 4; 
RGN_COPY = 5; 

  本例效果圖:

WinAPI: SelectClipRgn、ExtSelectClipRgn、SelectClipPath - 定義剪切區域

  代碼文件:

unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls, ExtCtrls; 
 
type 
 TForm1 = class(TForm) 
  RadioGroup1: TRadioGroup; 
  procedure FormCreate(Sender: TObject); 
  procedure FormDestroy(Sender: TObject); 
  procedure FormPaint(Sender: TObject); 
  procedure RadioGroup1Click(Sender: TObject); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
var 
 bit: TBITMAP; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
 RadioGroup1.Caption := '定義剪切區域'; 
 RadioGroup1.Items.CommaText := '無剪切區域,根據區域,根據路徑'; 
 RadioGroup1.ItemIndex := 0; 
 
 bit := TBitmap.Create; 
 bit.LoadFromFile('c:\temp\Test.bmp'); 
end; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Rgn: HRGN; 
begin 
 case RadioGroup1.ItemIndex of 
  1: begin 
     Rgn := CreateEllipticRgn(30,30,140,140); 
     SelectClipRgn(Canvas.Handle, Rgn); 
     DeleteObject(Rgn); 
    end; 
  2: begin 
     Canvas.Font.Size := 160; 
     Canvas.Font.Style := [fsBold]; 
     SetBkMode(Canvas.Handle, TRANSPARENT); 
     BeginPath(Canvas.Handle); 
     Canvas.TextOut(-15,-30,'A'); 
     EndPath(Canvas.Handle); 
     SelectClipPath(Canvas.Handle, RGN_COPY); 
    end; 
 end; 
 
 Canvas.Draw(0,0,bit); 
end; 
 
procedure TForm1.RadioGroup1Click(Sender: TObject); 
begin 
 Repaint; 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
 bit.Free; 
end; 
 
end. 

  窗體文件:

object Form1: TForm1 
 Left = 366 
 Top = 307 
 Caption = 'Form1' 
 ClIEntHeight = 206 
 ClIEntWidth = 309 
 Color = clBtnFace 
 Font.Charset = DEFAULT_CHARSET 
 Font.Color = clWindowText 
 Font.Height = -11 
 Font.Name = 'Tahoma' 
 Font.Style = [] 
 OldCreateOrder = False 
 Position = poDesigned 
 OnCreate = FormCreate 
 OnDestroy = FormDestroy 
 OnPaint = FormPaint 
 PixelsPerInch = 96 
 TextHeight = 13 
 object RadioGroup1: TRadioGroup 
  Left = 209 
  Top = 93 
  Width = 95 
  Height = 105 
  Caption = 'RadioGroup1' 
  TabOrder = 0 
  OnClick = RadioGroup1Click 
 end 
end 


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