#include "stdafx.h"
#include "Print01.h"
#include "Print01Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CPrint01Dlg::CPrint01Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CPrint01Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPrint01Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPrint01Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_PRINT, &CPrint01Dlg::OnBnClickedBtnPrint)
END_MESSAGE_MAP()
// CPrint01Dlg 消息处理程序
BOOL CPrint01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CPrint01Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CPrint01Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CPrint01Dlg::Print()
{
// Display the Windows Print dialog box with "All" radio button
// initially selected. All other radio buttons are disabled.
CPrintDialog printDlg(FALSE);
if (IDCANCEL == printDlg.DoModal())
return;
// 利用CPrintDialog生成打印机设备环境
CDC dc;
dc.Attach(printDlg.GetPrinterDC());
dc.m_bPrinting = TRUE;
DOCINFO di;
::ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = _T("sample");
// Start a print job.
bool bPrintingOK = dc.StartDoc(&di);
CPrintInfo info;
// Set the number of the last page of the document.
info.SetMaxPage(1);
// Specifies the usable drawing area of the page in logical coordinates.
info.m_rectDraw.SetRect(0, 0, dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
OnPrint(&dc, &info);
if (bPrintingOK)
dc.EndDoc(); // End a print job
else
dc.AbortDoc(); // Abort job.
dc.Detach(); // Detach the printer DC
}
void CPrint01Dlg::OnPrint(CDC *pdc, CPrintInfo *pInfo)
{
// Load a bitmap.
HANDLE file = ::LoadImage(NULL, _T("D:\\sample.bmp"), IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
if (NULL == file)
return;
CBitmap bmp;
// Attach a bitmap handle to a CBitmap object.
if (!bmp.Attach(file))
return;
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC memDC;
memDC.CreateCompatibleDC(pdc);
HBITMAP hOldBmp = (HBITMAP)memDC.SelectObject(&bmp);
CRect destRect = pInfo->m_rectDraw;
pdc->StretchBlt(destRect.left, destRect.top, destRect.Width(), destRect.Height(),
&memDC, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, SRCCOPY);
memDC.SelectObject(hOldBmp);
memDC.DeleteDC();
bmp.Detach();
}
void CPrint01Dlg::OnBnClickedBtnPrint()
{
Print();
}
Visual C++打印机编程入门
4星 · 超过85%的资源 需积分: 15 67 浏览量
2013-12-28
22:54:48
上传
评论 1
收藏 296KB RAR 举报
zhuyf87
- 粉丝: 101
- 资源: 8
最新资源
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
- for daily read
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页