C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-30-2001, 09:11 PM   #1
Registered User
 
Join Date: Aug 2001
Posts: 3
Post How to set paper size for the default printer through a program?

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
Sugunan is offline   Reply With Quote
Old 08-30-2001, 09:43 PM   #2
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,452
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.
novacain is offline   Reply With Quote
Old 08-30-2001, 10:21 PM   #3
Registered User
 
Join Date: Aug 2001
Posts: 3
Thanks for the fast response

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
Sugunan is offline   Reply With Quote
Old 08-31-2001, 12:00 AM   #4
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,452
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.
novacain is offline   Reply With Quote
Old 08-31-2001, 09:16 PM   #5
Registered User
 
Join Date: Aug 2001
Posts: 3
Just one more question

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
Sugunan is offline   Reply With Quote
Old 09-03-2001, 09:45 PM   #6
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,452
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.
novacain is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues and questions about queues Nazgulled C Programming 36 12-13-2007 02:03 PM
Using variables in system() Afro C Programming 8 07-03-2007 12:27 PM
Trouble with DMA Segmentation Faults firestorm717 C Programming 2 05-07-2006 09:20 PM
OpenGL and Windows sean345 Game Programming 5 06-24-2002 10:14 PM
Tab Controls - API -KEN- Windows Programming 7 06-02-2002 09:44 AM


All times are GMT -6. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22