Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <math.h>
- #include <stdlib.h>
- #include <printers.hpp>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- int offx,offy,dpix,dpiy;
- double left,top,right,bottom,aa;
- int xx1,xx2,yy1,yy2;
- dpix=GetDeviceCaps(Printer()->Handle,LOGPIXELSX);
- dpiy=GetDeviceCaps(Printer()->Handle,LOGPIXELSY);
- offx=GetDeviceCaps(Printer()->Handle,PHYSICALOFFSETX);
- offy=GetDeviceCaps(Printer()->Handle,PHYSICALOFFSETY);
- left=2.5;top=3.2;
- right=15;bottom=8.7;
- aa=left/2.54;
- aa=aa*dpix;
- xx1=floor(aa)-offx;
- aa=right/2.54;
- aa=aa*dpix;
- xx2=floor(aa)-offx;
- aa=top/2.54;
- aa=aa*dpiy;
- yy1=floor(aa)-offy;
- aa=bottom/2.54;
- aa=aa*dpiy;
- yy2=floor(aa)-offy;
- Printer()->BeginDoc();
- Printer()->Canvas->Rectangle(xx1,yy1,xx2,yy2);
- Printer()->EndDoc();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- int nn;
- char dvc[255],drv[255],port[255];
- THandle h;
- TDeviceMode *DevMode;
- Printer()->GetPrinter(dvc,drv,port,h);
- if(h==0)return;
- DevMode=(TDeviceMode *)GlobalLock((void*)h);
- nn=atoi(Edit1->Text.c_str());
- if(nn>100)nn=100;
- if(nn<10)nn=10;
- DevMode->dmFields=DevMode->dmFields|DM_SCALE;
- DevMode->dmScale=(short)nn;
- GlobalUnlock((void*)h);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- char dvc[255],drv[255],port[255];
- THandle h;
- TDeviceMode *DevMode;
- Printer()->GetPrinter(dvc,drv,port,h);
- if(h==0)return;
- DevMode=(TDeviceMode *)GlobalLock((void*)h);
- DevMode->dmFields=DevMode->dmFields|DM_COLOR;
- DevMode->dmColor=DMCOLOR_MONOCHROME;
- // DevMode->dmColor=DMCOLOR_COLOR;
- GlobalUnlock((void*)h);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- char dvc[255],drv[255],port[255];
- THandle h;
- TDeviceMode *DevMode;
- Printer()->GetPrinter(dvc,drv,port,h);
- if(h==0)return;
- DevMode=(TDeviceMode *)GlobalLock((void*)h);
- DevMode->dmFields=DevMode->dmFields|DM_PRINTQUALITY;
- DevMode->dmPrintQuality=DMRES_HIGH;
- //DMRES_HIGH
- //DMRES_MEDIUM
- //DMRES_LOW
- //DMRES_DRAFT
- GlobalUnlock((void*)h);
- }
- //---------------------------------------------------------------------------