'GetDeviceCaps'에 해당되는 글 3건
- 2007/09/11 TDesktopCanvas - draw on Windows Desktop
- 2007/09/11 How to Convert Pixels to Millimeters
- 2007/09/11 How to capture Windows Desktop to Bitmap
type
TDesktopCanvas = class(TCanvas)
private
DC : hDC;
function GetWidth:Integer;
function GetHeight:Integer;
public
constructor Create;
destructor Destroy; override;
published
property Width: Integer read GetWidth;
property Height: Integer read GetHeight;
end;
{ TDesktopCanvas object }
function TDesktopCanvas.GetWidth:Integer;
begin
Result:GetDeviceCaps(Handle,HORZRES) ;
end;
function TDesktopCanvas.GetHeight:Integer;
begin
Result:=GetDeviceCaps(Handle,VERTRES) ;
end;
constructor TDesktopCanvas.Create;
begin
inherited Create;
DC := GetDC(0) ;
Handle := DC;
end;
destructor TDesktopCanvas.Destroy;
begin
Handle := 0;
ReleaseDC(0, DC) ;
inherited Destroy;
end;
TDesktopCanvas = class(TCanvas)
private
DC : hDC;
function GetWidth:Integer;
function GetHeight:Integer;
public
constructor Create;
destructor Destroy; override;
published
property Width: Integer read GetWidth;
property Height: Integer read GetHeight;
end;
{ TDesktopCanvas object }
function TDesktopCanvas.GetWidth:Integer;
begin
Result:GetDeviceCaps(Handle,HORZRES) ;
end;
function TDesktopCanvas.GetHeight:Integer;
begin
Result:=GetDeviceCaps(Handle,VERTRES) ;
end;
constructor TDesktopCanvas.Create;
begin
inherited Create;
DC := GetDC(0) ;
Handle := DC;
end;
destructor TDesktopCanvas.Destroy;
begin
Handle := 0;
ReleaseDC(0, DC) ;
inherited Destroy;
end;
The code uses the API functionGetDeviceCaps to get the metrics you need.
procedure PixelsPerMM(
canvas: TCanvas;
var x, y: single) ;
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;
end;
canvas: TCanvas;
var x, y: single) ;
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;
end;
procedure ScreenShot(DestBitmap : TBitmap) ;
var
DC : HDC;
begin
DC :=GetDC GetDesktopWindow) ;
try
DestBitmap.Width :=GetDeviceCaps (DC, HORZRES) ;
DestBitmap.Height := GetDeviceCaps (DC, VERTRES) ;
BitBlt(DestBitmap.Canvas.Handle,
0,
0,
DestBitmap.Width,
DestBitmap.Height,
DC,
0,
0,
SRCCOPY) ;
finally
ReleaseDC (GetDesktopWindow, DC) ;
end;
end;
var
DC : HDC;
begin
DC :=GetDC GetDesktopWindow) ;
try
DestBitmap.Width :=GetDeviceCaps (DC, HORZRES) ;
DestBitmap.Height := GetDeviceCaps (DC, VERTRES) ;
BitBlt(DestBitmap.Canvas.Handle,
0,
0,
DestBitmap.Width,
DestBitmap.Height,
DC,
0,
0,
SRCCOPY) ;
finally
ReleaseDC (GetDesktopWindow, DC) ;
end;
end;

Prev

Rss Feed