Article View: borland.public.cppbuilder.nativeapi
Article #7844Re: Printer properties
From: Keith
Date: Thu, 16 Dec 2004 18:09
Date: Thu, 16 Dec 2004 18:09
69 lines
4542 bytes
4542 bytes
"Thomas J." wrote:
> Mad, I copied your code which you posted and I'm using Windows2000, BCB6
> Enterpise.
>
> This is the code which is running not proper on my system. I get directly
> the error message (the second MessageDlg("Error", ...)
>
> PRINTDLG printerSetup;
> ZeroMemory(&printerSetup, sizeof(PRINTDLG)); // clear out this local
> structure
> printerSetup.lStructSize = sizeof(PRINTDLG); // set the structure length
> printerSetup.hwndOwner = Handle; // and owner handle
>
> bool result = PrintDlg(&printerSetup);
> if (result) {
> MessageDlg("Ok", mtInformation, TMsgDlgButtons() << mbOK, 0);
> } else {
> MessageDlg("Error", mtError, TMsgDlgButtons() << mbOK, 0);
> }
>
If you get 0 for the return code from PrintDlg, check CommDlgExtendedError to find out the reason that the dialog returned 0.
Example:
if (result)
{ // it's OK
:
}
else
{
DWORD ErrorCode=CommDlgExtendedError();
#include <cderr.h>
switch(ErrorCode)
{
case PDERR_CREATEICFAILURE: ShowMessage("The PrintDlg function failed when it \
attempted to create an information context.");break;
case PDERR_DEFAULTDIFFERENT: ShowMessage("You called the PrintDlg function with \
the DN_DEFAULTPRN flag specified in the wDefault member of the DEVNAMES structure, but the printer described by the other structure members did not match the current default printer. (This
error occurs when you store the DEVNAMES structure and the user changes the default printer by using the Control Panel.) To use the printer described by the DEVNAMES structure, clear the
DN_DEFAULTPRN flag and call PrintDlg again. To use the default printer, replace the DEVNAMES structure (and the DEVMODE structure, if one exists) with NULL; and call PrintDlg again.");break;
case PDERR_DNDMMISMATCH: ShowMessage("The data in the DEVMODE and DEVNAMES \
structures describes two different printers.");break;
case PDERR_GETDEVMODEFAIL: ShowMessage("The printer driver failed to initialize \
a DEVMODE structure. (This error code applies only to printer drivers written \
for Windows versions 3.0 and later.");break;
case PDERR_INITFAILURE: ShowMessage("The PrintDlg function failed during \
initialization, and there is no more specific extended error code to describe \
the failure. This is the generic default error code for the function.");break;
case PDERR_LOADDRVFAILURE: ShowMessage("The PrintDlg function failed to load \
the device driver for the specified printer.");break;
case PDERR_NODEFAULTPRN: ShowMessage("A default printer does not exist.");break;
case PDERR_NODEVICES: ShowMessage("No printer drivers were found.");break;
case PDERR_PARSEFAILURE: ShowMessage("The PrintDlg function failed to parse the \
strings in the [devices] section of the WIN.INI file."); break;
case PDERR_PRINTERNOTFOUND: ShowMessage("The [devices] section of the WIN.INI \
file did not contain an entry for the requested printer.");break;
case PDERR_RETDEFFAILURE: ShowMessage("The PD_RETURNDEFAULT flag was specified \
in the Flags member of the PRINTDLG structure, but the hDevMode or hDevNames member was not NULL.");break;
case PDERR_SETUPFAILURE: ShowMessage("The PrintDlg function failed to load \
the required resources.");break;
default: MessageDlg("Error", mtError, TMsgDlgButtons() << mbOK, 0); break;
}
}
keith
Technical Details
Message-ID:
<41C1CF74.149A84CF@sbcglobal.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41bfe84c$1@newsgroups.borland.com> <6ro0s0pgsjn6kr7lnhkb68gtfkr2g0glm2@4ax.com> <41c162f7@newsgroups.borland.com> <41C19B3E.7A34D7BA@sbcglobal.net> <41c1a15b$1@newsgroups.borland.com> <41C1A8C1.45910074@sbcglobal.net> <41c1ab73$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6620db7697e43cb9 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <41C1CF74.149A84CF@sbcglobal.net> Date: Thu, 16 Dec 2004 12:09:56 -0600 From: Keith <kdopson@sbcglobal.net> X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Printer properties References: <41bfe84c$1@newsgroups.borland.com> <6ro0s0pgsjn6kr7lnhkb68gtfkr2g0glm2@4ax.com> <41c162f7@newsgroups.borland.com> <41C19B3E.7A34D7BA@sbcglobal.net> <41c1a15b$1@newsgroups.borland.com> <41C1A8C1.45910074@sbcglobal.net> <41c1ab73$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.71.227.85 X-Trace: newsgroups.borland.com 1103220596 65.71.227.85 (16 Dec 2004 10:09:56 -0800) Lines: 70 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail