home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
cprog
/
blx21.zip
/
OWLPRT.ARJ
/
PRTPAS.ARJ
/
RULER.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-12-12
|
5KB
|
190 lines
{************************************************}
{ }
{ Turbo Pascal for Windows }
{ RULER.PAS }
{ Copyright (c) 1991 by Borland International }
{ Author: Tom Swan }
{ }
{************************************************}
{$R ruler.res}
program Ruler;
uses WinTypes, WinProcs, WObjects, Strings, Printer, IDs;
type
TRulerApp = object(TApplication)
procedure InitMainWindow; virtual;
end;
PRulerWin = ^TRulerWin;
TRulerWin = object(TWindow)
Printer: PPrinter; { Pointer to a TPrinter object }
constructor Init(AParent: PWindowsObject; ATitle: PChar);
destructor Done; virtual;
procedure CMFilePrint(var Msg: TMessage);
virtual cm_First + cm_FilePrint;
procedure CMFilePrinterSetup(var Msg: TMessage);
virtual cm_First + cm_FilePrinterSetup;
procedure CMFileExit(var Msg: TMessage);
virtual cm_First + cm_FileExit;
procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
virtual;
end;
PRulerOut = ^TRulerOut;
TRulerOut = object(TPrintout)
procedure PrintPage(DC: HDC; Page: Word; Size: TPoint;
var Rect: TRect; Flags: Word); virtual;
end;
{ Display or print a ruler }
procedure ShowRuler(DC: HDC);
const
UnitsPerInch = 100; { Display scale 0.01 inches per unit }
NumInches = 6; { Size of ruler in inches }
MarksPerInch = 4; { Number of markers for each inch }
LargeMarkerSize = Round(0.50 * UnitsPerInch); { Size of labeled markers }
SmallMarkerSize = Round(0.25 * UnitsPerInch); { Size of small markers }
var
I: Integer; { For-loop control variable }
X, X1, Y1, X2, Y2: Integer; { Coordinates for displaying ruler }
S: array[0 .. 2] of Char; { Holds ruler digits in text form }
begin
SaveDC(DC);
SetMapMode(DC, mm_LoEnglish);
X1 := Round(0.50 * UnitsPerInch);
Y1 := X1;
X2 := X1 + Round(NumInches * UnitsPerInch);
Y2 := Y1 + Round(1 * UnitsPerInch);
Rectangle(DC, X1, -Y1, X2, -Y2);
Y2 := Y1 + LargeMarkerSize;
for I := 1 to NumInches - 1 do
begin
X := X1 + (I * UnitsPerInch);
MoveTo(DC, X, -Y1);
LineTo(DC, X, -Y2);
Str(I, S);
TextOut(DC, X, -Y2, S, StrLen(S));
end;
Y2 := Y1 + SmallMarkerSize;
for I := 0 to ((NumInches * MarksPerInch) - 1) do
begin
X := X1 + ((I * UnitsPerInch) div MarksPerInch);
MoveTo(DC, X, -Y1);
LineTo(DC, X, -Y2);
end;
RestoreDC(DC, -1);
end;
{ TRulerApp }
{ Initialize TRulerApp's main window }
procedure TRulerApp.InitMainWindow;
begin
MainWindow := New(PRulerWin, Init(nil, 'Ruler Demonstration'));
end;
{ TRulerWin }
{ Construct a TRulerWin object }
constructor TRulerWin.Init(AParent: PWindowsObject; ATitle: PChar);
begin
TWindow.Init(AParent, ATitle);
with Attr do
begin
Menu := LoadMenu(HInstance, PChar(id_Menu));
X := GetSystemMetrics(sm_CXScreen) div 8;
Y := GetSystemMetrics(sm_CYScreen) div 8;
H := Y * 6;
W := X * 6;
end;
Printer := New(PPrinter, Init);
end;
{ Destroy a TRulerWin object }
destructor TRulerWin.Done;
begin
Dispose(Printer, Done);
TWindow.Done;
end;
{ Execute File:Print command }
procedure TRulerWin.CMFilePrint(var Msg: TMessage);
var
Printout: PRulerOut;
begin
if Printer <> nil then
begin
Printout := New(PRulerOut, Init('Ruler Test'));
if Printout <> nil then
begin
Printout^.Banding := true;
Printer^.Print(@Self, Printout);
Dispose(Printout, Done);
end;
end;
end;
{ Execute File:Printer-setup command }
procedure TRulerWin.CMFilePrinterSetup(var Msg: TMessage);
begin
if Printer <> nil then Printer^.Setup(@Self);
end;
{ Execute File:Exit command }
procedure TRulerWin.CMFileExit(var Msg: TMessage);
begin
CloseWindow;
end;
{ Paint window's contents on screen }
procedure TRulerWin.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
begin
ShowRuler(PaintDC);
end;
{ TRulerOut }
{ Print page (or pages) }
procedure TRulerOut.PrintPage(DC: HDC; Page: Word; Size: TPoint;
var Rect: TRect; Flags: Word);
begin
ShowRuler(DC);
end;
var
RulerApp: TRulerApp;
begin
RulerApp.Init('Ruler');
RulerApp.Run;
RulerApp.Done;
end.