unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure PixelsPerMM(canvas: TCanvas;
var x, y: Extended);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
myscreenWidth, myscreenHeight :Extended;
implementation
{$R *.dfm}
procedure TForm1.PixelsPerMM(canvas: TCanvas;
var x, y: Extended);
var
H:HDC;
hres,vres,
hsiz,vsiz:integer;
begin
H:=canvas.handle;
hres := GetDeviceCaps(H,HORZRES) ;
{display width in pixels}
vres := GetDeviceCaps(H,VERTRES) ;
{display height in pixels}
hsiz := GetDeviceCaps(H,HORZSIZE) ;
{display width in mm}
vsiz := GetDeviceCaps(H,VERTSIZE) ;
{display height in mm}
x := hres/hsiz;
y := vres/vsiz;
myscreenWidth:=screen.Width/x;
// in mm
myscreenheight:=screen.Width/y;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
X, Y: Extended;
begin
PixelsPerMM(Form1.Canvas, X, Y);
Edit1.Text := FloatToStr(X);
{ the x value holds the pixels per mm horizontally }
Edit2.Text := FloatToStr(Y);
{ the y value holds the pixels per mm vertically }
Edit3.Text:=FloatToStr(myscreenWidth);
Edit4.Text:=FloatToStr(myscreenheight);
end;
end.