QuickRep如何動能設定紙張大小,及取得紙張大小清單?? |
尚未結案
|
jeffreck
高階會員 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
|
anypro
一般會員 發表:3 回覆:6 積分:1 註冊:2003-12-29 發送簡訊給我 |
定義紙型
const
PaperSize:array[0..27] of TQRPaperSize = (Default, Letter, LetterSmall, Tabloid, Ledger, Legal,
Statement, Executive, A3, A4, A4Small, A5, B4, B5, Folio,
Quarto, qr10X14, qr11X17, Note, Env9, Env10, Env11, Env12,
Env14, CSheet, DSheet, ESheet, Custom); 加入RUN代碼
form.QuickRep1.PrinterSetup;
Printers.Printer.GetPrinter(Device, Driver, Port, HDevMode);
if HDevMode <> 0 then begin
try
PDevMode := GlobalLock(HDevMode);
papertype := PDevMode.dmPaperSize;
if papertype<=26 then
form.QuickRep1.Page.PaperSize:=PaperSize[papertype]
else begin
form.QuickRep1.Page.PaperSize:=PaperSize[27]; //Custome
form.QuickRep1.Page.Width:=paperw/10;
form.QuickRep1.Page.Length:=paperl/10;
......
finally
GlobalUnlock(HDevMode);
end;
|
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
|
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
找了一下, 看下面這篇是不是你要的
http://www.mers.com/cgi-bin/mer.exe/EXECSEARCH?searchtext=Paper+Size+List&grouptext=Delphi&pageno=3&linktype=viewmsg&msgno=79215&boardno=740 原文轉貼
procedure GetPapernames( sl: TStrings ); Type TPaperName = Array [0..63] of Char; TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of TPaperName; PPapernameArray = ^TPaperNameArray; Var Device, Driver, Port: Array [0..255] of Char; hDevMode: THandle; i, numPaperformats: Integer; pPaperFormats: PPapernameArray; begin Printer.PrinterIndex := -1; Printer.GetPrinter(Device, Driver, Port, hDevmode); numPaperformats := WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil ); If numPaperformats > 0 Then Begin GetMem( pPaperformats, numPaperformats * Sizeof( TPapername )); try WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Pchar( pPaperFormats ), Nil); sl.Clear; For i:= 1 To numPaperformats Do sl.add( pPaperformats^[i] ); finally FreeMem( pPaperformats ); end; End; End;我不是高手, 高手是正在銀幕前微笑的人.
------
我不是高手, 高手是正在銀幕前微笑的人. |
jeffreck
高階會員 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
|
jeffreck
高階會員 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
引言: 找了一下, 看下面這篇是不是你要的 http://www.mers.com/cgi-bin/mer.exe/EXECSEARCH?searchtext=Paper+Size+List&grouptext=Delphi&pageno=3&linktype=viewmsg&msgno=79215&boardno=740 原文轉貼謝謝Miles 前輩,真是太厲害了!!! 但還有問題,當User 選好紙張大小後如何指定給QuickRep 報表?? 謝謝各位前輩!!procedure GetPapernames( sl: TStrings ); Type TPaperName = Array [0..63] of Char; TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of TPaperName; PPapernameArray = ^TPaperNameArray; Var Device, Driver, Port: Array [0..255] of Char; hDevMode: THandle; i, numPaperformats: Integer; pPaperFormats: PPapernameArray; begin Printer.PrinterIndex := -1; Printer.GetPrinter(Device, Driver, Port, hDevmode); numPaperformats := WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil ); If numPaperformats > 0 Then Begin GetMem( pPaperformats, numPaperformats * Sizeof( TPapername )); try WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Pchar( pPaperFormats ), Nil); sl.Clear; For i:= 1 To numPaperformats Do sl.add( pPaperformats^[i] ); finally FreeMem( pPaperformats ); end; End; End;我不是高手, 高手是正在銀幕前微笑的人. |
Miles
尊榮會員 發表:27 回覆:662 積分:622 註冊:2002-07-12 發送簡訊給我 |
Hi jeffreck 您好:
我在網路上晃了一下發現QuickReport的PaperSize問題還真不少.
參考了一下這一篇, 並將之前程式碼改寫, 整份內容如下, 要注意的是紙張大小會被改掉(印表機-->內容-->列印喜好設定-->進階-->列印紙張大小), 若有需要你在加程式碼改掉即可
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=237
//抓取紙張大小列表 procedure GetPapernames( sl: TStrings ); Type TPaperName = Array [0..63] of Char; TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of TPaperName; PPapernameArray = ^TPaperNameArray; Var Device, Driver, Port: Array [0..255] of Char; hDevMode: THandle; i, numPaperformats: Integer; pPaperFormats: PPapernameArray; begin Printer.PrinterIndex := -1; Printer.GetPrinter(Device, Driver, Port, hDevmode); numPaperformats := WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil ); If numPaperformats > 0 Then Begin GetMem( pPaperformats, numPaperformats * Sizeof( TPapername )); try WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Pchar( pPaperFormats ), Nil); sl.Clear; For i:= 1 To numPaperformats Do sl.add( pPaperformats^[i] ); finally FreeMem( pPaperformats ); end; End; End; //設定紙張大小 procedure SetPrinterSize(Const SizeName : String); var _PPrinterInfo2 : PPrinterInfo2; pPrinterName : PChar; sPrinterName, sFormName : String; hPrinter : THandle; cbNeeded : DWORD; dwBufferSize : DWORD; begin // 設定印表機的紙張大小名稱 sFormName := SizeName; // 取得預設印表機名稱 sPrinterName := Printer.Printers.Strings[Printer.PrinterIndex]; if not WinSpool.OpenPrinter(PChar(sPrinterName), hPrinter, nil) then raise Exception.Create('OpenPrinter Error, Code : ' IntToStr(GetLastError)); WinSpool.GetPrinter(hPrinter, 2, nil, 0, @cbNeeded); _PPrinterInfo2 := nil; try GetMem(_PPrinterInfo2, cbNeeded); WinSpool.GetPrinter(hPrinter, 2, _PPrinterInfo2, cbNeeded, @cbNeeded); with _PPrinterInfo2^.pDevMode^ do begin StrLCopy(dmFormName, PChar(sFormName), CCHFORMNAME - 1); //dmPaperSize := PaperSizeID(sPrinterName, sFormName); dmFields := DM_FORMNAME; // DM_PAPERSIZE end; // 不知為何 SetPrinter 一定會有錯誤 -> GetLastError = ERROR_ACCESS_DENIED // (即使以 Administrator 身份執行), 所以先把 raise 註解掉, Who could explain it for me ? Thanks. if not WinSpool.SetPrinter(hPrinter, 2, _PPrinterInfo2, 0) then ; //raise Exception.Create('SetPrinter Error, Code : ' IntToStr(GetLastError)); finally if _PPrinterInfo2 <> nil then FreeMem(_PPrinterInfo2); _PPrinterInfo2 := nil; end; end; procedure TForm1.Button1Click(Sender: TObject); begin GetPapernames(ListBox1.Items); end; procedure TForm1.ListBox1Click(Sender: TObject); begin SetPrinterSize(ListBox1.Items.Strings[ListBox1.ItemIndex]); QuickRep1.Preview; end;至於TPrintSetupDialog...Please forget it kindly~~~ 我不是高手, 高手是正在銀幕前微笑的人.
------
我不是高手, 高手是正在銀幕前微笑的人. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |