Add a custom paper with custom paper from Win2000XP.

xiaoxiao2021-03-06  41

// Add specification custom paper

// Papername: Custom Paper Name

// PaperWidth: The width of the paper is 0.1mm.

// PaperLength: The height of the paper is 0.1mm unit

Procedure TDM.AddcustomPaper (const papername: string; paperwidth, paperLength: integer);

VAR

PrintDevice, PrintDriver, Printport: Array [0..255] of char;

HDMODE: THANDLE;

Hprinter: thandle;

Forminfo: tFormInfo1;

Begin

Printer.getPrinter (PrintDevice, PrintDriver, Printport, HDMODE);

OpenPrinter (PrintDevice, Hprinter, NIL);

IF hprinter = 0 THEN

Raise Exception.create ('link printer failed!');

WITH FORMINFO DO

Begin

Flags: = form_user;

PNAME: = PCHAR (Papername);

Size.cx: = paperwidth * 100;

Size.cy: = PaperLength * 100;

ImageableARea.Left: = 0;

ImageableArea.top: = 0;

ImageableArea.right: = paperwidth * 100;

ImageableARea.bottom: = PaperLength * 100;

END;

/ / Modify the paper type, if you don't add new

IF not setform (Hprinter, Pchar (Papername), 1, @forminfo) THEN

Addform (Hprinter, 1, @formInfo);

Closeprinter (Hprinter);

END;

/ / Delete Custom Specifications Paper

// Papername: Custom Paper Name

Procedure TDM.DeleteCustomPaper (const papername: string);

VAR

PrintDevice, PrintDriver, Printport: Array [0..255] of char;

HDMODE: THANDLE;

Hprinter: thandle;

Begin

Printer.getPrinter (PrintDevice, PrintDriver, Printport, HDMODE);

OpenPrinter (PrintDevice, Hprinter, NIL);

IF hprinter = 0 THEN

Raise Exception.create ('link printer failed!');

Deleteform (Hprinter, Pchar (Papername));

Closeprinter (Hprinter);

END;

转载请注明原文地址:https://www.9cbs.com/read-74217.html

New Post(0)