如何用DELPHI永久改變印表機默認紙張大小? |
答題得分者是:jackkcg
|
richcomp
中階會員 發表:18 回覆:66 積分:51 註冊:2002-10-18 發送簡訊給我 |
|
jackkcg
站務副站長 發表:891 回覆:1050 積分:848 註冊:2002-03-23 發送簡訊給我 |
參考參考 QuickReport在Windows2000中自訂報表
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=237 【Delphi】【問題】請問有關郵寄標籤問題
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=20877
【轉貼】Api函數清單--與列印相關
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21601
【Delphi】【問題】QR 如何依紙張大小壓縮文件
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21358 深度論壇
http://forum.vclxx.org/topic.php?TOPIC_ID=21107&FORUM_ID=9&CAT_ID=2&Topic_Title=WINDOWS2000¤U¦p¦ó¦۩w义¥´¦L纸张¤j¤p¡H&Forum_Title=WinAPI **********************************************************************
abaca
幼幼班 20 Posts Posted - 10/08/2002 : 17:19:01
--------------------------------------------------------------------------------
這有一篇這兒的先進寫的, 我 copy 下內文, 却忘了是在那一篇討論中看到的,
若寫的先進看到別見怪, 我只是代為 paste 在 WindowsNT/200 環境下要自訂紙張尺寸所使用的方法與 Win9x 不同,
你必須先為目前的印表機定義一個自訂的 "Form"(呼叫 API: AddForm,
此 API 宣告於 WinSpool 單元中),然後把這個 Form 的名稱設定給
DEVMODES 結構中的 dmFormName 欄位。以下的函式可以直接拿來使用: uses Windows, WinSpool, Printers; (*------------------------------------------------------
Define a new Form (WinNT/2000 only).
If FormName already exists, do nothing and return.
If failed, an exception will be raised.
------------------------------------------------------*)
procedure PrnAddForm(const FormName: string; PaperWidth, PaperLength:
integer);
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter: THandle;
FormInfo: TFormInfo1;
PaperSize: TSize;
PaperRect: TRect;
errcode: integer;
s: string;
begin
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('Failed to open printer!');
FormInfo.Flags := FORM_USER;
FormInfo.pName := PChar(FormName);
PaperSize.cx := PaperWidth;
PaperSize.cy := PaperLength;
PaperRect.Left := 0;
PaperRect.Top := 0;
PaperRect.Right := PaperWidth;
PaperRect.Bottom := PaperLength;
FormInfo.Size := PaperSize;
FormInfo.ImageableArea := PaperRect;
if not AddForm(hPrinter, 1, @FormInfo) then
begin
errcode := GetLastError;
if errcode <> ERROR_FILE_EXISTS then // Form name exists?
begin
case errcode of
ERROR_ACCESS_DENIED: s := 'Access is denied';
ERROR_INVALID_HANDLE: s := 'The handle is invalid';
ERROR_NOT_READY: s := 'The device is not ready';
ERROR_CALL_NOT_IMPLEMENTED:
s := 'Function "AddForm" is not supported on this system';
else
s := 'Failed to add a Form (paper) name!';
end;
raise Exception.Create(s);
end;
end;
ClosePrinter(hPrinter);
end; (*
Set custom paper size for WinNT/2000.
Make sure FormName is supported by current printer,
You can call PrnAddForm to define a new Form.
*)
procedure PrnSetPaperSizeNT(FormName: string; PaperWidth, PaperLength:
integer);
var
Device, Driver, Port: array[0..80] of Char;
DevMode: THandle;
pDevmode: PDeviceMode;
begin
// Get printer device name etc.
Printer.GetPrinter(Device, Driver, Port, DevMode);
// force reload of DEVMODE
Printer.SetPrinter(Device, Driver, Port, 0) ;
// get DEVMODE handle
Printer.GetPrinter(Device, Driver, Port, DevMode);
if DevMode <> 0 then
begin
// lock it to get pointer to DEVMODE record
pDevMode := GlobalLock( DevMode );
if pDevmode <> nil then
try
with pDevmode^ do
begin
// modify form
StrLCopy( dmFormName, PChar(FormName), CCHFORMNAME-1 );
// tell printer driver that dmFormname field contains
// data it needs to inspect.
dmPaperWidth := PaperWidth;
dmPaperLength := PaperLength;
dmFields := dmFields or DM_FORMNAME or DM_PAPERWIDTH or DM_PAPERLENGTH;
end;
finally
GlobalUnlock( Devmode ); // unlock devmode handle.
end;
end; { If }
end; procedure TForm1.Button1Click(Sender: TObject);
begin
PrnAddForm(
edFormName.Text,
StrToInt(edPaperWidth.Text),
StrToInt(edPaperLength.Text)
);
PrnSetPaperSizeNT(
edFormName.Text,
StrToInt(edPaperWidth.Text),
StrToInt(edPaperLength.Text)
);
Printer.BeginDoc;
Printer.Canvas.TextOut(10, 10, 'Printer test!');
Printer.EndDoc;
end; 發表人 - jackkcg 於 2002/10/30 22:51:39
------
********************************************************** 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind |
richcomp
中階會員 發表:18 回覆:66 積分:51 註冊:2002-10-18 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |