⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 burncdpage.cpp

📁 把doc文档转成pdf后刻录成CD,用VC++开发,用了Nero的SDK和CXIMAGE的D
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// BurnCDPage.cpp : implementation file
//

#include "stdafx.h"
#include "Scan2PDF.h"
#include "BurnCDPage.h"

#include "BurnCD/getopt.h"
#include "BurnCD/BurnContext.h"

#include "Scan2PDFDefs.h"

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


#pragma comment(lib, "BurnCD/NeroAPIGlue.lib")
UINT BurnCD(LPVOID pParam);
UINT CheckCD(LPVOID pParam);

UINT DoNeroTask(int argc, char** ppargv);
BOOL WarnForFileOnCD(CString DriveLetter);


#define IMAGE_RECORDER		"Image Recorder"

typedef struct tagBurnThread
{
	char DriveName[256];
	BOOL Simulation;
} BurnThread;

char szDriveName[256]="";
BOOL gSimulation=FALSE;

/////////////////////////////////////////////////////////////////////////////
// CBurnCDPage property page

IMPLEMENT_DYNCREATE(CBurnCDPage, CPropertyPageEx)

CBurnCDPage::CBurnCDPage() : CPropertyPageEx(CBurnCDPage::IDD, 0, 
										IDS_BURN_CD_HEADER, IDS_BURN_CD_SUBHEADER)
{
	//{{AFX_DATA_INIT(CBurnCDPage)
	m_Simulation = FALSE;
	m_Feedback = _T("");
	//}}AFX_DATA_INIT
}

CBurnCDPage::~CBurnCDPage()
{
}

void CBurnCDPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPageEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBurnCDPage)
	DDX_Control(pDX, IDC_BURN_SPEED, m_Speed);
	DDX_Control(pDX, IDC_BURN_PROGRESS, m_BurnProgress);
	DDX_Control(pDX, IDC_DRIVE_LIST, m_Drive);
	DDX_Check(pDX, IDC_SIMULATION, m_Simulation);
	DDX_Text(pDX, IDC_FEEDBACK, m_Feedback);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBurnCDPage, CPropertyPageEx)
	//{{AFX_MSG_MAP(CBurnCDPage)
	ON_BN_CLICKED(IDC_CHANGE_LAYOUT, OnChangeLayout)
	ON_BN_CLICKED(IDC_BURN_CD, OnBurnCD)
	ON_BN_CLICKED(IDC_AVOID_BURN, OnAvoidBurn)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_BURN_PROGRESS, OnBurnProgress)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBurnCDPage message handlers

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

void CBurnCDPage::OnChangeLayout() 
{
	char lpFilename[_MAX_PATH];
	ZeroMemory(lpFilename, _MAX_PATH);
	GetModuleFileName(AfxGetInstanceHandle(), lpFilename, _MAX_PATH);
	
	CString szPath;
	CString szApp;
	szApp=AfxGetApp()->m_pszExeName;
	szApp+=CString(".exe");
	
	szPath=lpFilename;
	szPath.Replace(szApp, "");
	
	szPath+=theConf.m_ProjectName;
	
	ShellExecute(m_hWnd, "open", "explorer.exe", szPath, NULL, SW_SHOW);	
}

void CBurnCDPage::OnAvoidBurn() 
{
	CPropertySheetEx* pParent=(CPropertySheetEx*) GetParent();
	pParent->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);		
}

