Article ID: 132909
Article Last Modified on 11/21/2006
// Header file of CMyPrintDialog.
class CMyPrintDialog : public CPrintDialog
{
// Construction.
public:
// The arguments to the following constructor closely match
// CPrintDialog. Note the difference in the second argument.
CMyPrintDialog(BOOL bPrintSetupOnly,
// TRUE for Print Setup, FALSE for Print Dialog.
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES |
PD_HIDEPRINTTOFILE,
// Combination of flags. Refer to the Windows SDK
// documentation for PRINTDLG structure for a
// description of all the flags that can be used.
CWnd* pParentWnd = NULL);
// Rest of the class declaration.
...
DECLARE_MESSAGE_MAP()
};
// Implementation file of CMyPrintDialog.
CMyPrintDialog::CMyPrintDialog(BOOL bPrintSetupOnly,
DWORD dwFlags /* = PD_ALLPAGES | PD_USEDEVMODECOPIES |
PD_HIDEPRINTTOFILE */,
CWnd* pParentWnd /* = NULL */)
: CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd)
{
//{{AFX_DATA_INIT(CMyPrintDialog)
// NOTE: the ClassWizard will add member initialization here.
//}}AFX_DATA_INIT
}
// Implementation file of the view (for example, in myview.cpp).
...
#include "MyPrintDialog.h" // Include the CMyPrintDialog header file.
...
// Override OnPreparePrinting of the CView-derived class as below:
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// Delete the CPrintDialog object created in the CPrintInfo
// constructor, and substitute with customized print dialog.
delete pInfo->m_pPD;
// Construct and substitute with customized print dialog.
pInfo->m_pPD = new CMyPrintDialog(FALSE);
// Set the page range.
pInfo->m_pPD->m_pd.nMinPage = 1; // one based page numbers.
pInfo->m_pPD->m_pd.nMaxPage = 0xffff; // how many pages is unknown.
// Change the PRINTDLG struct so that the custom print dialog box will
// be used.
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.lpPrintTemplateName =
MAKEINTRESOURCE(1538);
// Set the Flags of the PRINTDLG structure as shown, else the
// changes will have no effect.
pInfo->m_pPD->m_pd.Flags |= PD_ENABLEPRINTTEMPLATE;
// For details about these flags, refer to the SDK documentation
// on the PRINTDLG structure.
return DoPreparePrinting(pInfo);
}Additional query words: CFileDialog
Keywords: kbcode kbfaq kbhowto kbprint kbprogramming KB132909