Click here to Skip to main content
15,895,667 members
Articles / Desktop Programming / MFC

Scan2PDF

Rate me:
Please Sign up or sign in to vote.
4.90/5 (75 votes)
22 Apr 20053 min read 434.5K   20.9K   230  
A utility for bulk scanning, converting the scanned pages to PDF and burning them on CD/DVD for archiving.
// FinishPage.cpp : implementation file
//

#include "stdafx.h"
#include "Scan2PDF.h"
#include "FinishPage.h"

#include "Scan2PDFDefs.h"
#include "Scan2PDFDlg.h"

#include "FileOperations.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFinishPage property page

IMPLEMENT_DYNCREATE(CFinishPage, CPropertyPageEx)

CFinishPage::CFinishPage() : CPropertyPageEx(CFinishPage::IDD)
{
	//{{AFX_DATA_INIT(CFinishPage)
	m_DeleteFolder = FALSE;
	m_LaunchWizard = TRUE;
	//}}AFX_DATA_INIT

	m_psp.dwFlags |= PSP_HIDEHEADER;
}

CFinishPage::~CFinishPage()
{
}

void CFinishPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPageEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFinishPage)
	DDX_Control(pDX, IDC_FINISH, m_Finish);
	DDX_Check(pDX, IDC_DELETE_FOLDER_FILES, m_DeleteFolder);
	DDX_Check(pDX, IDC_LAUNCH_WIZARD, m_LaunchWizard);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFinishPage, CPropertyPageEx)
	//{{AFX_MSG_MAP(CFinishPage)
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFinishPage message handlers
BOOL CFinishPage::OnInitDialog() 
{
	CPropertyPageEx::OnInitDialog();
	
	m_Finish.SetFontStatic(CString("Times New Roman"), 25, RGB(0, 0, 0), FS_BOLD);
	m_Finish.SetBackground(RGB(255, 255, 255));
	m_Finish.SetWindowText("Scan2PDF wizard finished!");
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CFinishPage::OnSetActive() 
{
	CPropertySheetEx* pParent=(CPropertySheetEx*) GetParent();
	pParent->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
	
	return CPropertyPageEx::OnSetActive();
}

BOOL CFinishPage::OnWizardFinish() 
{
	UpdateData(TRUE);

	char lpFilename[_MAX_PATH];
	ZeroMemory(lpFilename, _MAX_PATH);
	GetModuleFileName(AfxGetInstanceHandle(), lpFilename, _MAX_PATH);

	if (m_DeleteFolder)
	{
		CString szPath;
		CString szApp;
		szApp=AfxGetApp()->m_pszExeName;
		szApp+=CString(".exe");

		szPath=lpFilename;
		szPath.Replace(szApp, "");

		szPath+=theConf.m_ProjectName;
		//szPath+=CString("\\*.*");

		//delete the folder of all the contents
		/*SHFILEOPSTRUCT op;
		op.hwnd=m_hWnd;
		op.lpszProgressTitle=NULL;
		char TempPath[4096];
		strcpy(TempPath, szPath.GetBuffer(0));
		op.pFrom=TempPath;
		op.pTo=NULL;
		op.wFunc=FO_DELETE;
		op.fFlags=FOF_SILENT;
		op.hNameMappings=NULL;
		
		SHFileOperation(&op);*/
		CFileOperation fo;
		
		if (!fo.Delete(szPath)) // do Copy
		{
			//fo.ShowError(); // if copy fails show error message
		}
		
		szPath=lpFilename;
		szPath.Replace(szApp, "");
		SetCurrentDirectory(szPath);
		szPath+=theConf.m_ProjectName;

		if (!RemoveDirectory(szPath))
		{
			LPVOID lpMsgBuf;
			if (!FormatMessage( 
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM | 
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
				(LPTSTR) &lpMsgBuf,
				0,
				NULL ))
			{
				// Handle the error.
				
			}
			
			// Process any inserts in lpMsgBuf.
			// ...
			
			// Display the string.
			//AfxMessageBox((LPCTSTR) lpMsgBuf,MB_OK | MB_ICONERROR);
			
			// Free the buffer.
			LocalFree(lpMsgBuf);
		}

		//delete the project file name if exist
		CString szProjFileName;
		szProjFileName.Format("%s.prj", theConf.m_ProjectName.GetBuffer(0));

		DeleteFile(szProjFileName);
		
	}	//Delete Folder
	else
	{
		//save the project for future use
		CString szProjFileName;
		szProjFileName.Format("%s.prj", theConf.m_ProjectName.GetBuffer(0));

		FILE* fp=fopen(szProjFileName.GetBuffer(0), "wt");
		if (fp!=NULL)
		{
			fprintf(fp, "%d\n", theConf.m_ProjectSize);					//Project Size
			int index=theConf.m_PDFs.size();
			for (int i=0; i<index; i++)
				fprintf(fp, "%s\n", theConf.m_PDFs[i].GetBuffer(0));
			
			fclose(fp);
		}
	}

	if (m_LaunchWizard)
	{
		//launch new Scan2PDF.exe 
		ShellExecute(NULL, "open", lpFilename/*"Scan2PDF.exe"*/, NULL, NULL, SW_SHOW);
	}
	
	return CPropertyPageEx::OnWizardFinish();
}

void CFinishPage::OnAbout() 
{
	CScan2PDFDlg dlg;
	dlg.DoModal();	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Solaris Electronics LLC
United Arab Emirates United Arab Emirates
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acquisition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competition, my articles are:


You can see list of my articles, by clicking here


Comments and Discussions