?? invalidatergntu.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 + -