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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <printers.hpp>
  6. #pragma hdrstop
  7. #include "Unit1.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14.         : TForm(Owner)
  15. {
  16. }
  17. //---------------------------------------------------------------------------
  18. void __fastcall TForm1::Button1Click(TObject *Sender)
  19. {
  20.   int offx,offy,dpix,dpiy;
  21.   double left,top,right,bottom,aa;
  22.   int xx1,xx2,yy1,yy2;
  23.   dpix=GetDeviceCaps(Printer()->Handle,LOGPIXELSX);
  24.   dpiy=GetDeviceCaps(Printer()->Handle,LOGPIXELSY);
  25.   offx=GetDeviceCaps(Printer()->Handle,PHYSICALOFFSETX);
  26.   offy=GetDeviceCaps(Printer()->Handle,PHYSICALOFFSETY);
  27.   left=2.5;top=3.2;
  28.   right=15;bottom=8.7;
  29.   aa=left/2.54;
  30.   aa=aa*dpix;
  31.   xx1=floor(aa)-offx;
  32.   aa=right/2.54;
  33.   aa=aa*dpix;
  34.   xx2=floor(aa)-offx;
  35.   aa=top/2.54;
  36.   aa=aa*dpiy;
  37.   yy1=floor(aa)-offy;
  38.   aa=bottom/2.54;
  39.   aa=aa*dpiy;
  40.   yy2=floor(aa)-offy;
  41.   Printer()->BeginDoc();
  42.   Printer()->Canvas->Rectangle(xx1,yy1,xx2,yy2);
  43.   Printer()->EndDoc();
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TForm1::Button2Click(TObject *Sender)
  47. {
  48.   int nn;
  49.   char dvc[255],drv[255],port[255];
  50.   THandle h;
  51.   TDeviceMode *DevMode;
  52.   Printer()->GetPrinter(dvc,drv,port,h);
  53.   if(h==0)return;
  54.   DevMode=(TDeviceMode *)GlobalLock((void*)h);
  55.   nn=atoi(Edit1->Text.c_str());
  56.   if(nn>100)nn=100;
  57.   if(nn<10)nn=10;
  58.   DevMode->dmFields=DevMode->dmFields|DM_SCALE;
  59.   DevMode->dmScale=(short)nn;
  60.   GlobalUnlock((void*)h);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::Button3Click(TObject *Sender)
  64. {
  65.   char dvc[255],drv[255],port[255];
  66.   THandle h;
  67.   TDeviceMode *DevMode;
  68.   Printer()->GetPrinter(dvc,drv,port,h);
  69.   if(h==0)return;
  70.   DevMode=(TDeviceMode *)GlobalLock((void*)h);
  71.   DevMode->dmFields=DevMode->dmFields|DM_COLOR;
  72.   DevMode->dmColor=DMCOLOR_MONOCHROME;
  73. //  DevMode->dmColor=DMCOLOR_COLOR;
  74.   GlobalUnlock((void*)h);
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::Button4Click(TObject *Sender)
  78. {
  79.   char dvc[255],drv[255],port[255];
  80.   THandle h;
  81.   TDeviceMode *DevMode;
  82.   Printer()->GetPrinter(dvc,drv,port,h);
  83.   if(h==0)return;
  84.   DevMode=(TDeviceMode *)GlobalLock((void*)h);
  85.   DevMode->dmFields=DevMode->dmFields|DM_PRINTQUALITY;
  86.   DevMode->dmPrintQuality=DMRES_HIGH;
  87. //DMRES_HIGH
  88. //DMRES_MEDIUM
  89. //DMRES_LOW
  90. //DMRES_DRAFT
  91.   GlobalUnlock((void*)h);
  92. }
  93. //---------------------------------------------------------------------------