(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTScreenCanvas;

interface
uses
  SysUtils,Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, AHMEnhancedClass;

type
  TAHMScreenCanvas = class(TComponent)
  private
    FAHMAboutStr : TAHMAboutEnhancedStr;
    FCanvas: TCanvas;
    FSaveBack: Boolean;
    isPainting: Boolean;
    function GetWidth : Integer;
    function GetHeight : Integer;
  protected
    function GetCanvas:TCanvas;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure BeginPaint;
    procedure EndPaint;
    procedure RestoreScreen;
    property Canvas: TCanvas read GetCanvas;
    property Height: Integer read GetHeight;
    property Width: Integer read GetWidth;
  published
    property About : TAHMAboutEnhancedStr read FAHMAboutStr write FAHMAboutStr stored False;
    property AutoRestore: Boolean read FSaveBack write FSaveBack default false;
  end;


implementation

function TAHMScreenCanvas.GetWidth : Integer;
begin
   result:=Screen.Width;
end;
function TAHMScreenCanvas.GetHeight : Integer;
begin
   result:=Screen.Height;
end;

function TAHMScreenCanvas.GetCanvas:TCanvas;
begin
  if not isPainting then Beginpaint;
  Result:=FCanvas;
end;

constructor TAHMScreenCanvas.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  FSaveBack:=False;
end;

destructor TAHMScreenCanvas.Destroy;
begin
  EndPaint;
  inherited Destroy;
end;

procedure TAHMScreenCanvas.BeginPaint;
var DC: HDC;
begin
  if isPainting then exit;
  FCanvas:=TCanvas.Create;
  DC:=GetDC(0);
  FCanvas.Handle:=DC;
  isPainting:=True;
end;

procedure TAHMScreenCanvas.EndPaint;
begin
  if not isPainting then exit;
  ReleaseDC(0, FCanvas.Handle);
  FCanvas.Free;
  isPainting:=False;
  if AutoRestore then InvalidateRect(0,nil, true);
end;

procedure TAHMScreenCanvas.RestoreScreen;
begin
  InvalidateRect(0,nil, true);
end;


end.
