Getting available papersizes from printerdriver. 
Author Message
 Getting available papersizes from printerdriver.

I would greatly appreciate any help with enumerating forms for NT.
I've tried the code at the bottom but it always comes back with what looks
all the forms available for all the printers that are installed. It
certainly isn't the same list as the print setup dialogs use.

Am I missing something here?



>>I want to create a list with all the available papersizes of the used
>>printer. I think I should do this with DEVMODE, but I've tried a lot, but
>>cannot get all the papersizes, only the one currently selected.
>>This is the code I use :

>>PRINTDLG FAR * pPrintDlg = new PRINTDLG;
>>DEVMODE FAR *lpDevMode=
>>   (DEVMODE FAR*)::GlobalLock(pPrintDlg->hDevMode);

>>//Now I can read/write the selected papersize with :
>>if (lpDevMode->dmPaperSize != DMPAPER_A4)
>>        lpDevMode->dmPaperSize = DMPAPER_A4);

>>Thanks for reading, please help me out !!

>I wrote some sample code that handles what you are trying to do, but only
>works on an NT machine.
>You can use the EnumForms () api as such:

>// Open the printer and get its handle

> HANDLE PrinterHandle = 0;
> BOOL bSuccess = OpenPrinter (lpszDeviceName,
>                                                        &PrinterHandle,
>                                                        NULL);

>  FORM_INFO_1 *fi;
>  DWORD dwBytesNeeded = 0;
>  DWORD dwNumStructsNeeded = 0;

>//    This first call identifies how much memory you will need to allocate
>//    in order to store the returned info in the second call to EnumForms()
>  EnumForms (PrinterHandle, 1, NULL, 0,
>                         &dwBytesNeeded, &dwNumStructsNeeded);

>//    allocate enough memory for your structs
>  fi = (FORM_INFO_1*) new char [dwBytesNeeded];

>  EnumForms (PrinterHandle, 1, (UCHAR*)fi, dwBytesNeeded,
>                         &dwBytesNeeded, &dwNumStructsNeeded);


>//    clean up when you are done
>  delete [] fi;


>Your paper sizes will be returned to you in the FORM_INFO_1 structure

>Hope this helps,

Sun, 30 Sep 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Getting available papersizes from printerdriver.

2. Getting name of PrinterDriver files for different version of Windows

3. Getting available SQL Servers/Oracle Databases

4. Getting available COM ports

5. Getting a list of available serial ports (Visual C++)

6. Printing...PaperSize

7. How to get papersize in CView::OnBeginPrint?

8. Change papersize in printing

9. How to get papersize in CView::OnBeginPrint?

10. PaperSize matter

11. gets( ) gets crash

12. Gets() Considered Harmful (was: gets() messed up ?)


Powered by phpBB® Forum Software