 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Karsten Becker Guest
|
Posted: Tue Jun 29, 2004 11:05 am Post subject: TPrintDialog/ TPrinter? question |
|
|
Hi All,
I have a strange problem with printer settings.
I want to be able to auto print documents without user input. Some documents
should be printed on A4, others on A3. Therefor i have created two printers,
which actually pointing to the same printer. This printer can handle of
course both papersizes.
In the printer settings i made sure that the first printer (LP_1), which in
the standard printer, only can print A4.
The second one (LP_2) can only print A3. Therefor i had to change the
printer settings of that printer as well.
So far so good! Now, when printing to the first (standard) printer
everything works just fine, but when printing to the second (LP_2) the
trouble starts.
The printer detect that a wrong papaer size is selected.When i take a look
at the settings / advanced in my TPrintDialog of the second printer i can
see that the selected paper format is A4 and not A3 as i have set in the
windows printer manager. It seems that it shows the paperformat of the first
(standard) printer.
Is this a bug or am i doing something wrong?
I'm using BCB5 Pro/ WinXP
Regards
Karsten
|
|
| Back to top |
|
 |
TerryC Guest
|
Posted: Tue Jun 29, 2004 6:35 pm Post subject: Re: TPrintDialog/ TPrinter? question |
|
|
Are you just changing Printer()->PrinterIndex to switch which
(Windows) printer it is routed to?
Also, let me make certain that I understand what you are doing:
In Windows, a Printer is actually more like a print queue, and
the physical printer is refered to as a "printing device". As
I understand it, you have created two different Windows
printers, or print queues, which both point to the same
printing device, or physical printer. The two Windows printers
have their Printing Preference -> Paper Source set to two
different sources: One set to A4 and the other to A3.
In your code, you switch between these two Windows printers to
effectively select the paper tray from which the printing
device feeds when it prints.
Is that a good summary of the situation?
-Terry
|
|
| Back to top |
|
 |
TerryC Guest
|
Posted: Tue Jun 29, 2004 7:52 pm Post subject: Re: TPrintDialog/ TPrinter? question |
|
|
Karsten,
If my posting above is correct, there is probably a better way.
Here is a sample of code that will switch the paper size of
your print job before you print:
void __fastcall TForm1::ChangePaperSize(int PaperSize)
{
char PrinterName[256];
char DriverName[256];
char PortName[256];
THandle hDevMode;
PDEVMODE pDevMode;
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
if(hDevMode){
pDevMode = (PDEVMODE)GlobalLock((void*)hDevMode);
if(pDevMode){
// PaperSize should be DMPAPER_A4 or DMPAPER_A3 when called
pDevMode->dmPaperSize = PaperSize;
GlobalUnlock((void*)hDevMode);
}
GlobalFree((void*)hDevMode);
}
}
Then, to use the method we have built...
void __fastcall TForm1::OnButton1Click(TObject* Sender)
{
// Select the PrinterIndex
Printer()->PrinterIndex = 0;
// Call our paper size method
ChangePaperSize(DMPAPER_A4);
// Do our printing here
Printer->BeginDoc();
...
Printer->EndDoc();
}
That should do what you need, without having two Windows
printers defined. That way, your app isn't relying on how the
printers are installed.
-Terry
|
|
| Back to top |
|
 |
TerryC Guest
|
Posted: Tue Jun 29, 2004 8:36 pm Post subject: Re: TPrintDialog/ TPrinter? question - Oops! |
|
|
Oops! I missed a couple of things in the previous code.
Here is a better method for you:
void __fastcall TForm1::ChangePaperSize(int PaperSize)
{
char PrinterName[256];
char DriverName[256];
char PortName[256];
THandle hDevMode;
PDEVMODE pDevMode;
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
// Set printer back to defaults
Printer()->SetPrinter(
PrinterName,
DriverName,
PortName,
0
);
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
if(hDevMode){
pDevMode = (PDEVMODE)GlobalLock((void*)hDevMode);
if(pDevMode){
pDevMode->dmFields = pDevMode->dmFields || DM_PAPERSIZE;
// PaperSize should be DMPAPER_A4 or DMPAPER_A3 when called
pDevMode->dmPaperSize = PaperSize;
GlobalUnlock((void*)hDevMode);
Printer()->SetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
}
GlobalFree((void*)hDevMode);
}
}
|
|
| Back to top |
|
 |
