Article View: borland.public.cppbuilder.nativeapi
Article #15397Re: Setting page size progmatically
From: A Whitesell
Date: Thu, 03 Jul 2003 13:02
Date: Thu, 03 Jul 2003 13:02
107 lines
4668 bytes
4668 bytes
Hey Midnight Programmer,
I am using the VCL, but TPrinter does not have a way to set the page height
and width, they are read only. Are you aware of a way to use the VCL and
set the page height and width? I am having problems getting the example
below to work but I still have a lot of things left to try, but using the
VCL would be easier.
TIA.
"Midnight Programmer" <nospam@nospam.com> wrote in message
news:3f04acd9$1@newsgroups.borland.com...
> "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:
<3f04d39f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!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> <3f04acd9$1@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 18:09:27 PST From: "A Whitesell" <awhitesell@attbi.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f045222$1@newsgroups.borland.com> <3f0459d8@newsgroups.borland.com> <3f04aaa7@newsgroups.borland.com> <3f04acd9$1@newsgroups.borland.com> Subject: Re: Setting page size progmatically Date: Thu, 3 Jul 2003 09:02:23 -0400 Lines: 109 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.128.134.183 Message-ID: <3f04d39f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1057280927 24.128.134.183 (3 Jul 2003 18:08:47 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail