Can anyone tell me how to set the paper size and other printer properties without bringing up the printer setup dialog box? I tried AddForm and SetForm API function. However, the currently selected printer form doesn't seem to change.
Thanks
Sugunan
This is a discussion on How to set paper size for the default printer through a program? within the Windows Programming forums, part of the Platform Specific Boards category; Can anyone tell me how to set the paper size and other printer properties without bringing up the printer setup ...
Can anyone tell me how to set the paper size and other printer properties without bringing up the printer setup dialog box? I tried AddForm and SetForm API function. However, the currently selected printer form doesn't seem to change.
Thanks
Sugunan
Try,
PageSetUp->lStructSize=sizeof(PAGESETUPDLG) ;
PageSetUp->hwndOwner= hWnd ;
PageSetUp->hDevMode = NULL ;
PageSetUp->hDevNames= NULL;
PageSetUp->Flags=PSD_RETURNDEFAULT;
//stack the structure with data for the default printer
PageSetupDlg(PageSetUp);
This should call the Print Dlg without showing it, returning the default printers settings. The DevMode struct will contain the paper size.
Also you can use the EnumPrinters() function, with the PRINTER_ENUM_DEFAULT flag. You will need to know what OS is running, to tell what PRINT_INFO struct to use, and watch for truncated printer names under NT/2000.
Then create a DC and use GetDeviceCaps() on the printer DC.
iWidth =GetDeviceCaps(hdcTemp,HORZRES);
iHeight =GetDeviceCaps(hdcTemp,VERTRES);
I find, under NT/2000
GetProfileString("windows", "device", (LPCTSTR) &szBuffer,(LPTSTR) &szOutputString, 255);
will get the printer name without the truncation. (If the printer has a long driver name it won't fit in the string, the last characters are lost and so you can't getDC with it)
Isn't this easy!
/////////
I should read these questions more carefully. This is how to GET the paper size.
Last edited by novacain; 08-30-2001 at 09:46 PM.
Dear Novacain,
thank you for the fast response and the tip to execute the Print Setup Dialog without actually showing it. May be there is a way on similar lines to set the property also. I shall read the MSDN documantation in detail.
regards
Sugunan
A way round the problem may be to save the data, DEVNAME and DEVMODE from the PAGESETUP struct, to disk and load them up when you need a new print.
All you need are the settings to save in the first place.
Thanks for the tip.
Is it necessary to free the HGLOBAL returned in the hDevMode parameter? MSDN doesn't say anything about this.
thanks
Sugunan
As far as I know you do not have to free the HGLOBAL returned DEVMODE or DEVNAME structure.
You may have to use GlobalLock on them to 'type cast' them to the structures to use the data returned in them.