Solved

How do I remove special characters / hyroglyphs from print output (MFC Dialog print)?

Posted on 2010-08-26
1
504 Views
Last Modified: 2013-11-20
I'm new to MFC programming and have been working on a Database application.  I'm more experienced in COBOL and VBA so alot of this is new to me.
I have attached an example of my print layout and the coding to produce it, any help / guidance would be greatly appreciated.
Thanks.
void CDB3tutorialView::OnDraw(CDC* pDC)
{
	// TODO: Add your specialized code here and/or call the base class
	CDB3tutorialDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CString strTmp;
	CDatabase database;
	CString SqlString;
	int ysize = 400;
	CString	sFirstName = _T("");
	CString	sLastName = _T("");
	CString	sAge = _T("");
	CString	sProject = _T("");
	CString	sCompleted = _T("");
	CString sDriver = _T("MICROSOFT ACCESS DRIVER (*.mdb)");
	CString sDsn;
	CString sFile = _T("c:\\Users\\A Telfer\\Desktop\\TestDB.mdb");

	CRect rect (100, 100, 10000, 10000);
	if(pDC->IsPrinting())
		pDC->TextOutW( 200, 200, _T("First"));
		pDC->TextOutW( 200, 300, _T("-------"));
		pDC->TextOutW( 800, 200, _T("Last"));
		pDC->TextOutW( 800, 300, _T("-------"));
		pDC->TextOutW( 1300, 200, _T("Age"));
		pDC->TextOutW( 1300, 300, _T("---"));
		pDC->TextOutW( 1700, 200, _T("Project"));
		pDC->TextOutW( 1700, 300, _T("-------"));
		pDC->TextOutW( 2200, 200, _T("Completed?"));
		pDC->TextOutW( 2200, 300, _T("----------"));
		
		sDsn.Format( _T("ODBC;DRIVER={%s};DSN='';DBQ=%s"),sDriver,sFile);	
		database.Open(NULL,false,false,sDsn);

		// Allocate the recordset
		CRecordset recset( &database );

		// Build the SQL statement
		SqlString =  _T("SELECT FirstName, LastName, Age, Project, Completed ")
				_T("FROM Project");

		// Execute the query
		recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);

		// Loop through each record
		while( !recset.IsEOF() )
		{
			// Copy each column into a variable
			recset.GetFieldValue(_T("FirstName"),sFirstName);
			recset.GetFieldValue(_T("LastName"),sLastName);
			recset.GetFieldValue(_T("Age"),sAge);
			recset.GetFieldValue(_T("Project"),sProject);
			recset.GetFieldValue(_T("Completed"),sCompleted);
			pDC->TextOutW( 200, ysize, sFirstName);
			pDC->TextOutW( 800, ysize, sLastName);
			pDC->TextOutW( 1300, ysize, sAge);
			pDC->TextOutW(1800, ysize, sProject);
			pDC->TextOutW(2350, ysize, sCompleted);

			// goto next record
			recset.MoveNext();
			sFirstName = _T("");
			sLastName = _T("");
			sAge = _T("");
			sProject = _T("");
			sCompleted = _T("");
			ysize = ysize+100;
		}
}

Open in new window

Database-print.JPG
0
Comment
Question by:atonline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
atonline earned 0 total points
ID: 33529790
I have actually found out a solution to my problem.
It appears changing the Project "Character Set" to 'Multi-Byte' instead of 'Unicode' and a bit of code tweeking has resolved my problem.  (Example attached)

Any comments on alternatives will be appreciated.
Database-print-ok.JPG
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 130
Thin secure Windows 10 5 107
Problem with SqlConnection 4 184
How to convert Structure to vector of byte and vice versa 5 31
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question