Solved

(urgent) Setting paper size and source bin data into CPrintDialog

Posted on 2002-07-08
15
549 Views
Last Modified: 2013-11-20
Hi,

I'm writing a page setup dialog for a program. To print the document I use CPrintDialog. I need a way to set the paper size and source bin settings from my page setup dialog into the CPrintDialog when it is activated. The data is stored in a string (like "A4" or "Automatically Select").

Could anyone please help me with this?

Thanks in advance,
ICR
0
Comment
Question by:ICR
15 Comments
 

Accepted Solution

by:
RockErwin earned 50 total points
ID: 7140309
You have to modify the DevMode structure
CWinApp has a member m_hDevMode which specifies the printing options.

The following code is available.

CPageSetupDialog dlg;
PRINTDLG pd;
pd.lStructSize = (DWORD)sizeof(PRINTDLG) ;
BOOL bRet = GetPrinterDeviceDefaults(&pd) ;
if (bRet)
{
/* protect memory handle with ::GlobalLock and ::GlobalUnlock */
DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(m_hDevMode) ;
// set orientation to portrait
pDevMode->dmOrientation = DMORIENT_LANDSCAPE ;
pDevMode->dmPaperSize  = DMPAPER_A3;
pDevMode->dmDefaultSource = DMBIN_FIRST; // Change source
::GlobalUnlock(m_hDevMode) ;
}
// Initialize dialog with m_hDevMode
dlg.m_psd.hDevMode = m_hDevMode;
// Call domdoal
dlg.DoModal();
0
 

Author Comment

by:ICR
ID: 7141656
I already knew that I would have to change the DEVMODE, that is not my question. First, WHERE do I change the DEVMODE - OnPrepareDC?OnBeginPrinting?somwhere else?
Second, as I've stated in the question, the data I have is stored in strings. I need to convert it into the ID the DEVMODE contains.
0
 

Author Comment

by:ICR
ID: 7141657
I already knew that I would have to change the DEVMODE, that is not my question. First, WHERE do I change the DEVMODE - OnPrepareDC?OnBeginPrinting?somwhere else?
Second, as I've stated in the question, the data I have is stored in strings. I need to convert it into the ID the DEVMODE contains.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Expert Comment

by:RockErwin
ID: 7142365
You have to store the id's of the paper and bin rather than the string or made a lookup table for which given a string u can find the corresponding id

You have to do add a commad handler for ID_FILE_PRINT in the view class and after modifying the DevMode structure call the base view class OnFilePrint method.
0
 

Author Comment

by:ICR
ID: 7142866
How can I modify the devmode in OnFilePrint when it's not created yet - isn't OnFilePrint the method which activates the printing dialog?
0
 

Expert Comment

by:RockErwin
ID: 7142990
You can use onprepareprinting to modify the devmode structure
0
 

Author Comment

by:ICR
ID: 7143571
But there is no devmode structure in OnPreparePrinting - it hasn't been created yet
0
 

Author Comment

by:ICR
ID: 7144191
(the GetDevMode() func returns NULL)
0
 

Expert Comment

by:RockErwin
ID: 7145107
Call GetPrinterDeviceDefaults method
0
 

Author Comment

by:ICR
ID: 7146202
Are you saying I should create my own devmode structure and it would work?
0
 

Expert Comment

by:RockErwin
ID: 7148066
GetPrinterDeviceDefaults method of CWinApp would initialize the m_hDevMode member variable.
0
 

Author Comment

by:ICR
ID: 7185723
I tried to call GetPrinterDeviceDefaults before using the devmode, but I still get a NULL pointer. Isn't there a way to create a devmode structure in OnPreparePrinting method? Or is there any other method I should try changing the devmode in?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8451622
Upon review of the comments here, I am recommending this disposition:

        points to RockErwin

Please post a comment if you disagree.

DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8492651
per recommendation.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Line meaning 9 88
sumHeights  challenge 17 75
Not needed 13 120
how to use laptop or pad camera in vb.net windows application 2 86
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question