Karsten Becker Guest
|
Posted: Wed Jun 30, 2004 8:50 am Post subject: Re: TPrintDialog/ TPrinter? question |
|
|
Hi Terry
That is correct. You descibed it exactly the way i did it. It does not
matter if i switch the printer by source or with a TPrintDialog. In both
cases i get the same result.
Karsten
"TerryC" <terryc.dont_spam_me (AT) sweetwaterhsa (DOT) com> schreef in bericht
news:40e1b667$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Are you just changing Printer()->PrinterIndex to switch which
(Windows) printer it is routed to?
Also, let me make certain that I understand what you are doing:
In Windows, a Printer is actually more like a print queue, and
the physical printer is refered to as a "printing device". As
I understand it, you have created two different Windows
printers, or print queues, which both point to the same
printing device, or physical printer. The two Windows printers
have their Printing Preference -> Paper Source set to two
different sources: One set to A4 and the other to A3.
In your code, you switch between these two Windows printers to
effectively select the paper tray from which the printing
device feeds when it prints.
Is that a good summary of the situation?
-Terry
|
|
|
| Back to top |
|
 |
Karsten Becker Guest
|
Posted: Wed Jun 30, 2004 8:54 am Post subject: Re: TPrintDialog/ TPrinter? question - Oops! |
|
|
Thanks for the piece of source Terry. I'll try it.
Karsten
"TerryC" <terryc.dont_spam_me (AT) sweetwaterhsa (DOT) com> schreef in bericht
news:40e1d2b6$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Oops! I missed a couple of things in the previous code.
Here is a better method for you:
void __fastcall TForm1::ChangePaperSize(int PaperSize)
{
char PrinterName[256];
char DriverName[256];
char PortName[256];
THandle hDevMode;
PDEVMODE pDevMode;
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
// Set printer back to defaults
Printer()->SetPrinter(
PrinterName,
DriverName,
PortName,
0
);
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
if(hDevMode){
pDevMode = (PDEVMODE)GlobalLock((void*)hDevMode);
if(pDevMode){
pDevMode->dmFields = pDevMode->dmFields || DM_PAPERSIZE;
// PaperSize should be DMPAPER_A4 or DMPAPER_A3 when called
pDevMode->dmPaperSize = PaperSize;
GlobalUnlock((void*)hDevMode);
Printer()->SetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
}
GlobalFree((void*)hDevMode);
}
}
|
|
|
| Back to top |
|
 |
dcent Guest
|
Posted: Wed Sep 15, 2004 5:21 pm Post subject: Printer()->GetPrinter() problem |
|
|
I have implimented the code below, but I have a problem with with it.
Elsewhere in coed I set the PrinterIndex to a printer that is NOT the
default printer. When I call this code, the first time through the
pDevMode->dmDeviceName is that of the default printer, but the
PrinterName is correct.
How do I get Printer() to know that I REALLY want the selected printer
NOT the default one?
Jeff
- BCB5ent update1
| Quote: |
void __fastcall TForm1::ChangePaperSize(int PaperSize)
{
char PrinterName[256];
char DriverName[256];
char PortName[256];
THandle hDevMode;
PDEVMODE pDevMode;
Printer()->GetPrinter(
PrinterName,
DriverName,
PortName,
hDevMode
);
if(hDevMode){
pDevMode = (PDEVMODE)GlobalLock((void*)hDevMode);
if(pDevMode){
// PaperSize should be DMPAPER_A4 or DMPAPER_A3 when called
pDevMode->dmPaperSize = PaperSize;
GlobalUnlock((void*)hDevMode);
}
GlobalFree((void*)hDevMode);
}
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|