Get a list of scanners/printers

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Get a list of scanners/printers

Postby Lena » Sat May 19, 2018 3:54 am

Tell me, please, how to get a list of scanners/printers that sees the computer.
Thank you.
Lena
BCBJ Master
BCBJ Master
 
Posts: 571
Joined: Sun Feb 06, 2011 1:28 pm

Re: Get a list of scanners/printers

Postby HsiaLin » Sat May 19, 2018 5:21 pm

Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{

    DWORD flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
    int level = 2;
    PRINTER_INFO_2* printerInfo;
    DWORD memsize, printer_count;

    EnumPrinters(flags, NULL, level, NULL, 0, &memsize, &printer_count);
    if (memsize < 1) return;

    BYTE* bytes = new BYTE[memsize];
    if (EnumPrinters(flags, NULL, level, bytes, memsize, &memsize, &printer_count))
    {
        printerInfo = (PRINTER_INFO_2*)bytes;
        for (UINT i = 0; i < printer_count; i++)
        {
            ShowMessage(printerInfo->pPrinterName);
            ShowMessage(printerInfo->pDriverName);
            printerInfo++;
        }
    }
    delete[] bytes;
}
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 299
Joined: Sun Jul 08, 2007 6:29 pm

Re: Get a list of scanners/printers

Postby Lena » Sun May 20, 2018 5:14 am

Thank You very much HsiaLin!

P.S.
I collect all the devices in ComboBox.
How to send a document for scanning after selecting in ComboBox?
Thanks.
Lena
BCBJ Master
BCBJ Master
 
Posts: 571
Joined: Sun Feb 06, 2011 1:28 pm

Re: Get a list of scanners/printers

Postby HsiaLin » Sun May 20, 2018 8:14 am

Lena wrote:I collect all the devices in ComboBox.
How to send a document for scanning after selecting in ComboBox?
Thanks.


If you are wanting to scan pictures or documents you will most likely have to use
TWAIN services. I dont know of any other way. TWAIN is highly complicated unless
you use a 3rd party component.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 299
Joined: Sun Jul 08, 2007 6:29 pm

Re: Get a list of scanners/printers

Postby HsiaLin » Sun May 20, 2018 9:18 am

After looking into it, an easier way to get printer names is just do it this way.
Saves a lot of code.

Code: Select all
     int x = Printer()->Printers->Count;
     TStringList *S = (TStringList*)Printer()->Printers;

     for(int t=0; t < x; ++t)
     {
        ComboBox1->Items->Add(S->Strings[t]);
     }

     S->Clear();
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 299
Joined: Sun Jul 08, 2007 6:29 pm

Re: Get a list of scanners/printers

Postby Lena » Mon May 21, 2018 12:31 am

Thank You very much!
Lena
BCBJ Master
BCBJ Master
 
Posts: 571
Joined: Sun Feb 06, 2011 1:28 pm

Re: Get a list of scanners/printers

Postby rlebeau » Tue May 22, 2018 1:29 pm

HsiaLin wrote:After looking into it, an easier way to get printer names is just do it this way.
Saves a lot of code.


You don't need the type-cast to TStringList:

Code: Select all
TStrings *S = Printer()->Printers;
int x = S->Count;
for(int t = 0; t < x; ++t)
{
    ComboBox1->Items->Add(S->Strings[t]);
}


This is even simpler:

Code: Select all
ComboBox1->Items->AddStrings(Printer()->Printers);
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1533
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA


Return to Technical

Who is online

Users browsing this forum: No registered users and 11 guests

cron