📄 改变打印设置.txt
字号:
procedure TForm1.Button1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := DMPAPER_LEGAL;
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMillimeter};
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.BeginDoc;
Printer.Canvas.TextOut(100,100, 'Test 1');
Printer.EndDoc;
end;
**********************************************************************************************
procedure save_and_restore_printer_settings_demo;
var
dev, driver, port : array [0..64] of char;
nbytes: integer;
modebuffer: Pointer;
dmp : PDeviceMode;
p: THandle;
begin
{ get the current device, driver, port and a Handle of a
Memory Object containing DEVMODE structure ;
**** Important Note: p returns a Handle to a Memory Object,
**** not a Pointer to the DEVMODE struct! Get the pointer
**** by GlobalLock ! }
Printer.GetPrinter(dev,driver,port,p);
{ There's driver specific data behind the DEVMODE struct.
allocate a Buffer large enough to hold all the Data }
dmp := GlobalLock(p); // Get a Pointer !!
nbytes := dmp.dmSize+dmp.dmDriverExtra ;
GetMem(modebuffer,nbytes); // Get memory
CopyMemory(modebuffer,dmp,nbytes); // Copy
GlobalUnlock(p); // Unlock
{ now you have all the current
settings. save them all the way you like: file, database,
registry ....)
....
{to restore : read in the data from storage back
into the vars}
....
p := GlobalAlloc(GHND, nbytes); // Allocate mem
dmp := GlobalLock(p);
CopyMemory(dmp,modebuffer,nbytes);
GlobalUnlock(p);
{set the printer to the stored one.... don't forget to check if
the Printer exists !!! }
Printer.SetPrinter(dev,driver,port,p);
{ now we are done... start printing ! }
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -