bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi 如何設定印表機的紙張大小
查看: 4910|回復: 1
go

如何設定印表機的紙張大小 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2010-5-4 13:54 |只看該作者 |倒序瀏覽 |打印
How to set the printer paper size:
http://www.lmc-mediaagentur.de/dpool/tips/0170.htm
  1. var
  2.     Device, Driver, Port: array[0..80] of Char;
  3.     DevMode: THandle;
  4.     pDevmode: PDeviceMode;
  5. begin
  6.     {Get printer device name etc.}
  7.     Printer.GetPrinter(Device, Driver, Port, DevMode);
  8.     {force reload of DEVMODE}
  9.     Printer.SetPrinter(Device, Driver, Port, 0) ;
  10.     {get DEVMODE handle}
  11.     Printer.GetPrinter(Device, Driver, Port, DevMode);
  12.     if Devmode <> 0 then
  13.     begin
  14.     {lock it to get pointer to DEVMODE record}
  15.     pDevMode := GlobalLock( Devmode );
  16.     if pDevmode <> Nil then
  17.     try
  18.         with pDevmode^ do
  19.         begin
  20.         {modify paper size}
  21.         dmPapersize := DMPAPER_B5;
  22.         {tell printer driver that dmPapersize field contains data it needs to inspect}
  23.         dmFields := dmFields or DM_PAPERSIZE;
  24.         end;
  25.     finally
  26.         {unlock DEVMODE handle}
  27.         GlobalUnlock( Devmode );
  28.     end;
  29.     end;
  30. end;




  31. uses winspool;

  32. procedure GetBinnames( sl: TStrings );
  33. Type
  34.     TBinName = Array [0..23] of Char;
  35.     TBinNameArray = Array [1..High(Integer) div Sizeof( TBinName )] of TBinName;
  36.     PBinnameArray = ^TBinNameArray;
  37.     TBinArray = Array [1..High(Integer) div Sizeof(Word)] of Word;
  38.     PBinArray = ^TBinArray;
  39. var
  40.     Device, Driver, Port: Array [0..255] of Char;
  41.     hDevMode: THandle;
  42.     i, numBinNames, numBins, temp: Integer;
  43.     pBinNames: PBinnameArray;
  44.     pBins: PBinArray;
  45. begin
  46.     Printer.PrinterIndex := - 1;
  47.     Printer.GetPrinter(Device, Driver, Port, hDevmode);
  48.     numBinNames := WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES, Nil, Nil );
  49.     numBins := WinSpool.DeviceCapabilities( Device, Port, DC_BINS, Nil, Nil );
  50.     if numBins <> numBinNames then
  51.     begin
  52.     raise Exception.Create('DeviceCapabilities reports different number of bins and '+ 'bin names!');
  53.     end;
  54.     if numBinNames > 0 then
  55.     begin
  56.     pBins := Nil;
  57.     GetMem( pBinNames, numBinNames * Sizeof( TBinname ));
  58.     GetMem( pBins, numBins * Sizeof(Word));
  59.     try
  60.         WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES, Pchar( pBinNames ), Nil);
  61.         WinSpool.DeviceCapabilities( Device, Port, DC_BINS, Pchar( pBins ), Nil );
  62.         sl.clear;
  63.         for i:= 1 to numBinNames do
  64.         begin
  65.         temp := pBins^[i];
  66.         sl.addObject( pBinNames^[i], TObject( temp ));
  67.         end;
  68.     finally
  69.         FreeMem( pBinNames );
  70.         if pBins <> Nil then
  71.         FreeMem( pBins );
  72.     end;
  73.     end;
  74. end;



  75. var
  76.     aDrvName, aPrtName, aPortName: Array[0..127] of Char;
  77.     aDeviceMode: THandle;
  78.     PDevMode: ^TDevMode;
  79.     i: Integer;
  80. begin
  81.     with Printer do
  82.     begin
  83.     GetPrinter(aDrvName, aPrtName, aPortName, aDeviceMode);
  84.     PDevMode := GlobalLock(aDeviceMode);
  85.     try
  86.         if PDevMode^.dmPaperSize = DMPAPER_A4 then
  87.         ShowMessage('A4')
  88.         else
  89.         if PDevMode^.dmPaperSize = DMPAPER_A3 then
  90.         ShowMessage('A3')
  91.         else
  92.         begin
  93.         ShowMessage('Size not supported!' + #13 + 'Resetting papersize to A4');
  94.         PDevMode^.dmPaperSize := DMPAPER_A4;
  95.         end;
  96.     finally
  97.         GlobalUnlock(aDeviceMode);
  98.     end;
  99.     end;
  100. end;
複製代碼
http://delphi.ktop.com.tw/board.php?cid=30&fid=100&tid=42907
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw

Rank: 9Rank: 9Rank: 9

2#
發表於 2010-5-4 15:02 |只看該作者
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2024-5-2 08:33 , Processed in 0.011962 second(s), 10 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.