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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <printers.hpp>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::Button1Click(TObject *Sender)
  17. {
  18.   int ll,ww;
  19.   char dvc[255],drv[255],port[255];
  20. //  AnsiString dvc,drv,port;
  21.   THandle h;
  22.   TDeviceMode *DevMode;
  23. //  Printer()->GetPrinter(dvc.c_str(),drv.c_str(),port.c_str(),h);
  24.   Printer()->GetPrinter(dvc,drv,port,h);
  25.   if(h==0)return;
  26.   Edit1->Text=dvc;
  27.   Edit2->Text=drv;
  28.   Edit3->Text=port;
  29.   DevMode=(TDeviceMode *)GlobalLock((void*)h);
  30.   DevMode->dmFields=DevMode->dmFields|DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;//改变长度与宽度
  31.   DevMode->dmPaperSize=DMPAPER_USER;//采用自定义纸张
  32.   //注意,此处单位为0.1毫米
  33.   ww=2000;//200毫米
  34.   ll=2800;//280毫米
  35.   if(Printer()->Orientation==poLandscape)//横向
  36.   {
  37.     DevMode->dmPaperLength=(short)ww;
  38.     DevMode->dmPaperWidth=(short)ll;
  39.   }
  40.   else
  41.   {
  42.     DevMode->dmPaperLength=(short)ll;
  43.     DevMode->dmPaperWidth=(short)ww;
  44.   }
  45.   GlobalUnlock((void*)h);
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TForm1::Button2Click(TObject *Sender)
  49. {
  50.   PrinterSetupDialog1->Execute();
  51. }
  52. //---------------------------------------------------------------------------