⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prt_demodlg.cpp

📁 通用报表打印类使用说明 主要功能: 1 – 自动分页 2 – 自动划出纵横表格线 3 – 支持横向 / 纵向打印 4 – 支持打印输出或生成文本文件 使用方法: 1.Copy prt.h
💻 CPP
字号:
// Prt_DemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Prt_Demo.h"
#include "Prt_DemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPrt_DemoDlg dialog

CPrt_DemoDlg::CPrt_DemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPrt_DemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPrt_DemoDlg)
		// 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 CPrt_DemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPrt_DemoDlg)
	DDX_Control(pDX, IDC_LIST, m_List);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPrt_DemoDlg, CDialog)
	//{{AFX_MSG_MAP(CPrt_DemoDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_PRT, OnPrt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrt_DemoDlg message handlers

BOOL CPrt_DemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	//-----------------------------------------------------------
	// Set Header
	m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EDITLABELS);
	m_List.InsertColumn(0,"",LVCFMT_CENTER,0);
	m_List.InsertColumn(1,"No.",LVCFMT_CENTER,40);
	m_List.InsertColumn(2,"  Name",LVCFMT_LEFT,80);
	m_List.InsertColumn(3," Telephone",LVCFMT_LEFT,120);
	m_List.InsertColumn(4,"     Address",LVCFMT_LEFT,220);

	// Add Line 1
	m_List.InsertItem(0,"");
	m_List.SetItemText(0,1,"1");
	m_List.SetItemText(0,2,"张三");
	m_List.SetItemText(0,3,"65666768");
	m_List.SetItemText(0,4,"四平路500号");

	// Add Line 2
	m_List.InsertItem(1,"");
	m_List.SetItemText(1,1,"2");
	m_List.SetItemText(1,2,"李四");
	m_List.SetItemText(1,3,"13012345678");
	m_List.SetItemText(1,4,"北京路812号-405");
	
	// Add Line 3
	m_List.InsertItem(2,"");
	m_List.SetItemText(2,1,"3");
	m_List.SetItemText(2,2,"王五");
	m_List.SetItemText(2,3,"13809090900");
	m_List.SetItemText(2,4,"中山路1253弄18号");

	prt_cnt=3;
	//-----------------------------------------------------------

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CPrt_DemoDlg::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 CPrt_DemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPrt_DemoDlg::OnPrt() 
{
	// TODO: Add your control notification handler code here
	CPrt dlg;
	dlg.LandScape=0;			// 1=横向打印, 0=纵向打印
	dlg.pRow->title=" 通讯录";	// Print Name
	dlg.pRow->row_sum=3;		// Totol lines
	dlg.SetGetRowCallback((int (CWnd::*)(PRTROW *))GetRow);
	dlg.DoModal();
}


int CPrt_DemoDlg::GetRow(PRTROW *pRow)
{
	int n;
	CString str,ss;
	switch(pRow->op_code){
	case PRTROW::stGetHeader:	// Set Title
		pRow->head="通讯录";	// Main Title
		//pRow->head_l=sub title (if necessary), left margin
		//pRow->head_m=sub title (if necessary), middle
		//pRow->head_r=sub title (if necessary), right margin
		pRow->col_count=4;
		pRow->hx[0]=" No. ";	// Set Header Text & Column Width
		pRow->hx[1]="   Name   ";
		pRow->hx[2]="  Telephone  ";
		pRow->hx[3]="             Address             ";
		return 1;
	case PRTROW::stGetRow:		// Set Content
		n=(pRow->page-1)*pRow->row_count+pRow->row;
		if(n>=prt_cnt) return 0;
		pRow->tx[0]=m_List.GetItemText(n,1);
		pRow->tx[1]=m_List.GetItemText(n,2);
		pRow->tx[2]=m_List.GetItemText(n,3);
		pRow->tx[3]=m_List.GetItemText(n,4);
		return 1;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -