CView::OnFilePrint();和CView::OnFilePrintPreview();在打印中出错
我的代码如下,请高手赐教:
CPrintView类:
#include "stdafx.h"
#include "Shipstate.h"
#include "PrintView.h"
#include "PrintFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrintView
IMPLEMENT_DYNCREATE(CPrintView, CView)
CPrintView::CPrintView()
{
IsPrint = TRUE;
}
CPrintView::~CPrintView()
{
}
BEGIN_MESSAGE_MAP(CPrintView, CView)
//{{AFX_MSG_MAP(CPrintView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrintView drawing
void CPrintView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CPrintView diagnostics
#ifdef _DEBUG
void CPrintView::AssertValid() const
{
CView::AssertValid();
}
void CPrintView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPrintView message handlers
void CPrintView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnBeginPrinting(pDC, pInfo);
CPrintFrame *pFrame=(CPrintFrame* )GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_BEGIN_PRINTING,(WPARAM )pDC,(LPARAM) pInfo);
}
void CPrintView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnEndPrinting(pDC, pInfo);
CPrintFrame *pFrame=(CPrintFrame *) GetParent();
pFrame-> m_pCallerDlg ->SendMessage(WM_END_PRINTING,(WPARAM)pDC,(LPARAM)pInfo);
if (IsPrint)
{
GetParent() ->DestroyWindow();
}
}
void CPrintView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{
CView::OnEndPrintPreview(pDC, pInfo, point, pView);
GetParent() ->DestroyWindow();
}
BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
if (DoPreparePrinting(pInfo))
return TRUE;
else
{
GetParent() ->DestroyWindow();
return FALSE;
}
return CView::OnPreparePrinting(pInfo);
}
void CPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrint(pDC, pInfo);
CPrintFrame *pFrame =(CPrintFrame *) GetParent();
pFrame ->m_pCallerDlg ->SendMessage(WM_MY_PRINT,(WPARAM)pDC,(LPARAM)pInfo);
}
void CPrintView::OnMyPrint()
{
GetParent() ->ShowWindow(SW_SHOWMINIMIZED);
IsPrint=TRUE;
CView::OnFilePrint(); //打印时每次运行到错误的地方。
}
void CPrintView::OnMyPreview()
{
GetParent() ->ShowWindow(SW_SHOWMAXIMIZED);
IsPrint =FALSE;
CView::OnFilePrintPreview(); ////打印预览时每次运行到错误的地方。
}
CPrintFrame类:
其中:CWnd *m_pWnd; CDialog *m_pDialog; CPrintView *m_pView;
#include "stdafx.h"
#include "PrintFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrintFrame
IMPLEMENT_DYNCREATE(CPrintFrame, CFrameWnd)
CPrintFrame::CPrintFrame()
{
m_pCallerDlg=NULL;
m_pWnd = AfxGetApp() ->m_pMainWnd;
AfxGetApp() ->m_pMainWnd =this;
}
CPrintFrame::~CPrintFrame()
{
}
BEGIN_MESSAGE_MAP(CPrintFrame, CFrameWnd)
//{{AFX_MSG_MAP(CPrintFrame)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrintFrame message handlers
void CPrintFrame::OnDestroy()
{
CFrameWnd::OnDestroy();
if (m_pView!=NULL)
{
m_pView->DestroyWindow();
}
AfxGetApp() ->m_pMainWnd =m_pWnd;
}
BOOL CPrintFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
{
m_pView =new CPrintView();
m_pView ->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,AFX_IDW_PANE_FIRST,pContext);
return TRUE;
}
CShipInfo类:
//打印预览
void CShipInfo::OnPrintview()
{
// TODO: Add your control notification handler code here
//UpdateData(TRUE);
CPrintFrame *pFrame = new CPrintFrame;
pFrame->m_pCallerDlg = this;
pFrame->Create(NULL,"打印预览",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0));
pFrame->m_pView ->OnMyPreview();
}
//打印
void CShipInfo::OnPrint()
{
// TODO: Add your control notification handler code here
//UpdateData(TRUE);
CPrintFrame *pFrame =new CPrintFrame;
pFrame ->m_pCallerDlg =this;
pFrame ->Create(NULL,"打印",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0));
pFrame ->m_pView ->OnMyPrint();
}
BEGIN_MESSAGE_MAP(CShipInfo, CDialog)
//{{AFX_MSG_MAP(CShipInfo)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_BEGIN_PRINTING,OnBeginPrinting)
ON_MESSAGE(WM_END_PRINTING,OnEndPrinting)
ON_MESSAGE(WM_MY_PRINT,OnMyPrint)
END_MESSAGE_MAP()
CShipInfo.h中
protected:
HRESULT OnBeginPrinting(WPARAM wParam,LPARAM lParam);
HRESULT OnEndPrinting(WPARAM wParam,LPARAM lParam);
HRESULT OnMyPrint(WPARAM wParam,LPARAM lParam);
希望高手赶快来解决,我真的是解决不了了,要崩溃了。
[解决办法]
CView::OnFilePrint();
CView::OnFilePrintPreview();
这俩的定义呢??
[解决办法]
这俩需要你改的!
lz可以看看下面的连接:
http://www.vckbase.com/document/viewdoc/?id=1618
[解决办法]
你应该单步看看在那里出错时到底在哪行因为什么原因出错得,直接看代码往往看不出错误