Article View: borland.public.cppbuilder.nativeapi
Article #7841Re: Printer properties
From: Bob Gonder
Date: Thu, 16 Dec 2004 16:21
Date: Thu, 16 Dec 2004 16:21
79 lines
3519 bytes
3519 bytes
Thomas J. wrote:
>Oh sorry I used to work with the VCL. It would be great if you could send me
>a code snippet how to open the dialog.
The following is commented out of my production code because I didn't
want to burden my users with the MS arcanea.
HDC printerDC;
int printerJob;
/*optional*/
static HGDIOBJ oldPrinterFont; /*module local*/
static HFONT printerFont;
//RptLabel is the name that will show in the Printer Jobs queue.
BOOL _stdcall setup_printer(char*RptLabel, DWORD rows, DWORD cols)
{
PRINTDLG pd;
DOCINFO lpdi;
bPrint=TRUE;
ReportLabel=RptLabel;
// Initialize the PRINTDLG members.
pd.lStructSize = sizeof(PRINTDLG);
pd.hDevMode = (HANDLE) NULL;
pd.hDevNames = (HANDLE) NULL;
pd.Flags = PD_RETURNDC|PD_USEDEVMODECOPIESANDCOLLATE;
pd.hwndOwner = hWnd;
pd.hDC = (HDC) NULL;
pd.nFromPage = 1;
pd.nToPage = 1;
pd.nMinPage = 0;
pd.nMaxPage = 0;
pd.nCopies = 1;
pd.hInstance = (HANDLE) NULL;
pd.lCustData = 0L;
pd.lpfnPrintHook = (LPPRINTHOOKPROC) NULL;
pd.lpfnSetupHook = (LPSETUPHOOKPROC) NULL;
pd.lpPrintTemplateName = (LPSTR) NULL;
pd.lpSetupTemplateName = (LPSTR) NULL;
pd.hPrintTemplate = (HANDLE) NULL;
pd.hSetupTemplate = (HANDLE) NULL;
if( 0==allow_PTD ) pd.Flags |= PD_DISABLEPRINTTOFILE;
// Display the PRINT dialog box.
PrintDlg(&pd);
if( 0==(printerDC=pd.hDC) ) return FALSE;
/*my code to pick best-fit font for the report */
/*sets printerFont*/
/*ignore this line to use default font*/
oldPrinterFont=setup_font(rows,cols);
lpdi.cbSize=sizeof(DOCINFO);
lpdi.lpszDocName=ReportLabel;
lpdi.lpszOutput=(pd.Flags & PD_PRINTTOFILE) ? "FILE:" : NULL;
//NULL for printerDC
lpdi.lpszDatatype="RAW"; // Windows 95 only; ignored
lpdi.fwType=0; // Banding: Windows 95 only;
printerJob=StartDoc(printerDC,&lpdi);
if( printerJob<1 )
{ ErrorBox2(GetLastError(),"Printer (StartDoc) Error",
&printerfile_port);
/*Ignore next 2 lines if using default font*/
SelectObject(printerDC,oldPrinterFont);//RestoreOriginalFont
DeleteObject(printerFont);//DeleteMyFont
DeleteDC(printerDC);
return FALSE;
};
StartPage(printerDC);
//I use ExtTextOut to position each string, so use TA_NOUPDATECP
SetTextAlign(printerDC,TA_LEFT+TA_TOP+TA_NOUPDATECP);
>//If Bk isn't transparent then subsequent lines/chars can clip previous data
SetBkMode (printerDC, TRANSPARENT);
return TRUE;
}
Technical Details
Message-ID:
<r2c3s0ta1bn5u16c3cmv5fi5nf3bfn09cr@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41bfe84c$1@newsgroups.borland.com> <6ro0s0pgsjn6kr7lnhkb68gtfkr2g0glm2@4ax.com> <41c162f7@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 From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Printer properties Date: Thu, 16 Dec 2004 08:21:34 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <r2c3s0ta1bn5u16c3cmv5fi5nf3bfn09cr@4ax.com> References: <41bfe84c$1@newsgroups.borland.com> <6ro0s0pgsjn6kr7lnhkb68gtfkr2g0glm2@4ax.com> <41c162f7@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.147.66 X-Trace: newsgroups.borland.com 1103214093 67.77.147.66 (16 Dec 2004 08:21:33 -0800) Lines: 82 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail