Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.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 ll,ww;
- char dvc[255],drv[255],port[255];
- // AnsiString dvc,drv,port;
- THandle h;
- TDeviceMode *DevMode;
- // Printer()->GetPrinter(dvc.c_str(),drv.c_str(),port.c_str(),h);
- Printer()->GetPrinter(dvc,drv,port,h);
- if(h==0)return;
- Edit1->Text=dvc;
- Edit2->Text=drv;
- Edit3->Text=port;
- DevMode=(TDeviceMode *)GlobalLock((void*)h);
- DevMode->dmFields=DevMode->dmFields|DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;//改变长度与宽度
- DevMode->dmPaperSize=DMPAPER_USER;//采用自定义纸张
- //注意,此处单位为0.1毫米
- ww=2000;//200毫米
- ll=2800;//280毫米
- if(Printer()->Orientation==poLandscape)//横向
- {
- DevMode->dmPaperLength=(short)ww;
- DevMode->dmPaperWidth=(short)ll;
- }
- else
- {
- DevMode->dmPaperLength=(short)ll;
- DevMode->dmPaperWidth=(short)ww;
- }
- GlobalUnlock((void*)h);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- PrinterSetupDialog1->Execute();
- }
- //---------------------------------------------------------------------------