win32打印图片


最近要做打印,所以需要打印的数据 都会绘制一在个缓冲图上 ,在网上找了此资料整理了一下. 随便求大神,
系统有没有这种API.调这个API直接能出现打印预览,我把这个缓冲图传给他,然后就由系统进行打印了?


DWORD dwNeeded, dwReturned;
	EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwNeeded, &dwReturned);
	PRINTER_INFO_5* prninfo = (PRINTER_INFO_5*)GlobalAlloc(GPTR, dwNeeded);

	if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (LPBYTE)prninfo, dwNeeded, &dwNeeded, &dwReturned)) 
	{
        创建打印DC
		m_PrinterDC = CreateDC(NULL,prninfo[0].pPrinterName, NULL, NULL) ;  
	}

bool IPrinter::PrinteImage(Gdiplus::Image* pImg)
{


	DOCINFO docInfo;

	docInfo.cbSize = sizeof(docInfo) ;

	docInfo.lpszDocName = (LPCWSTR)"NJ3a";

	docInfo.lpszOutput = NULL;

	docInfo.lpszDatatype = NULL;

	docInfo.fwType = 0;

	int result = StartDoc(m_PrinterDC, &docInfo) ;

	if (result <= 0)

	{

		MessageBox(0, L"StartDoc() failed" ,

			L"Basic Print App" , MB_OK | MB_ICONERROR) ;



	}  

	// 第3步:调用StartPage()

	result = StartPage(m_PrinterDC) ;

	if (result <= 0)

	{

		MessageBox(0, L"StartPage() failed" ,

			L"Basic Print App" , MB_OK  |  MB_ICONERROR) ;

		return false;

	}  

	// 第4步:打印数据

	//Rectangle(m_PrinterDC, 20, 20, 355, 417) ;

	//int w=pImg->GetWidth();
	//int h=pImg->GetHeight()-40;
	//HDC hdcsrc=CreateCompatibleDC(m_PrinterDC);
	//SelectObject(hdcsrc,pImg);
	//BitBlt(m_PrinterDC,0,0,w,h,hdcsrc,0,0,SRCCOPY);




	Gdiplus::Graphics g(m_PrinterDC);

	Gdiplus:: ImageAttributes imageAttr;


	imageAttr.SetWrapMode(Gdiplus::WrapModeTile);

	Gdiplus::RectF destDrawRect(0,0,pImg->GetWidth(),pImg->GetHeight()-40);
	Gdiplus::RectF srcRect(0,0,pImg->GetWidth(),pImg->GetHeight()-40);
	g.DrawImage(pImg,destDrawRect,srcRect.X,srcRect.Y,srcRect.Width,srcRect.Height,Gdiplus::UnitPixel,&imageAttr);

	// 第5步:调用EndPage()

	result = EndPage(m_PrinterDC) ;

	if (result <= 0)
	{

		MessageBox(0, L"EndPage() failed" ,

			L"Basic Print App" , MB_OK  |  MB_ICONERROR) ;
	}  

	// 第6步:调用EndDOC()

	EndDoc(m_PrinterDC) ;

	MessageBox(0, L"Document printed" , L"Basic Print App" ,

		MB_OK  |  MB_ICONINFORMATION) ;


	return true;
}
  

  

 

转载于:https://www.cnblogs.com/Hideaway/archive/2013/04/19/3030586.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值