BOOL CBurnCDPage::OnInitDialog() 
{
	CPropertyPageEx::OnInitDialog();
	
	theConf.m_BurnWindow=m_hWnd;

	FillComboDrives();

	m_BurnProgress.SetRange32(0, 100);
	m_Speed.SetCurSel(5);	//24x
	
	if (m_Drive.GetCount())
		m_Drive.SetCurSel(0);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBurnCDPage::OnBurnCD() 
{
	CPropertySheetEx* pParent=(CPropertySheetEx*) GetParent();
	pParent->SetWizardButtons(PSWIZB_BACK);		
	
	//get the specified drive to write
	CString DriveName;
	m_Drive.GetWindowText(DriveName);
	strcpy(m_DriveName, DriveName.GetBuffer(0));
	
	GetDlgItem(IDC_BURN_CD)->EnableWindow(FALSE);
	GetDlgItem(IDC_AVOID_BURN)->EnableWindow(FALSE);
	
	UpdateData(TRUE);
	
	strcpy(szDriveName, DriveName.GetBuffer(0));
	//BurnThread bt;
	//strcpy(bt.DriveName, m_DriveName);
	//strcpy(bt.DriveName, theConf.m_DriveLetter.GetBuffer(0));
	
	gSimulation=m_Simulation;
	
	
	AfxBeginThread(CheckCD, NULL);
	//AfxBeginThread(BurnCD, &m_Simulation /*&bt*/ /*(char*) m_DriveName*/);
}

UINT CheckCD(LPVOID pParam)
{
	//check if there is any file on targeted CD
	//and the option to format the CD
	int argc;
	char argv[11][100];
	char* pargv[100];
	char** ppargv;
	
	//query the device
	argc=2;
	strcpy(argv[0], "--listdrives");
	strcpy(argv[1], "--no_error_log");


	for (int i=0; i<argc; i++)
		pargv[i]=argv[i];
	
	ppargv=pargv;
	
	UINT iRes=DoNeroTask(argc, ppargv);

	int iFind=theConf.m_DriveList.Find(szDriveName);

	if (iFind!=-1)
	{
		//find something
		int Len=theConf.m_DriveList.GetLength();
		CString temp=theConf.m_DriveList.Right(Len - iFind + 2);

		//now we have the drive letter
		temp=temp.Left(1);
				
		//search the drive letter to find is there any file on CD or not
		if (WarnForFileOnCD(temp))
		{
			int iResult=AfxMessageBox("There are some files on your CD.\n"
				"If you want to format it click on Retry\n"
				"if not, click on Cancel, eject the CD and\n"
				"click on Burn button again.", 
				MB_ICONEXCLAMATION | MB_RETRYCANCEL | MB_DEFBUTTON2);

			if (iResult==IDRETRY)
			{
				//format the CD
				//--erase [--entire] --drivename <name>
				argc=5;
				strcpy(argv[0], "--erase");
				strcpy(argv[1], "--entire");
				strcpy(argv[2], "--drivename");
				strcpy(argv[3], temp.GetBuffer(0));
				strcpy(argv[4], "--no_error_log");
				
				
				for (int i=0; i<argc; i++)
					pargv[i]=argv[i];
				
				ppargv=pargv;
				
				iRes=DoNeroTask(argc, ppargv);
				
				//burn the content
				AfxBeginThread(BurnCD, &gSimulation /*&bt*/ /*(char*) m_DriveName*/);
			}
			else	//cancel
			{
				//eject the CD
				//--eject --drivename
				argc=4;
				strcpy(argv[0], "--eject");
				strcpy(argv[1], "--drivename");
				strcpy(argv[2], temp.GetBuffer(0));
				strcpy(argv[3], "--no_error_log");
				
				
				for (int i=0; i<argc; i++)
					pargv[i]=argv[i];
				
				ppargv=pargv;
				
				iRes=DoNeroTask(argc, ppargv);

				return 0;
			}	//iResult==IDRETRY
		}	//WarnForFileOnCD
		else
		{
			//there is no file on CD
			//burn CD regularly
			AfxBeginThread(BurnCD, &gSimulation /*&bt*/ /*(char*) m_DriveName*/);
		}

	}
		
	return 0;
}

UINT BurnCD(LPVOID pParam)
{
	//BurnThread* pbt=(BurnThread*) pParam;
	//char* DriveName=(char*) pParam;
	
	BOOL bSimulation=*((BOOL*) pParam);
	
	CString ProjectFolder;
	ProjectFolder.Format("%s\\*.*", theConf.m_ProjectName);

	int argc;
	char argv[11][100];
	char* pargv[100];
	char** ppargv;


/*
	//if we want image recording
	
	CString ISOFile;
	ISOFile.Format("%s.iso", theConf.m_ProjectName);

	argc=11;
	//strcpy(argv[0], "NeroCMD");
	strcpy(argv[0], "--write");
	strcpy(argv[1], "--drivename");
	strcpy(argv[2], IMAGE_RECORDER);	///"Image Recorder"
	strcpy(argv[3], "--real");
	strcpy(argv[4], "--iso");
	strcpy(argv[5], theConf.m_ProjectName.GetBuffer(0));	//Title
	strcpy(argv[6], ProjectFolder.GetBuffer(0));			//Folder
	strcpy(argv[7], "--recursive");
	strcpy(argv[8], "--output_image");
	strcpy(argv[9], ISOFile.GetBuffer(0));
	strcpy(argv[10], "--no_error_log");
	
*/
	
	//if we want to create real CD
	//if (!pbt->Simulation)		//real burn
	if (!bSimulation)
	{
		argc=9;
		//strcpy(argv[0], "NeroCMD");
		strcpy(argv[0], "--write");
		strcpy(argv[1], "--drivename");
		strcpy(argv[2], szDriveName); //theConf.m_DriveLetter.GetBuffer(0) /*pbt->DriveName/ /*DriveName/);	
		strcpy(argv[3], "--real");
		strcpy(argv[4], "--iso");
		//strcpy(argv[5], "--speed");
		//strcpy(argv[6], "");
		strcpy(argv[5], theConf.m_ProjectName.GetBuffer(0));	//Title
		strcpy(argv[6], ProjectFolder.GetBuffer(0));			//Folder
		strcpy(argv[7], "--recursive");
		strcpy(argv[8], "--no_error_log");
	}
	else							//simulation mode
	{
		argc=8;
		//strcpy(argv[0], "NeroCMD");
		strcpy(argv[0], "--write");
		strcpy(argv[1], "--drivename");
		strcpy(argv[2], szDriveName); //theConf.m_DriveLetter.GetBuffer(0) /*pbt->DriveName/ /*DriveName/);	
		//strcpy(argv[3], "--real");	//fake burn -> simulation
		strcpy(argv[3], "--iso");
		//strcpy(argv[5], "--speed");
		//strcpy(argv[6], "");
		strcpy(argv[4], theConf.m_ProjectName.GetBuffer(0));	//Title
		strcpy(argv[5], ProjectFolder.GetBuffer(0));			//Folder
		strcpy(argv[6], "--recursive");
		strcpy(argv[7], "--no_error_log");
	}
	

	for (int i=0; i<argc; i++)
		pargv[i]=argv[i];

	ppargv=pargv;

	UINT iRes=DoNeroTask(argc, ppargv);

/*
	PARAMETERS params;
	EXITCODE code;
	CBurnContext s_BurnContext(&params);
	
	// Get the parameters from the command line.
	
	if (!getopt (params, //--
				argc, //++
				ppargv))
	{
		return s_BurnContext.Exit (EXITCODE_BAD_USAGE);
	}
	
	// Open the log file. If the log file name was not specified
	// no file will be be openned.
	
	s_BurnContext.OpenLogFile (params.GetErrorLogName());
	
	// Load the NEROAPI.DLL.
	
	code = s_BurnContext.NeroLoad ();
	if (code != EXITCODE_OK)
	{
		return s_BurnContext.Exit (code);
	}
	
	if (COMMAND_VERSION == params.GetCommand())
	{
		// Display version information.
		
		s_BurnContext.CommandVersion ();
		code = EXITCODE_OK;
	}
	else
	{
		// Initialize NeroAPI.
		
		code = s_BurnContext.InitNeroAPI ();
		if (code == EXITCODE_OK)
		{
			if (params.GetCommand () == COMMAND_IMAGE_INFO)
			{
				code = s_BurnContext.CommandImageInfo (params);
			}
			else
			{
				// Get available drives.
				
				code = s_BurnContext.GetAvailableDrives (params);
				if (code == EXITCODE_OK)
				{
					switch (params.GetCommand())
					{
					case COMMAND_LISTDRIVES:
						// Just give a nice listing of all available drives.
						
						code = s_BurnContext.CommandListDrives (params);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -