Use this method to implement a customized print dialog:
Copy the PRINTDLGORD dialog template from COMMDLG.RC to the application's .RC file. (In Visual C++ 4.x and 5.0, this dialog template resides in the file INCLUDE\PRNSETUP.DLG) To do this:
Open MSVC\MFC\SAMPLES\APSTUDIO\COMMDLG.RC and your application's resource file by using AppStudio (the Resource Editor). This file is in \msdev\samples\mfc\general\clipart under 32-bit Visual C++. For Visual C++ 6.0, you can find this file in ..\samples\vc98\mfc\general\clipart on the MSDN CD that ships with Visual C++ 6.0. If you are using Visual C++ 4.x or 5.0, add the line #include "windows.h" to the top of the file the file INCLUDE\PRNSETUP.DLG. Save and close this file. Reopen it as "Resources". (See the "Open As" combo box in the File Open dialog box.)
In the resource browser window of the "from" file, select the PRINTDLGORD (id 1538) dialog resource.
As you hold down the CTRL key, drag the resource to the resource browser window of the "to" file.
NOTE: Dragging the resource without holding the CTRL key moves the resource rather than copies it.
Make the necessary changes to the copied dialog template. NOTE: None of the controls present in the original dialog template should be deleted. Deleting the controls will cause a problems in the DoDataExchange function of CPrintDialog. Instead, the unwanted controls should be disabled and/or hidden in an overridden OnInitDialog member function of your CPrintDialog-derived class.
Use ClassWizard to add a C++ class (say, CMyPrintDialog) for this dialog template. Derive this new class from CDialog with PRINTDLGORD as the dialog ID. (NOTE: In Visual C++ 4.x and 5.0 this class can be derived directly from CPrintDialog.)
Change all references from CDialog to CPrintDialog in both the header and implementation file of the newly created class. (This step is not necessary if you have derived your class directly from CPrintDialog.)
Because the constructor of CPrintDialog differs from CDialog, modify the constructor of CMyPrintDialog using this code: (NOTE: this step is not necessary if you have derived your class directly from CPrintDialog.) // 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
}
Modify the CView-derived class (say, CMyView) to use the customized print dialog by using this code: // Implementation file of the view (say, in myview.cpp)
...
#include "myprintd.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 will
// be used.
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.lpPrintTemplateName =
MAKEINTRESOURCE(PRINTDLGORD); // 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);
}
Copy the PRINTDLGORD dialog template from COMMDLG.RC to the application's .RC file. (In Visual C++ 4.x and 5.0, this dialog template resides in the file INCLUDE\PRNSETUP.DLG) To do this:
Open MSVC\MFC\SAMPLES\APSTUDIO\COMMDLG.RC and your application's resource file by using AppStudio (the Resource Editor). This file is in \msdev\samples\mfc\general\clipart under 32-bit Visual C++. For Visual C++ 6.0, you can find this file in ..\samples\vc98\mfc\general\clipart on the MSDN CD that ships with Visual C++ 6.0. If you are using Visual C++ 4.x or 5.0, add the line #include "windows.h" to the top of the file the file INCLUDE\PRNSETUP.DLG. Save and close this file. Reopen it as "Resources". (See the "Open As" combo box in the File Open dialog box.)
In the resource browser window of the "from" file, select the PRINTDLGORD (id 1538) dialog resource.
As you hold down the CTRL key, drag the resource to the resource browser window of the "to" file.
NOTE: Dragging the resource without holding the CTRL key moves the resource rather than copies it.
Make the necessary changes to the copied dialog template. NOTE: None of the controls present in the original dialog template should be deleted. Deleting the controls will cause a problems in the DoDataExchange function of CPrintDialog. Instead, the unwanted controls should be disabled and/or hidden in an overridden OnInitDialog member function of your CPrintDialog-derived class.
Use ClassWizard to add a C++ class (say, CMyPrintDialog) for this dialog template. Derive this new class from CDialog with PRINTDLGORD as the dialog ID. (NOTE: In Visual C++ 4.x and 5.0 this class can be derived directly from CPrintDialog.)
Change all references from CDialog to CPrintDialog in both the header and implementation file of the newly created class. (This step is not necessary if you have derived your class directly from CPrintDialog.)
Because the constructor of CPrintDialog differs from CDialog, modify the constructor of CMyPrintDialog using this code: (NOTE: this step is not necessary if you have derived your class directly from CPrintDialog.) // 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
}
Modify the CView-derived class (say, CMyView) to use the customized print dialog by using this code: // Implementation file of the view (say, in myview.cpp)
...
#include "myprintd.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 will
// be used.
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.lpPrintTemplateName =
MAKEINTRESOURCE(PRINTDLGORD); // 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);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货