📄 privatedcu.pas
字号:
unit PrivateDcU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams); override;
end;
var
Form1: TForm1;
NewBrush, // a handle to a new brush
OldBrush: HBRUSH; // holds the old brush
implementation
{$R *.DFM}
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
{initialize the parameters with default values}
inherited CreateParams(Params);
{indicate that this window should have its own device context. comment
this line out to see the effects}
Params.WindowClass.style := Params.WindowClass.Style or CS_OWNDC;
end;
procedure TForm1.FormActivate(Sender: TObject);
var
TempDC: HDC; // a temporary device context handle
begin
{retrieve a handle to the private device context for this window}
TempDC := GetDC(Form1.Handle);
{create a new brush and select it into this device context}
NewBrush := CreateHatchBrush(HS_DIAGCROSS, clRed);
OldBrush := SelectObject(TempDC, NewBrush);
{release the device context. note that since we are dealing with a private
device context, the new brush will remain within the device context.}
ReleaseDC(Form1.Handle, TempDC);
end;
procedure TForm1.FormPaint(Sender: TObject);
var
TempDC: HDC; // a temporary device context handle
begin
{retrieve a handle to the private device context}
TempDC := GetDC(Form1.Handle);
{draw a rectangle. note that we are not creating a new brush, so the
rectangle should be filled with the default brush selected in a device
context. since this is a private device context, it will use the brush
previously selected to fill the rectangle}
Rectangle(TempDC, 0, 0, ClientWidth, ClientHeight);
{release the device context}
ReleaseDC(Form1.Handle, TempDC);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{delete the brush}
SelectObject(GetDC(Form1.Handle), OldBrush);
DeleteObject(NewBrush);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -