⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invalidatergntu.pas

📁 Delphi Win32核心API参考光盘源码 本书包含了常用的Windows API函数
💻 PAS
字号:
unit InvalidateRgntU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button2: TButton;
    Image1: TImage;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
var
  PointsArray: array[0..2] of TPoint; // an array of points defining the region
  RegionHandle: HRGN;                 // a handle to the region
begin
  {define the region}
  PointsArray[0].X := 20;
  PointsArray[0].y := 20;
  PointsArray[1].x := 100;
  PointsArray[1].y := 65;
  PointsArray[2].x := 20;
  PointsArray[2].y := 120;

  {create the region}
  RegionHandle := CreatePolygonRgn(PointsArray, 3, ALTERNATE);

  {invalidate the region}
  InvalidateRgn(Form1.Handle, RegionHandle, TRUE);

  {the region is no longer needed, so delete it}
  DeleteObject(RegionHandle);
end;

procedure TForm1.WMPaint(var Msg: TWMPaint);
var
  InvalidRgn: HRGN;          // a handle to the invalid region
  PaintStruct: TPaintStruct; // holds painting information
begin
  {GetUpdateRgn requires a handle to a pre-existing region, so create one}
  InvalidRgn := CreateRectRgn(0, 0, 1, 1);

  {retrieve the handle to the update region}
  GetUpdateRgn(Handle, InvalidRgn, FALSE);

  {begin the painting operation}
  BeginPaint(Handle, PaintStruct);

  {if the region is equal to the entire client area...}
  if EqualRgn(InvalidRgn, CreateRectRgnIndirect(ClientRect)) then
    {...draw the bitmap in Image1 to the form's canvas}
    Canvas.Draw(0, 0, Image1.Picture.Bitmap)
  else
  begin
    {...otherwise draw the invalid region in red}
    Canvas.Brush.Color := clRed;
    FillRgn(Canvas.Handle, InvalidRgn, Canvas.Brush.Handle);
  end;

  {end the painting operation}
  EndPaint(Handle, PaintStruct);

  {delete the region object, as it is no longer needed}
  DeleteObject(InvalidRgn);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -