Article View: borland.public.cppbuilder.nativeapi
Article #15395Re: Setting page size progmatically
From: Midnight Programmer
Date: Thu, 03 Jul 2003 22:23
Date: Thu, 03 Jul 2003 22:23
89 lines
4045 bytes
4045 bytes
"A Whitesell" <awhitesell@attbi.com> wrote in message
news:3f04aaa7@newsgroups.borland.com...
> No offense Hans, but this reference is 4 years old to a news group that no
> longer exists.
Had to use Google's GROUP search....
Here's the Text of the thread...
Search Result 1
From: Damon Chandler (dmc27@cornell.edu)
Subject: Re: Changing PageSize for a print job
View: Complete Thread (2 articles)
Original Format
Newsgroups: borland.public.cppbuilder.winapi
Date: 1999/10/18
Hi Klaus,
> How can I change the page size if my document without calling the
> printer setup dialogbox.
You can use the DocumentProperties() function to accomplish this. Here's a
simple example...
// get the default printer name, driver, and port
char *def_string = "no printer";
char buffer[MAX_PATH];
GetProfileString("windows", "device", def_string,
buffer, MAX_PATH);
AnsiString Abuffer(buffer);
AnsiString Device, Driver, Port;
// parse the buffer to extract individual properties
int first_comma = Abuffer.Pos(",");
Device = Abuffer.SubString(1, first_comma - 1);
Abuffer = Abuffer.SubString(first_comma + 1,
Abuffer.Length() - first_comma);
int second_comma = Abuffer.Pos(",");
Driver = Abuffer.SubString(1, second_comma - 1);
Port = Abuffer.SubString(second_comma + 1,
Abuffer.Length() - second_comma);
// open the printer
HANDLE HPrinter;
if (OpenPrinter(Device.c_str(), &HPrinter, NULL))
{
// call DocumentProerties() with a zero fMode parameter
// to get the number of bytes required
long int num_bytes;
num_bytes = DocumentProperties(NULL, HPrinter, Device.c_str(),
NULL, NULL, 0);
// allocate the memory
unsigned char *buffer = new unsigned char[num_bytes];
// call DocumentProperties() again, this time to get the
// device mode information
DocumentProperties(NULL, HPrinter, Device.c_str(),
(PDEVMODE)buffer, NULL, DM_OUT_BUFFER);
PDEVMODE pdm = (PDEVMODE)buffer;
// modify the appropriate fields
pdm->dmPaperSize = DMPAPER_10X14; // for example
// tell Windows which fields we changed
pdm->dmFields = pdm->dmFields | DM_PAPERSIZE;
// call DocumentProperties() yet again, this time to get
// the final DEVMODE to pass into the CreateDC() function
DocumentProperties(NULL, HPrinter, Device.c_str(),
pdm, pdm, DM_OUT_BUFFER | DM_IN_BUFFER);
// CreateDC(...);
// print...
delete [] buffer;
ClosePrinter(HPrinter);
}
If you are using the VCL, the TPrinter::GetPrinter() method simplifies this
process.
Good luck.
--------------------------------------
Damon Chandler
Technical Details
Message-ID:
<3f04acd9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f045222$1@newsgroups.borland.com> <3f0459d8@newsgroups.borland.com> <3f04aaa7@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,163c42dfba190846 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-03 15:39:30 PST From: "Midnight Programmer" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f045222$1@newsgroups.borland.com> <3f0459d8@newsgroups.borland.com> <3f04aaa7@newsgroups.borland.com> Subject: Re: Setting page size progmatically Date: Thu, 3 Jul 2003 15:23:25 -0700 Lines: 92 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 64.70.40.254 Message-ID: <3f04acd9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1057271001 64.70.40.254 (3 Jul 2003 15:23:21 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail