Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Below is a MFC code which is used for printing

C#
void CMFCSample1Dlg::OnBnClickedWrite()
{
	UpdateData(TRUE);

	if (m_vckWriteFile) {
		CString name;
		m_cbWriteFile.GetWindowText(name);
		CFile file;
		if (file.Open(name, CFile::modeRead) == FALSE) {
			return;
		}
		TCHAR Buff[4096];
		DWORD dwLen;
		dwLen = (DWORD)file.GetLength();
		if (4096 < dwLen) {
			file.Close();
			return;
		}
		file.Read(Buff, dwLen);
		file.Close();

		DWORD r = PrtWrite(Buff, dwLen);

		TCHAR buf[64];
		GetErrorMessage(r, buf, 64);
		CString mes;
		mes.Format("PrtWrite(<%s>, %d): %d\n<%s>", name, dwLen, r, buf);
		MessageBox(mes);
	} else {
		TCHAR Buff[256];
		DWORD dwLen = m_vedWrite.GetLength();
		if (254 < dwLen) {
			return;
		}
		_tcscpy(Buff, m_vedWrite);
		Buff[dwLen] = 0x0D;
		dwLen++;
		Buff[dwLen] = 0;

		DWORD r = PrtWrite(Buff, dwLen);

		TCHAR buf[64];
		GetErrorMessage(r, buf, 64);
		CString mes;
		mes.Format("PBWrite(%s, %d): %d\n<%s>", m_vedWrite, dwLen, r, buf);
		MessageBox(mes);
	}
}


I am not able to do this in c#.
can anyone help me on this please.
I need to print one notepad file using this.
Posted
Comments
[no name] 9-Jul-14 5:52am    
Do you want to print using C# or mfc?

Here is one article
Printing with MFC Made Easy[^]

And here is another
http://www.ucancode.net/faq/MFC%20Tutorial-MFC_Print.htm[^]

It is not easy to explain the code in a forum likes this.
 
Share this answer
 
I should take no note of that code, it looks far too complex for simply reading and printing a file. There are lots of samples around which show how to read a text file, and how to print lines of text.
 
Share this answer
 
Comments
[no name] 9-Jul-14 5:35am    
Please provide some links for that.

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