国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

在winnt以上版本中對打印機紙張的動態設置方法

2019-11-18 18:04:48
字體:
來源:轉載
供稿:網友
在一些票據打印程序中,常常需要動態調整打印機紙張的設置,而網上能夠找到的dll只能在98下修改自定義紙張,在nt以上版本中還無相應的dll。所以自己動手通過一些比較笨的辦法實現動態修改紙張設置的功能。



library PRint;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  WinSpool,
  Windows,
  Messages,
  Classes;
var
  hPrinter: THandle;

{$R *.res}
Function GetDefaultPrinterName():PChar; //得到默認的打印機名稱
var
  sIniFile, sSection, sKeyName,p,q: PChar;
begin
  sIniFile := 'win.ini';
  sSection := 'windows';
  sKeyName := 'device';
  p:=StrAlloc(80);
  q:=StrAlloc(80);
  GetPrivateProfileString(sSection,sKeyName,nil,p,80,sIniFile); 
  StrLCopy(q,p,(strscan(p,',')-p));
  Result := q;
end;

Function addpage():Boolean; //添加一打印紙張類型名稱為300k
var
  FormInfo: TFormInfo1;
  PaperSize: TSize;
  PaperRect: TRect;
begin
  FormInfo.Flags := FORM_USER;
  FormInfo.pName := PChar('300k');
  PaperSize.cx := 100000;
  PaperSize.cy := 100000; //300k紙張的默認大小 1000mm*1000mm
  PaperRect.Left := 1;
  PaperRect.Top := 1;
  PaperRect.Right := 100000;
  PaperRect.Bottom := 100000; //紙張的邊距
  FormInfo.Size := PaperSize;
  FormInfo.ImageableArea := PaperRect;
  AddForm(hPrinter, 1, @FormInfo);
  Result := True;
end;

Function changepape():Boolean; //改變當前的打印紙張設置
var
  FormInfos : Array [1..1024] of Form_Info_1;
  cbNeeded, cReturned ,neededsize: DWord;
  i,j:integer;
  ppo:PRINTER_INFO_2;
  dev :PDeviceMode;
begin
  EnumForms(hPrinter, 1, Nil, 0, cbNeeded, cReturned);
  EnumForms(hPrinter, 1, @FormInfos, cbNeeded, cbNeeded, cReturned );
  j := 0;
  for i:= 1 to cReturned  do 通過輪尋找到300k的紙張的紙張類型排序號
    if FormInfos[i].pName = '300k' then j:=i;
  if j=0 then 
  begin
    addpage();
    j := cReturned + 1;
  end; //如無300k紙張則添加
  GetPrinter(hPrinter,2,Nil, 0, @NeededSize);
  GetPrinter(hPrinter, 2, @ppo, NeededSize, @NeededSize);
  dev := ppo.pDevMode;
  dev.dmPaperSize := j;
  ppo.pDevMode := dev;
  SetPrinter(hPrinter,2,@ppo,0); //定義打印機列表并選擇300k紙張
  Result := True;
end;

Function MySetPrtInfo(P:Pchar;W:Integer;L:Integer):Boolean;stdcall;
 //設置打印機的紙張類型為300k,并動態修改300k的大小和邊距
var
  FormInfo: TFormInfo1;
  PaperSize: TSize;
  PaperRect: TRect;
begin
  OpenPrinter(GetDefaultPrinterName, hPrinter, nil);
  changepape(); //改變紙張類型定義
  FormInfo.Flags := FORM_USER;
  FormInfo.pName := '300K';
  PaperSize.cx := W*100;
  PaperSize.cy := L*100;
  PaperRect.Left := 0;
  PaperRect.Top := 0;
  PaperRect.Right := W*100;
  PaperRect.Bottom := L*100;
  FormInfo.Size := PaperSize;
  FormInfo.ImageableArea := PaperRect;
  SetForm(hPrinter,'300k',1,@FormInfo); //設置紙張大小
  ClosePrinter(hPrinter);
  Result := True;
end;

exports
  MySetPrtInfo;
begin
end.


上一篇:如何在DBGRID或者STRINGGRID中實現用滾輪進行翻頁的功能,就象瀏覽網頁一樣

下一篇:創建Photoshop式浮動窗口應用程序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 颍上县| 泰宁县| 墨竹工卡县| 邵阳市| 资中县| 桐乡市| 开封市| 和静县| 邻水| 弥渡县| 安达市| 农安县| 澄城县| 扶沟县| 浦城县| 东山县| 长垣县| 旅游| 兴安盟| 喀喇| 香港| 怀集县| 元谋县| 噶尔县| 偃师市| 云和县| 太和县| 阜平县| 云龙县| 宁河县| 北海市| 新津县| 靖江市| 清苑县| 浦东新区| 英德市| 南溪县| 华宁县| 宜春市| 新余市| 昭通市|