Dynamically change custom print paper in C Builder programming
Due to the Delphi example in the Internet, I found some examples when I was written in CB.
So I have checked the information yourself, I'm afraid that the netizens also meet this situation when using programming.
I immediately passed.
Void __fastcall tform1 :: bitbtn1click (Tobject * Sender)
{
Char * ADEVICE, * ADRIVER, * APORT
Thandle DeviceMode;
PDeviceMode devmode;
INT Length, Width;
Length = 1400;
Width = 2410; // Setting the size unit of custom paper is 0.1 mm
Adevice = new char [100];
Adriver = new char [100];
Aport = new char [100];
/ / Get the printer
Printer () -> GetPrinter (Adevice, Adriver, Aport, DeviceMode);
// Get a PDEVMODE structure
DEVMODE = (_ DeviceModea *) GlobalLock ((void *) devicemode;
/ / Set the value that can be modified
DMFIELDS = devmode-> DMFIELDS | DM_PAPERSIZE
DMFIELDS = devmode-> dmfields | DM_PAPERLENGTH;
Devmode-> DMfields = devmode-> DMFields | DM_PAPERWIDTH;
/ / Set the value to modify
DEVMODE-> DMPAPERSIZE = DMPAPER_USER; / / Change Paper
DEVMODE-> DMPAPERLENGTH = Length;
DEVMODE-> DMPAPERWIDTH = Width;
// Test print
() -> begindoc ();
TextOut (Printer () -> Handle, 0, 0, "---------------", 17);
PRINTER () -> newPage ();
Textout (Printer () -> Handle, 0, 0, " , 18);
PRINTER () -> newPage ();
PRINTER () -> enddoc ();
}