Devices

Set monitor into standby mode

Posted in Devices

To place a monitor into standby mode use WM_SYSCOMMAND message:

procedure TForm1.Button1Click(Sender: TObject);
begin
  SendMessage(Application.Handle,WM_SYSCOMMAND,SC_MONITORPOWER,2);
end;

Print exact sizes

Posted in Devices

his example shows how to print a bitmap with specified printing area.

uses Printers;
...
procedure TForm1.Button1Click(Sender: TObject);
var
  Rec: TRect;
  Rate: Double;
begin
  Image1.Picture.LoadFromFile('factory.bmp');
  Rate:=Image1.Picture.Height/Image1.Picture.Width;
  Rec:=Rect(
    5,
    5,
    Printer.PageWidth-5,
    Trunc(Printer.PageHeight*Rate-
      GetDeviceCaps(Printer.Handle,LOGPIXELSX))-5);
  Printer.BeginDoc;
  Printer.Canvas.StretchDraw(Rec,Image1.Picture.Graphic);
  Printer.EndDoc;
end;

Print a bitmap

Posted in Devices

This example shows how to print a bitmap.

uses Printers;
...
procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap;
begin
  BitMap:=TBitmap.Create;
  BitMap.LoadFromFile('factory.bmp');
  with Printer do
  begin
    BeginDoc;
    Canvas.Draw(25,25,BitMap);
    EndDoc;
  end;
  BitMap.Free;
end;

Print QuickRep on different paper size

Posted in Devices

PaperSize can be set to any of the following values: Letter, LetterSmall, Tabloid, Ledger, Legal, Statement, Executive, A3, A4, A4Small, A5, B4, B5, Folio, Quarto, qr10X14, qr11X17, Note, Env9, Env10, Env11, Env12, Env14, CSheet, DSheet, and ESheet. These formats are all the default paper sizes defined in Windows. Selecting a paper size will automatically be reflected in the PaperLength and PaperWidth properties. You can also set PaperSize to Custom and select any PaperLength and PaperWidth you want. Note that not all printers support all paper sizes. Also, many printers does not support custom paper size or can only have custom size within certain values. If you select a paper size not supported by a printer QuickReport will automatically switch to the default paper size when preparing the report. The default paper size is selected in the printer driver setup. This example shows how we can change PaperLength and PaperWidth properties with Custom parameter in the PaperSize property.

procedure TForm1.Button1Click(Sender: TObject);
begin
  QuickRep1.Preview;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  QuickRep1.Page.Length:=StrToInt(Edit1.Text);
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
  QuickRep1.Page.Width:=StrToInt(Edit1.Text);
end;

Play a wav-file

Posted in Devices

Use PlaySound function. For example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  PlaySound(PChar('yes.wav'), 0, SND_SYNC);
end;

Related chapters
    Resource