I have an dialog-based application that creates a plot in a CFrameWnd object and a landscape orientation. Most printers, however, are setup for portrait output by default. My application can bring up the print dialog box, but unless the user manually changes the orientation to landscape, the plot doesn't display properly. IF THE USER SELECTES LANDSCAPE THE PRINTOUT IS CORRECT. I would like to set the orientation in the printer Properties dialog box to landscape automatically.
The CPrintDialog allows for various PD_xxx flags, but orientation is not one of them. Orientation is buried in the DEVMODE structure which I cannot seem to "get to" until AFTER the dialog box returns. I can then query dmOrientation, but setting it to 2 (landscape) has no effect on the printout.
Here is the portion of code that prints the plot:
void CXPlot::OnPlotFilePrint() // CXPlot derived from CFrameWnd
// create a device context and a print dialog box, attach the two,
// and pass the device context to the draw routine to "redraw" the plot
CDC dc; // get a device context
CPrintDialog dlg(FALSE); // create a print dialog box
if (dlg.DoModal() == IDOK) // display the print dialog box
dc.Attach(dlg.GetPrinterDC()); // attach the printer dc
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "My Plot";
this->DrawSetupPrint(&dc); // setup scaling
this->Draw(&dc); // draw the plot on the printer
I have tried calling the following code from various points in the above:
void CMyApp::SetPrinterOrientation(UINT orientation)
PRINTDLG dlg; // get a PRINTDLG structure
DEVMODE FAR *pDevMode; // pointer to a DEVMODE structure
dlg.lStructSize = (DWORD)sizeof(PRINTDLG);
if (this->GetPrinterDeviceDefaults(&dlg)) // a CWinApp function
if ((pDevMode = (DEVMODE FAR *)::GlobalLock(m_hDevMode)) != NULL)
pDevMode->dmOrientation = orientation;
The displayed orientation is always Portrait. There must be a way I can automatically set the orientation to Landscape, isn't there?