Article ID: 166130
Article Last Modified on 11/21/2006
extern void AFXAPI AfxGlobalFree(HGLOBAL hGlobal); // 4.1 or later
void CMyApp::UpdatePrinterSelection(BOOL bForceDefaults)
{
if (!bForceDefaults && m_hDevNames != NULL)
{
CWinApp::UpdatePrinterSelection(bForceDefaults);
}
else
{
// First time or Forced -- Get defaults
CPrintDialog pd(TRUE);
pd.GetDefaults();
if (m_hDevMode != NULL)
::GlobalFree(m_hDevMode);
// AfxGlobalFree for 4.1 or later
if (m_hDevNames != NULL)
::GlobalFree(m_hDevNames);
// AfxGlobalFree for 4.1 or later
m_hDevMode = pd.m_pd.hDevMode;
m_hDevNames = pd.m_pd.hDevNames;
// new code to set DMORIENT_LANDSCAPE
LPDEVMODE lp = (LPDEVMODE) ::GlobalLock(m_hDevMode);
ASSERT(lp);
lp->dmOrientation = DMORIENT_LANDSCAPE;
::GlobalUnlock(m_hDevMode);
}
}
Unfortunately, this is not a virtual function, so you'll need to override
all the functions in its call tree in the three cases below:
(CMyApp::UpdatePrinterSelection)
CWinApp::GetPrinterDeviceDefaults
Non-virtual, copy from MFC src
CView::DoPreparePrinting (non-virtual)
Non-virtual, copy from MFC src, change CWinApp* to CMyApp* in code,
include "docobj.h"
CView::OnPreparePrinting
Virtual, must override anyway
CView::OnFilePrint
Use ClassWizard
(CMyApp::UpdatePrinterSelection)
CWinApp::DoPrintDialog
Non-virtual, copy from MFC src, include "cderr.h"
CView::DoPreparePrinting
Non-virtual, see above
(CMyApp::UpdatePrinterSelection)
CWinApp::DoPrintDialog
Non-virtual, see above
CWinApp::OnFilePrintSetup
Use ClassWizard
For the non-virtual functions, just clone the base class code.
Keywords: kbhowto kbprint kbcmndlgprint kbcode KB166130