Click here to Skip to main content
15,894,907 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Hello world... please help Pin
Nelek13-May-07 20:46
protectorNelek13-May-07 20:46 
GeneralRe: Hello world... please help Pin
David Crow14-May-07 3:27
David Crow14-May-07 3:27 
QuestionHello world... help Pin
WakenDJ13-May-07 17:23
WakenDJ13-May-07 17:23 
AnswerRe: Hello world... help Pin
amets13-May-07 22:53
amets13-May-07 22:53 
QuestionThreadpool Linker Problem Pin
Cyrilix13-May-07 12:35
Cyrilix13-May-07 12:35 
AnswerRe: Threadpool Linker Problem Pin
led mike13-May-07 15:44
led mike13-May-07 15:44 
GeneralRe: Threadpool Linker Problem Pin
Cyrilix13-May-07 16:59
Cyrilix13-May-07 16:59 
QuestionProblem with print function ? Pin
Lewis0113-May-07 10:31
Lewis0113-May-07 10:31 
Hello,

Here is the function:

void CAssignment04View::OnPrint(CDC* pDC, CPrintInfo* pInfo)<br />
{<br />
int iRowCount = 1; // Current print row count.<br />
	CString cNumeric; // Text form of numeric data.<br />
	CPen oPen; // Pen for drawing.<br />
	CBrush oBrush; // Brush for shading.<br />
	CFont oTextFont; // Text Font.<br />
	CFont oHeadFont; // Heading Font.<br />
	CFont oColFont; // Column Heading Font.<br />
	LOGFONT lfFont; // Font characteristic structure.<br />
	CSize oFontSize; // Size of a font.<br />
	COLORREF clrRef; // Color structure.<br />
	int iRowPos = 120; // Row position on printed page.<br />
	int iTextHeight = 0; // Current text height.<br />
	CRect oDrawRect; // Drawing area for printer.<br />
	int iRecNumPos; // Record number position.<br />
	COleCurrency Salary;<br />
<br />
	// Database records.<br />
	int iEmployeeNumPos; <br />
	int iFirstNamePos; <br />
	int iLastNamePos;<br />
	int iAgePos;<br />
	int iDepartmentPos;<br />
	int iSalaryPos;<br />
<br />
	BOOL EndOfRowset = false; // End of the rowset?<br />
	HRESULT hr; // Operation Result<br />
<br />
<br />
	// Get the drawing area for our print routine.<br />
	oDrawRect = pInfo->m_rectDraw;<br />
	// Create a pen and select it into our device context.<br />
	clrRef = 0x00000000;<br />
<br />
	oPen.CreatePen(PS_SOLID, 2, clrRef);<br />
	pDC->SelectObject(&oPen);<br />
	// Create a brush and select it into our device context.<br />
	clrRef = 0x00C0C0C0;<br />
	oBrush.CreateSolidBrush(clrRef);<br />
	pDC->SelectObject(&oBrush);<br />
	// Create a heading font and select it into our device context.<br />
	oHeadFont.CreatePointFont(240, "Arial", pDC);<br />
	pDC->SelectObject(&oHeadFont);<br />
	// Display our heading.<br />
	oFontSize = pDC->GetOutputTextExtent("HR DataBase");<br />
	pDC->Ellipse(500,<br />
	iRowPos - (oFontSize.cy / 2) - 10,<br />
	oDrawRect.Width() - 500,<br />
	iRowPos + (oFontSize.cy / 2) + 10);<br />
	pDC->SetBkMode(TRANSPARENT);<br />
	pDC->TextOut((oDrawRect.Width() - oFontSize.cx) / 2,<br />
	iRowPos - (oFontSize.cy / 2) - 10,<br />
	"HR DataBase");<br />
	pDC->SetBkMode(OPAQUE);<br />
	// Create the appropriate space.<br />
	oHeadFont.GetLogFont(&lfFont);<br />
	iRowPos = abs(lfFont.lfHeight) + 175;<br />
	// Create a text font.<br />
	oTextFont.CreatePointFont(120, "Arial", pDC);<br />
	// Get the current text font height.<br />
	oTextFont.GetLogFont(&lfFont);<br />
	iTextHeight = abs(lfFont.lfHeight) + 10;<br />
	// Create a font for displaying column headings.<br />
	lfFont.lfWeight = 700; // Make it bold, normal is 400.<br />
	oColFont.CreateFontIndirect(&lfFont);<br />
	pDC->SelectObject(&oColFont);<br />
<br />
	// Compute the column spacings. Set the first column to 1/2 inch.<br />
	iRecNumPos = int(oDrawRect.Width() / 17);<br />
	iFirstNamePos = iRecNumPos + 50 + pDC->GetOutputTextExtent("##").cx;<br />
	iLastNamePos = iFirstNamePos + 50 + pDC->GetOutputTextExtent("###########").cx;<br />
	iAgePos = iLastNamePos + 100 + pDC->GetOutputTextExtent("###########").cx;<br />
	iDepartmentPos = iAgePos + 150 + pDC->GetOutputTextExtent("##").cx;<br />
	iSalaryPos = iDepartmentPos + 150 + pDC->GetOutputTextExtent("##########################").cx;<br />
	<br />
	<br />
	// Display the column headings.<br />
	pDC->TextOut(iRecNumPos, iRowPos, "#");<br />
	pDC->TextOut(iFirstNamePos, iRowPos, "First Name");<br />
	pDC->TextOut(iLastNamePos, iRowPos, "Last Name");<br />
	pDC->TextOut(iAgePos, iRowPos, "Age");<br />
	pDC->TextOut(iDepartmentPos, iRowPos, "Department");<br />
	pDC->TextOut(iSalaryPos, iRowPos, "Salary");<br />
<br />
	// Create a space between the column heading and the text.<br />
	iRowPos += iTextHeight;<br />
	pDC->MoveTo(iRecNumPos, iRowPos);<br />
	pDC->LineTo(oDrawRect.Width() - iRecNumPos, iRowPos);<br />
	iRowPos += 30;<br />
	// Select our text font into the device context.<br />
	pDC->SelectObject(&oTextFont);<br />
	// Determine the row height.<br />
	iTextHeight = 20 + pDC->GetOutputTextExtent("Xy").cy;<br />
	// Move to the first row.<br />
	m_pSet->MoveFirst();<br />
	// Print the records in a loop.<br />
	while (!EndOfRowset)<br />
<br />
	{<br />
		// Display the current record number.<br />
		itoa(iRowCount, cNumeric.GetBuffer(10), 10);<br />
		cNumeric.ReleaseBuffer(-1);<br />
		pDC->TextOut(iRecNumPos, iRowPos, cNumeric);<br />
		pDC->TextOut(iFirstNamePos, iRowPos, CString(m_pSet->m_Employee_Name_First));<br />
		pDC->TextOut(iLastNamePos, iRowPos, CString(m_pSet->m_Employee_Name_Last));<br />
		//pDC->TextOut(iAgePos, iRowPos, m_pSet->m_Employee_Age);<br />
<br />
		itoa(m_pSet->m_Employee_Age, cNumeric.GetBuffer(10), 10);<br />
		cNumeric.ReleaseBuffer(-1);<br />
		pDC->TextOut(iAgePos, iRowPos, cNumeric);<br />
<br />
		pDC->TextOut(iDepartmentPos, iRowPos, CString(m_pSet->m_Department));<br />
		//pDC->TextOut(iSalaryPos, iRowPos, m_pSet->m_Employee_Salary);<br />
<br />
		//Salary = COleCurrency(m_pSet->m_Employee_Salary);<br />
		//pDC->TextOut(iSalaryPos,iRowPos, "£" + Salary.Format(0, LANG_USER_DEFAULT));<br />
<br />
		// Advance the row.<br />
		iRowPos += iTextHeight;<br />
		iRowCount ++;<br />
<br />
    // See if this is the last row.<br />
            //if (hr == DB_S_ENDOFROWSET)<br />
		m_pSet->MoveNext();<br />
            if (m_pSet->IsEOF())<br />
            {<br />
				<br />
            // If so, end the printing loop.<br />
            EndOfRowset = true;<br />
            break;<br />
            }<br />
	<br />
		<br />
	}<br />
<br />
	CRecordView::OnPrint(pDC, pInfo);<br />
}


