From: Mike Silva on
Hello,

I'm developing an application that uses two printers. One is a normal
page printer, whatever the user has installed, and the other is a
receipt printer that prints on 3.125 inch paper. I need to be able to
find and select (via code) the installed receipt printer without going
through any printer selection dialogs. OTOH, I will use standard
printer selection dialogs when printing to the page printer.

So, what I need is a way to search through the installed printers and
get info on each printer. I could reliably detect the receipt printer
based on the paper width. I'm not sure what else I could search on
that would guarantee a proper ID, but I'm open to suggestions. This
could be as simple as, on startup, attaching a DC to each available
printer and using GetDeviceCaps to determine if it's the receipt
printer, but what I don't know is how to iterate through the list of
installed printers. Many thanks for any pointers.

Mike
From: David Lowndes on
>... but what I don't know is how to iterate through the list of
>installed printers.

Mike,

EnumPrinters looks like a good starting point.

Dave
From: Mike Silva on
On May 7, 10:40 am, David Lowndes <Dav...(a)example.invalid> wrote:
> >... but what I don't know is how to iterate through the list of
> >installed printers.
>
> Mike,
>
> EnumPrinters looks like a good starting point.
>
> Dave

Sure does. I had already searched for "EnumPrinterDevices" based on
the existence of EnumDisplayDevices, and of course got no hits.
Thanks!

Mike
From: Mike Silva on
On May 7, 10:40 am, David Lowndes <Dav...(a)example.invalid> wrote:
> >... but what I don't know is how to iterate through the list of
> >installed printers.
>
> Mike,
>
> EnumPrinters looks like a good starting point.
>
> Dave

OK, I'm stuck again. I can get printer info from EnumPrinters into
e.g. PRINTER_INFO_1 structs. Then I can get a HANDLE to a printer via
OpenPrinter(). But I don't know how to get from the resulting HANDLE
to a DC via which I can use GetDeviceCaps() to examine the printer,
and then later to select a printer for printing. So I've got a
printer name and from that I can get a HANDLE, and at that point I'm
stuck. How do I go from HANDLE to CDC? The HANDLE-based equivalent
of

CDC dc;
CPrintDialog printDlg( FALSE );
dc.Attach(printDlg.CreatePrinterDC());

Mike
From: Mike Silva on
On May 7, 1:59 pm, Mike Silva <snarflem...(a)yahoo.com> wrote:
> On May 7, 10:40 am, David Lowndes <Dav...(a)example.invalid> wrote:
>
> > >... but what I don't know is how to iterate through the list of
> > >installed printers.
>
> > Mike,
>
> > EnumPrinters looks like a good starting point.
>
> > Dave
>
> OK, I'm stuck again.  I can get printer info from EnumPrinters into
> e.g. PRINTER_INFO_1 structs.  Then I can get a HANDLE to a printer via
> OpenPrinter().  But I don't know how to get from the resulting HANDLE
> to a DC via which I can use GetDeviceCaps() to examine the printer,
> and then later to select a printer for printing.  So I've got a
> printer name and from that I can get a HANDLE, and at that point I'm
> stuck.  How do I go from HANDLE to CDC?  The HANDLE-based equivalent
> of
>
> CDC dc;
> CPrintDialog printDlg( FALSE );
> dc.Attach(printDlg.CreatePrinterDC());
>
> Mike

After more searching it seems that I might not need the HANDLE or
OpenPrinter(). It seems I should be able to do this:

PRINTER_INFO_2 * ppi2 = &pi2[ i ]; // one of the enumerated printers
CDC dc;
dc.CreateDC( ppi2->pDriverName, ppi2->pPrinterName, ppi2->pPortName,
NULL );

If this doesn't work as I expect then, sadly, I'll be back.

Mike