Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to build bill printing app in C++/MFC , I need to know to handle printing job in click of button

What I have tried:

C++
// l've done this code in Onprint;

void CGCAppView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add customized printing code here
	ASSERT(pDC);
	ASSERT(pInfo);
	// do some default output onto the page
	CString	text;
	CSize	csText;
	CFont* pOldFont;
	CFont	myFont;

	int fontSize = -MulDiv(18, pDC->GetDeviceCaps(LOGPIXELSY), 72);
	VERIFY(myFont.CreateFont(fontSize * 2, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,	DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,FF_ROMAN,L"Arial"));
	pOldFont = pDC->SelectObject(&myFont);
	pDC->Rectangle(pInfo->m_rectDraw);
	pDC->Ellipse(pInfo->m_rectDraw);
	text.Format(L"PAGE %1d of %1d", pInfo->m_nCurPage, pInfo->GetMaxPage());
	csText = pDC->GetTextExtent(text);
	pDC->TextOut(pInfo->m_rectDraw.left + (pInfo->m_rectDraw.Width() - csText.cx) / 2,
		pInfo->m_rectDraw.top + (pInfo->m_rectDraw.Height() - csText.cy) / 2, text);
	pDC->SelectObject(pOldFont);
	VERIFY(myFont.DeleteObject());
	pDC->TextOutW(400, 200, L"Hello Mfc");
	CString alfa;
	alfa = L"this is a test string";
	pDC->TextOutW(400, 300, alfa);
	//pDC->DrawText();
}
Posted
Updated 18-Apr-21 7:45am
v2

1 solution

Searching can find lots of sample code to look at. This site has some too. Here's one : Printing with MFC Made Easy[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900