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

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
ICRAsked:
Who is Participating?
 
RockErwinCommented:
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
 
ICRAuthor Commented:
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
 
ICRAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RockErwinCommented:
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
 
ICRAuthor Commented:
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
 
RockErwinCommented:
You can use onprepareprinting to modify the devmode structure
0
 
ICRAuthor Commented:
But there is no devmode structure in OnPreparePrinting - it hasn't been created yet
0
 
ICRAuthor Commented:
(the GetDevMode() func returns NULL)
0
 
RockErwinCommented:
Call GetPrinterDeviceDefaults method
0
 
ICRAuthor Commented:
Are you saying I should create my own devmode structure and it would work?
0
 
RockErwinCommented:
GetPrinterDeviceDefaults method of CWinApp would initialize the m_hDevMode member variable.
0
 
ICRAuthor Commented:
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
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation.

SpideyMod
Community Support Moderator @Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.