GDIdemo: Delphi Version
{*****************************************************************************
* *
* GDIdemo.dpr *
* GDIdemoU.pas *
* *
* This program shows how to use Windows GDI functions to write to a virtual *
* buffer. It uses GDI functions to display a cross-hatched rectangle with a *
* border, something that would require construction from several graphics *
* primitives if using Fastgraph for Windows drawing functions only. *
* *
*****************************************************************************}
unit GDIdemoU;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, FGWin;
type
TForm1 = class(TForm)
procedure AppOnActivate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
dc : hDC;
hPal : hPalette;
hVB : integer;
cxClient, cyClient : integer;
procedure TForm1.AppOnActivate(Sender: TObject);
begin
fg_realize(hPal);
Invalidate;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
fg_realize(hPal);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Brush : hBrush;
hDIB : hDC;
Pen : hPen;
begin
dc := GetDC(Form1.Handle);
fg_setdc(dc);
hPal := fg_defpal;
fg_realize(hPal);
fg_vbinit;
hVB := fg_vballoc(320,240);
fg_vbopen(hVB);
fg_vbcolors;
{ use FG to fill the virtual buffer with light green pixels }
fg_setcolor(20);
fg_fillpage;
{ use Windows GDI functions to display a cross-hatched
rectangle with blue border in the virtual buffer }
hDIB := fg_getdc;
Pen := CreatePen(PS_SOLID,3,RGB(0,0,255));
Brush := CreateHatchBrush(HS_DIAGCROSS,RGB(255,0,0));
SelectObject(hDIB,Pen);
SelectObject(hDIB,Brush);
Rectangle(hDIB,20,20,50,50);
DeleteObject(Pen);
DeleteObject(Brush);
Application.OnActivate := AppOnActivate;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
fg_vbscale(0,fg_getmaxx,0,fg_getmaxy,0,cxClient-1,0,cyClient-1);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
cxClient := ClientWidth;
cyClient := ClientHeight;
Invalidate;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
fg_vbclose;
fg_vbfree(hVB);
fg_vbfin;
DeleteObject(hPal);
ReleaseDC(Form1.Handle,dc);
end;
end.
|