⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 有视频
💻 CPP
字号:
//---------------------------------------------------------------------------
#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();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -