Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <Printers.hpp>
  4. #include <math.h>
  5. #pragma hdrstop
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TForm1::Button1Click(TObject *Sender)
  18. {
  19.   Printer()->BeginDoc();
  20.   PaintTo(Printer()->Handle, 10, 10);
  21.   Printer()->EndDoc();
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::Button2Click(TObject *Sender)
  25. {
  26.   TRect rect;
  27.   int px,py;
  28.   double aa;
  29.   Graphics::TBitmap *bmp = new Graphics::TBitmap();
  30.   px=GetDeviceCaps(Printer()->Handle,LOGPIXELSX);
  31.   py=GetDeviceCaps(Printer()->Handle,LOGPIXELSY);
  32.   bmp->Width=Width;
  33.   bmp->Height=Height;
  34. //  bmp->Canvas->MoveTo(10,10);
  35. //  bmp->Canvas->LineTo(100,100);
  36. //  bmp->LoadFromFile("c:\te\bmp.bmp");
  37.   PaintTo(bmp->Handle, 0, 0);
  38.   bmp->SaveToFile("c:\te\bmp1.bmp");
  39.   rect.Left=20;
  40.   rect.Top=20;
  41.   aa=px;
  42.   aa=aa/96;
  43.   aa=aa*Width;
  44.   rect.Right=floor(aa);
  45.   aa=py;
  46.   aa=aa/96;
  47.   aa=aa*Height;
  48.   rect.Bottom=floor(aa);
  49. //  Printer()->BeginDoc();
  50. //  StretchBlt(Printer()->Handle,20,20,rect.right,rect.bottom,this,0,0,Width,Height,SRCCOPY);
  51. //  Printer()->Canvas->StretchDraw(rect,bmp);
  52. //  Printer()->EndDoc();
  53.   delete bmp;
  54. }
  55. //---------------------------------------------------------------------------