'GetDeviceCaps'에 해당되는 글 3건

  1. 2007/09/11 TDesktopCanvas - draw on Windows Desktop
  2. 2007/09/11 How to Convert Pixels to Millimeters
  3. 2007/09/11 How to capture Windows Desktop to Bitmap
2007/09/11 08:01

TDesktopCanvas - draw on Windows Desktop

This canvas class allows you to access the Windows Desktop, and draw on it.

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;
Trackback 0 Comment 0
2007/09/11 07:44

How to Convert Pixels to Millimeters

If you need to convert pixel value to millimeters (inches, centimeters, etc.) use the code provided here.

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;
Trackback 0 Comment 0
2007/09/11 07:43

How to capture Windows Desktop to Bitmap

Here's a piece of Delphi code capable of capturing the Windows Desktop image into a TBitmap object:

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;
Trackback 0 Comment 0