Click here to Skip to main content
15,900,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDLL Question Pin
Shay Harel9-Feb-06 10:04
Shay Harel9-Feb-06 10:04 
AnswerRe: DLL Question Pin
Rick York9-Feb-06 10:24
mveRick York9-Feb-06 10:24 
GeneralRe: DLL Question Pin
Shay Harel9-Feb-06 13:33
Shay Harel9-Feb-06 13:33 
AnswerRe: DLL Question Pin
sunit59-Feb-06 17:11
sunit59-Feb-06 17:11 
AnswerRe: DLL Question Pin
Ryan Binns9-Feb-06 17:39
Ryan Binns9-Feb-06 17:39 
QuestionPrinting Pin
#realJSOP9-Feb-06 9:11
professional#realJSOP9-Feb-06 9:11 
AnswerRe: Printing Pin
David Crow9-Feb-06 9:14
David Crow9-Feb-06 9:14 
GeneralRe: Printing Pin
#realJSOP9-Feb-06 9:31
professional#realJSOP9-Feb-06 9:31 
Nope.

here's my code:

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
LRESULT CPatientInfoView::OnCBPrint(WPARAM wParam, LPARAM lParam)
{
	CPrintDialog dlg(FALSE);
	if (dlg.DoModal() != IDOK)
	{
		return 1L;
	}
	HDC hDC = dlg.GetPrinterDC();
	if (hDC == NULL)
	{
		// no printer selected
		return 1L;
	}

	CDC printerDC;
	printerDC.Attach(hDC);

	DOCINFO docinfo;
	memset(&docinfo, 0, sizeof(docinfo));
	docinfo.cbSize = sizeof(docinfo);
	docinfo.lpszDocName = _T("TRIAD Patient Info Report");

	if (printerDC.StartDoc(&docinfo) < 0)
	{
		AfxMessageBox(_T("Printer wouldn't initalize"));
	}
	else
	{
		CalcPrintedPageHeight(&printerDC);
		int nLinesPrinted = 0;
		do 
		{
			nLinesPrinted = PrintPage(&printerDC, nLinesPrinted);
		} while (nLinesPrinted > 0);

		printerDC.EndDoc();
	}
	return 1L;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL CPatientInfoView::BuildReportFont(CFont* pFont)
{
    int nFontSize = -12;
    CString sFontName = _T("Courier");
	return pFont->CreateFont(nFontSize, 0,0,0, FW_NORMAL, 0,0,0, DEFAULT_CHARSET,
                             OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
                             DEFAULT_PITCH | FF_DONTCARE, sFontName);
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int CPatientInfoView::PrintPage(CDC* pDC, int nStartLine)
{
	if (pDC->StartPage() < 0)
	{
		MessageBox(_T("Could not start page"));
		return pDC->AbortDoc();
	}

	int nCount = m_saLines.GetSize();
	if (nCount <= 0)
	{
		return -10;
	}

	if (nStartLine >= nCount)
	{
		return -11;
	}

	TRACE("DrawOnDevice()\n");
	m_nDocHeight = 0;
	CRect screenRect;

	CFont* pOldFont = NULL;
	CFont docFont;
	BuildReportFont(&docFont);
	pDC->SelectObject(&docFont);

	CString sText   = "";
	CString sTemp   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	int nLineHeight = pDC->GetTextExtent(sTemp).cy + 2;
	int nTabWidth   = 25;
	int nYPos       = 5;
	int nXPos       = 5;

	pDC->SetBkColor(RGB(255,255,255));
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextColor(RGB(0,0,0));

	// we don't care about pages on the screen, so we just print the lines in 
	// the array as they are.
	int i = 0;
	for (i = nStartLine; i < nCount; i++)
	{
		nYPos += (DrawLine(pDC, nXPos, nYPos, m_saLines.GetAt(i)) * nLineHeight);
		if (nYPos > m_nPageHeight - nLineHeight)
		{
			break;
		}
	}
	pDC->SelectObject(pOldFont);
	pDC->EndPage();

	if (i >= nCount -1)
	{
		return -12;
	}
	return i;
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CPatientInfoView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	TRACE("OnPrepareDC()\n");
	if (!pDC->IsPrinting())
	{
		SetScrollSizes(MM_TEXT, CSize(1000, m_nDocHeight));
		CScrollView::OnPrepareDC(pDC, pInfo);
	}
	else
	{
		CScrollView::OnPrepareDC(pDC, pInfo);
	}
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CPatientInfoView::CalcPrintedPageHeight(CDC* pDC)
{
	CDC *pCurrentDC = GetDC();        // will have dimensions of the client area
	if (!pCurrentDC) 
	{
		return;
	}

	pDC->SetMapMode(MM_TEXT);

	CSize szPaperPPI (pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
	CSize szScreenPPI(pCurrentDC->GetDeviceCaps(LOGPIXELSX), pCurrentDC->GetDeviceCaps(LOGPIXELSY));

	int nLeftMargin   = 0;
	int nRightMargin  = 0;
	int nHeaderHeight = 0;
	int nFooterHeight = 0;
	int nGap          = 0;

	// Create the printer font
	CFont prnFont;
	BuildReportFont(&prnFont);
	CFont *pOldFont = pDC->SelectObject(&prnFont);

	// Get the average character width (in GridCtrl units) and hence the margins
	CSize charSize = pDC->GetTextExtent(_T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSATUVWXYZ"),52);
	charSize.cx   /= 52;
	int nMargins   = (nLeftMargin + nRightMargin) * charSize.cx;

	// Get the page sizes (physical and logical)
	CSize szPaperSize = CSize(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));

	CSize szLogicalPageSize = CSize(szScreenPPI.cx * szPaperSize.cx / szPaperPPI.cx * 3 / 4,
	                                szScreenPPI.cy * szPaperSize.cy / szPaperPPI.cy * 3 / 4);

	m_nPageHeight = szLogicalPageSize.cy - 
	                (nHeaderHeight + nFooterHeight + 2 * nGap) * 
	                charSize.cy;
	m_nPageWidth  = szLogicalPageSize.cx -
	                (nLeftMargin + nRightMargin + 2 * nGap);

	
    pDC->SetWindowExt  (szLogicalPageSize);
    pDC->SetViewportExt(szPaperSize);
    pDC->SetWindowOrg  (nLeftMargin * charSize.cx, 0);

	pDC->SelectObject(pOldFont);
}


------- sig starts

"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt

"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
AnswerRe: Printing Pin
Shog99-Feb-06 11:45
sitebuilderShog99-Feb-06 11:45 
AnswerRe: Printing Pin
Michael Dunn9-Feb-06 10:14
sitebuilderMichael Dunn9-Feb-06 10:14 
GeneralRe: Printing Pin
#realJSOP10-Feb-06 5:26
professional#realJSOP10-Feb-06 5:26 
GeneralRe: Printing Pin
#realJSOP10-Feb-06 10:13
professional#realJSOP10-Feb-06 10:13 
AnswerRe: Printing Pin
Stan Shannon9-Feb-06 13:54
Stan Shannon9-Feb-06 13:54 
QuestionHow to disable all controls in the dialog box Pin
Eugene Pustovoyt9-Feb-06 8:39
Eugene Pustovoyt9-Feb-06 8:39 
AnswerRe: How to disable all controls in the dialog box Pin
Andy Moore9-Feb-06 9:14
Andy Moore9-Feb-06 9:14 
QuestionRe: How to disable all controls in the dialog box Pin
David Crow9-Feb-06 9:15
David Crow9-Feb-06 9:15 
AnswerRe: How to disable all controls in the dialog box Pin
#realJSOP9-Feb-06 10:09
professional#realJSOP9-Feb-06 10:09 
AnswerRe: How to disable all controls in the dialog box Pin
jhwurmbach10-Feb-06 3:27
jhwurmbach10-Feb-06 3:27 
QuestionMultithreaded Programming Pin
RanjanShrestha9-Feb-06 8:07
RanjanShrestha9-Feb-06 8:07 
AnswerRe: Multithreaded Programming Pin
Rage9-Feb-06 8:13
professionalRage9-Feb-06 8:13 
GeneralRe: Multithreaded Programming Pin
RanjanShrestha9-Feb-06 8:17
RanjanShrestha9-Feb-06 8:17 
GeneralRe: Multithreaded Programming Pin
Rage9-Feb-06 8:31
professionalRage9-Feb-06 8:31 
Questiona little output problem Pin
Peter Charlesworth9-Feb-06 7:46
Peter Charlesworth9-Feb-06 7:46 
AnswerRe: a little output problem Pin
Rage9-Feb-06 8:15
professionalRage9-Feb-06 8:15 
QuestionGetting CXX0030: Error: expression cannot be evaluated Pin
zahid_ash9-Feb-06 7:34
zahid_ash9-Feb-06 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.