15,979
社区成员
发帖
与我相关
我的任务
分享
PrintFrame *pFrame = new PrintFrame;
pFrame->m_pCallerDlg = this;
pFrame->Create(NULL,"Curve Print",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0));
// TestProDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestPro.h"
#include "TestProDlg.h"
#include "math.h"
#include "TestDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestProDlg dialog
CTestProDlg::CTestProDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestProDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestProDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestProDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestProDlg)
DDX_Control(pDX, IDC_OCX1, m_wmpplayer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestProDlg, CDialog)
//{{AFX_MSG_MAP(CTestProDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_PRINT, OnPrint)
//}}AFX_MSG_MAP
ON_BN_CLICKED(ID_PRINT, OnPrint)
ON_MESSAGE(WM_MY_PRINT,OnMyPrint)
ON_MESSAGE(WM_BEGIN_PRINTING,OnBeginPrinting)
ON_MESSAGE(WM_END_PRINTING,OnEndPrinting)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestProDlg message handlers
BOOL CTestProDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CString strMediaPath = "F:\\vc\\vc++\\Insurance_test\\Debug\\ad.wmv";
CWMPMedia media = m_wmpplayer.newMedia(strMediaPath);
// m_wmpplayer.SetUrl("E:\\lonely.wmv");
m_wmpplayer.SetCurrentMedia(media);
m_wmpcontrols = m_wmpplayer.GetControls();
m_wmpsetings = m_wmpplayer.GetSettings();
m_wmpsetings.SetPlayCount(10);
m_wmpcontrols.play();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestProDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestProDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestProDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestProDlg::OnPrint()
{
// TODO: Add your control notification handler code here
PrintFrame *pFrame = new PrintFrame;
pFrame->m_pCallerDlg = this;
pFrame->Create(NULL,"Curve Print",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0));//就是这个窗口,如何在关闭他的时候不要把父窗口也给关闭了
pFrame->m_pView->OnMyPrint();
}
LRESULT CTestProDlg::OnMyPrint(WPARAM wParam,LPARAM lParam)
{
UINT gl_uNumOfPoints = 5;//只打印五行
CDC* pDC = (CDC*)wParam;
CPrintInfo* pInfo = (CPrintInfo *)lParam;
int nPageNumber = pInfo->m_nCurPage;
int i,j;
CFont *pOldFont;
CFont DataFont;
DataFont.CreatePointFont(120,"宋体",pDC);
if(nPageNumber==1)
{
TCHAR *pszTitle[7]={"Time","数值1","数值2","数值3","数值4","数值5","数值6"};
pOldFont=pDC->SelectObject(&DataFont);
//Rectangle用于画矩形
pDC->Rectangle(m_cxOffset,(int)((2.5 + PRINTMARGIN)*m_cyPrinter),m_cxOffset+m_cxWidth,(m_nLinesPerPage+3 + PRINTMARGIN)*m_cyPrinter+20);
for(i=1;i<5;i++)//加竖线
{
// pDC->MoveTo(m_cxOffset+i*m_cxWidth/4,(int)((2.5 + PRINTMARGIN)*m_cyPrinter));
// pDC->LineTo(m_cxOffset+i*m_cxWidth/4,(3 +m_nLinesPerPage+PRINTMARGIN)*m_cyPrinter+20);
}
pDC->MoveTo(m_cxOffset,(4 + PRINTMARGIN)*m_cyPrinter);
pDC->LineTo(m_cxOffset+m_cxWidth,(4 + PRINTMARGIN)*m_cyPrinter);
for(i=0;i<4;i++)//确认要显示的字段个数:pszTitle
{
//控制间距,与下相等
pDC->TextOut(m_cxOffset+80+i*m_cxWidth/5,(int)((2.8 + PRINTMARGIN)*m_cyPrinter),CString(pszTitle[i]));
}
for(i=0;i<(int)m_nLinesPerPage-1;i++)
{
CString str[7];
int nIndex = (nPageNumber-1)*(m_nLinesPerPage-1)+i;
if(nIndex<(int)gl_uNumOfPoints)
{
str[0].Format("%.3f",(double)(i+1));
str[1].Format("%.3f",1+sin(i));
str[2].Format("%.3f",1+cos(i));
str[3].Format("%.3f",1+sin(0.5*i));
for(j=0;j<7;j++)
{
//控制间距,与上相等
pDC->TextOut(m_cxOffset+80+j*m_cxWidth/5,(4 + PRINTMARGIN+i)*m_cyPrinter+5,str[j]);
}
}
}
pDC->SelectObject (pOldFont);
}
return TRUE;
}
LRESULT CTestProDlg::OnBeginPrinting(WPARAM wParam,LPARAM lParam)
{
CDC* pDC = (CDC*)wParam;
CPrintInfo* pInfo = (CPrintInfo *)lParam;
if(m_fontPrinter.m_hObject==NULL)
m_fontPrinter.CreatePointFont(120,"FixedSys",pDC);
TEXTMETRIC tm;
CFont* pOldFont = pDC->SelectObject (&m_fontPrinter);
pDC->GetTextMetrics (&tm);
m_cyPrinter = tm.tmHeight + tm.tmExternalLeading;
CSize size = pDC->GetTextExtent (_T ("1----2-----3-----4"), 35);
pDC->SelectObject (pOldFont);
m_cxWidth = size.cx;
pInfo->SetMaxPage (1);//设置最大页码数
m_cxOffset = (pDC->GetDeviceCaps (HORZRES) - size.cx) / 1;
return TRUE;
}
LRESULT CTestProDlg::OnEndPrinting(WPARAM wParam,LPARAM lParam)
{
if(m_fontPrinter.m_hObject!=NULL)
m_fontPrinter.DeleteObject ();
return FALSE;
}
// PrintFrame.cpp : implementation file
//
#include "stdafx.h"
#include "TestPro.h"
#include "PrintFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// PrintFrame
IMPLEMENT_DYNCREATE(PrintFrame, CFrameWnd)
PrintFrame::PrintFrame()
{
m_pCallerDlg = NULL;
m_pWnd = AfxGetApp()->m_pMainWnd;
AfxGetApp()->m_pMainWnd = this;
}
PrintFrame::~PrintFrame()
{
}
BEGIN_MESSAGE_MAP(PrintFrame, CFrameWnd)
//{{AFX_MSG_MAP(PrintFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// PrintFrame message handlers
BOOL PrintFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
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;
}
void PrintFrame::OnDestroy()
{
if(m_pView!=NULL)
{
m_pView->DestroyWindow();
}
CFrameWnd::OnDestroy();
AfxGetApp()->m_pMainWnd = m_pWnd;
}
// PrintView.cpp : implementation file
//
#include "stdafx.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()
{
m_bPrint = 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::OnMyPrint()
{
GetParent()->ShowWindow(SW_SHOWMINIMIZED);
m_bPrint = TRUE;
CView::OnFilePrint();
}
void CPrintView::OnMyPrintPreview()
{
GetParent()->ShowWindow(SW_SHOWMAXIMIZED);
m_bPrint=FALSE;
CView::OnFilePrintPreview();
}
BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->m_bDirect = TRUE;//不弹出打印对话框
if(DoPreparePrinting(pInfo))
return TRUE;
else
{
GetParent()->DestroyWindow();
return FALSE;
}
}
void CPrintView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnBeginPrinting(pDC, pInfo);
PrintFrame *pFrame =(PrintFrame *)GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_BEGIN_PRINTING,(WPARAM) pDC, (LPARAM) pInfo);
}
void CPrintView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnEndPrinting(pDC, pInfo);
PrintFrame *pFrame =(PrintFrame *)GetParent();
pInfo->m_bDirect = TRUE;
pFrame->m_pCallerDlg->SendMessage(WM_END_PRINTING,(WPARAM) pDC, (LPARAM) pInfo);
if(m_bPrint) //直接打印,不是预览
//GetParent()->DestroyWindow();
pFrame->DestroyWindow();
pFrame->GetParent()->ShowWindow(SW_SHOW);
}
void CPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
PrintFrame *pFrame =(PrintFrame *)GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_MY_PRINT,(WPARAM) pDC, (LPARAM) pInfo) ;
}
void CPrintView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{
// TODO: Add your specialized code here and/or call the base class
CView::OnEndPrintPreview(pDC, pInfo, point, pView);
GetParent()->DestroyWindow();
}