******************************************
Retrieves the current printer.
void __fastcall GetPrinter(char * ADevice, char * ADriver, char * APort,
int &ADeviceMode);
Description
It is not necessary to directly call GetPrinter. Instead, access the
printer in the Printers property array. For more information, see the
CreateDC function in the Win32 Developer's Reference (WIN32.HLP).
******************************************
It says to see the WIN32 CreateDC documentation for more info. However,
the Win32 CreateDC function takes a DEVMODE structure for its device
mode argument, while TPrinter::GetPrinter stores the device mode in an
integer.
1) What does the integer returned in ADeviceMode mean? What is it used
for?
2) How do I get the real DEVMODE structure? We are reusing some old OWL
code, and the OWL TPrintDC constructor requires this DEVMODE structure.
3) If I can't get the DEVMODE structure, is there some way I can
determine what options the user selected in the TPrinterSetupDialog?
4) Just out of curiosity, why does the GetPrinter documentation say:
"It is not necessary to directly call GetPrinter.
Instead, access the printer in the Printers property array."
The Printers array only contains the names of the installed printers;
it contains no information about driver, port, or mode.
Jeff Wilhite
1. Because the VCL is written in Delphi, the DeviceMode "integer" is
actually a handle to a block of memory that points to a device mode. (In C,
you would declare it as HANDLE DeviceMode.) You can use DeviceMode as
follows (C++Builder 4 code):
HANDLE hDeviceMode = 0;
char Device[256], Driver[256], Port[256];
Printer()->GetPrinter( Device, Driver, Port, ( unsigned int
& )hDeviceMode );
if ( !hDeviceMode )
throw EPrinter( "Could not get device mode" );
LPDEVMODE pDevMode = ( LPDEVMODE )GlobalLock( hDeviceMode );
if ( !pDevMode )
throw EPrinter( "Could not lock device mode" );
// set whatever DEVMODE fields you want to change...
pDevMode->dmFields |= DM_PAPERSIZE | DM_DUPLEX;
pDevMode->dmPaperSize = ( short )DMPAPER_LETTER;
pDevMode->dmDuplex = DMDUP_SIMPLEX;
GlobalUnlock( hDeviceMode );
Printer()->SetPrinter( Device, "", "", ( unsigned int )hDeviceMode );
Note that once you've changed the DEVMODE and unlocked the handle to it, you
should call SetPrinter() to use the new DEVMODE.
2. You can use the code above to get the pointer to the DEVMODE structure
using the DeviceMode handle.
3. Since you can easily use the DeviceMode as in #1 and #2 above, you
shouldn't need to use the options in TPrinterSetupDialog.
4. Sometimes we have to ignore the documentation. :-) To do basic printing,
it shouldn't be necessary to use GetPrinter(), however all the printing apps
I've written have required accessing the DEVMODE structure. btw, in a Win32
app, you shouldn't need anything other than the printer name or DeviceMode
returned by GetPrinter(). Win9x/NT knows which printer driver and port to
use based on the device name.
IMHO, the TPrinter class is a little too basic, and as above, I had to use
GetPrinter() to do duplex printing and change printer trays, among other
things. In another app, I had to write my own printer class from scratch so
that I could print to more than one printer at the same time. TPrinter
doesn't really do that much...
Murray
Jeff Wilhite <jwil...@acm.org> wrote in message
news:37D674F1...@acm.org...
> Here is a quote from the TPrinter::GetPrinter documentation:
>