Now the problem:

When you start the application you can navigate the records fine. You can then click print preview and it displays what you might expect. Now if you close the print preview window the recordset has navigated to the end. When you try to click either the << or < button it displays the following error message:

operation failed, no current record

Any suggestions what might be wrong. If you don't click the print preview button then you can navigate the records without problem.

Many Thanks.
AnswerRe: Problem with print function ? Pin
bob1697213-May-07 10:57
bob1697213-May-07 10:57 
GeneralRe: Problem with print function ? Pin
Lewis0113-May-07 11:05
Lewis0113-May-07 11:05 
GeneralRe: Problem with print function ? Pin
bob1697213-May-07 11:27
bob1697213-May-07 11:27 
GeneralRe: Problem with print function ? Pin
David Crow14-May-07 3:34
David Crow14-May-07 3:34 
QuestionTrying to use m_strSort with OLE DB Pin
Lewis0113-May-07 10:27
Lewis0113-May-07 10:27 
QuestionMemory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 8:04
dum13-May-07 8:04 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
bob1697213-May-07 9:30
bob1697213-May-07 9:30 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 11:16
dum13-May-07 11:16 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
bob1697213-May-07 12:06
bob1697213-May-07 12:06 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 12:11
dum13-May-07 12:11 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 12:13
dum13-May-07 12:13 
AnswerRe: Memory leak found after reporting "No memory leaks detected" Pin
cmk13-May-07 14:55
cmk13-May-07 14:55 
QuestionRe: Memory leak found after reporting "No memory leaks detected" Pin
dum13-May-07 15:15
dum13-May-07 15:15 
AnswerRe: Memory leak found after reporting &quot;No memory leaks detected&quot; Pin
Mark Salsbery14-May-07 5:09
Mark Salsbery14-May-07 5:09 
GeneralRe: Memory leak found after reporting &quot;No memory leaks detected&quot; Pin
dum18-May-07 9:27
dum18-May-07 9:27 
QuestionPlatform SDK Pin
<color>Aljechin 13-May-07 6:48
<color>Aljechin 13-May-07 6:48 
AnswerRe: Platform SDK Pin
Sam_c13-May-07 6:57
Sam_c13-May-07 6:57 

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.