mfc printing problem -- getting printer info 
Author Message
 mfc printing problem -- getting printer info

The onprepareprinting function displays the printing dialog. my problem
is that i can't compute the doc size (in pages) at this point. so i have
to leave that part of the dialog blank. in the onbeginprinting function
i can compute the #pages by using the information:
pDC->GetDeviceCaps(VERTRES)

as far as i can see, the device context for the printer is not available
until that point. is there any way to get the information about the
printer before that (say, in the onprepareprinting function). i tried
creating a device context using the printer's driver name, etc. and then
using the getprinter function. but i could not get it to work. Any ideas
would be greatly appreciated.

Thanks,
bob

  brussell.vcf
< 1K Download


Mon, 03 Feb 2003 03:00:00 GMT  
 mfc printing problem -- getting printer info

Bob,

Try this in OnPreparePrinting...

   CWinApp *pApp = AfxGetApp();
   PRINTDLG pd;
   pd.lStructSize = (DWORD)sizeof(PRINTDLG);
   BOOL bRet = pApp->GetPrinterDeviceDefaults(&pd);
   if(bRet)
      int nVertRes = GetDeviceCaps(pd->hDC, VERTRES);

This uses the Win32 API version of GetDeviceCaps after retrieving the
information about the default printer from the application class.

Dave Smith


Quote:
> The onprepareprinting function displays the printing dialog. my problem
> is that i can't compute the doc size (in pages) at this point. so i have
> to leave that part of the dialog blank. in the onbeginprinting function
> i can compute the #pages by using the information:
> pDC->GetDeviceCaps(VERTRES)

> as far as i can see, the device context for the printer is not available
> until that point. is there any way to get the information about the
> printer before that (say, in the onprepareprinting function). i tried
> creating a device context using the printer's driver name, etc. and then
> using the getprinter function. but i could not get it to work. Any ideas
> would be greatly appreciated.

> Thanks,
> bob



Mon, 03 Feb 2003 03:00:00 GMT  
 mfc printing problem -- getting printer info

I think that i have answered my own question to some degree. the following
ugly code seems to do the trick:
 CPrintDialog *pDial;
 pDial = new CPrintDialog(false);
 pDial->m_pd.hDevNames = NULL;
 bool ok = pDial->GetDefaults();
 tagDEVNAMES *x;
// x = (tagDEVNAMES*)pDial->m_pd.hDevNames;
// char *y = (char*)(x);
// y += x->wDeviceOffset;
 HDC hh = pDial->m_pd.hDC;
 CDC * pDC = CDC::FromHandle(hh);
 int z = pDC->GetDeviceCaps(VERTRES);

the 3 lines commented out puzzled me. i was not able to get any information
from the structure m_pd. i don't understand why.

Bob

Quote:

> The onprepareprinting function displays the printing dialog. my problem
> is that i can't compute the doc size (in pages) at this point. so i have
> to leave that part of the dialog blank. in the onbeginprinting function
> i can compute the #pages by using the information:
> pDC->GetDeviceCaps(VERTRES)

> as far as i can see, the device context for the printer is not available
> until that point. is there any way to get the information about the
> printer before that (say, in the onprepareprinting function). i tried
> creating a device context using the printer's driver name, etc. and then
> using the getprinter function. but i could not get it to work. Any ideas
> would be greatly appreciated.

> Thanks,
> bob

  brussell.vcf
< 1K Download


Mon, 03 Feb 2003 03:00:00 GMT  
 mfc printing problem -- getting printer info
You might check GetPrinterDeviceDefaults and CreatePrinterDC.
Have a look at CView::DoPreparePrinting (preview section) how
you could do it. However you will just be able to caculate the number
of pages for the current standard printer.

Hope this helps.

--

Uwe Kotyczka

http://ws56.tinst.uni-jena.de



| The onprepareprinting function displays the printing dialog. my problem
| is that i can't compute the doc size (in pages) at this point. so i have
| to leave that part of the dialog blank. in the onbeginprinting function
| i can compute the #pages by using the information:
| pDC->GetDeviceCaps(VERTRES)
|
| as far as i can see, the device context for the printer is not available
| until that point. is there any way to get the information about the
| printer before that (say, in the onprepareprinting function). i tried
| creating a device context using the printer's driver name, etc. and then
| using the getprinter function. but i could not get it to work. Any ideas
| would be greatly appreciated.
|
| Thanks,
| bob
|
|



Tue, 04 Feb 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: ActiveX CTL Getting Printer Info From Container

2. Getting page info (size) before printing

3. slightly OT: need help finding info on quering printers for info

4. Getting detailed info on using ADO with MFC

5. Getting Machine info Using MFC/API

6. Getting printer handle from Printer.hDC

7. Printing Debug Without Printer :: MFC

8. printer drivers and MFC printing routines

9. different printing results: ps-printer and non ps-printer

10. different printing results: ps-printer and non ps-printer

11. Problem getting info from a COblist

12. Problem printing to default HP printer

 

 
Powered by phpBB® Forum Software