Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / C++

A Copy Utility using TWAIN

Rate me:
Please Sign up or sign in to vote.
4.54/5 (10 votes)
14 Jul 20042 min read 99.8K   6.8K   47  
Example for a simple encapsulation of the TWAIN interface
///////////////////////////////////////////////////////////////////////////////
//
//		CTCopyApp
//		----------
//		Application of copy TWAIN utility
//
////Holger Kloos, 2004/////////////////////////////////////////////////////////


#include "stdafx.h"
#include "TCopy.h"
#include "TCopyDlg.h"


const char* STR_VALUE			= "Value";


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

/////////////////////////////////////////////////////////////////////////////
// CTCopyApp

BEGIN_MESSAGE_MAP(CTCopyApp, CWinApp)
	//{{AFX_MSG_MAP(CTCopyApp)
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTCopyApp construction

CTCopyApp::CTCopyApp()
		: m_bGerman(TRUE)
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTCopyApp object

CTCopyApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTCopyApp initialization

BOOL CTCopyApp::InitInstance()
{
	// Standard initialization

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	ReadIniFileValue("Deutsch", m_bGerman);

	CTCopyDlg dlg(m_bGerman ? IDD_TCOPY_DIALOG : IDD_TCOPY_DIALOG_E);
	m_pMainWnd = &dlg;
	dlg.DoModal();

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

const CString CTCopyApp::LoadString(UINT nId) const
{
	CString sRes;
	if (!m_bGerman)
		nId += 1000;
	sRes.LoadString(nId);

	return sRes;
}

const CString CTCopyApp::GetIniFileName() const
{
	CString sIniFile(m_pszHelpFilePath);
	sIniFile.Delete(sIniFile.GetLength() - 3, 3);
	sIniFile += "ini";

	return sIniFile;
}


void CTCopyApp::ReadIniFileValue(const char* pSection, int& nValue) const
{
	nValue = GetPrivateProfileInt(pSection, STR_VALUE, 0, GetIniFileName());
}

BOOL CTCopyApp::WriteIniFileValue(const char* pSection, int nValue) const
{
	CString sValue;
	sValue.Format("%d", nValue);
	return WritePrivateProfileString(pSection, STR_VALUE, sValue, GetIniFileName());
}

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
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions