📄 nerofiddlesdlg.cpp
字号:
case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
AppendString ("BurnCD() : function not allowed");
break;
case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
AppendString ("BurnCD() : drive not allowed");
break;
case NEROAPI_BURN_USER_ABORT:
AppendString ("BurnCD() : user aborted");
break;
case NEROAPI_BURN_BAD_MESSAGE_FILE:
AppendString ("BurnCD() : bad message file");
break;
default:
AppendString ("BurnCD() : unknown error");
break;
}
}
}
}
BOOL NERO_CALLBACK_ATTR CNeroFiddlesDlg::IdleCallback(void *pUserData)
{
// idle callback is called frequently by NeroAPI
// make sure that messages from other controls can be handled
static MSG msg;
while (!(((CNeroFiddlesDlg*)pUserData)->mbAborted) && ::PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
{
if (!AfxGetThread()->PumpMessage())
{
break;
}
}
// aborted-flag serves as function result
return ((CNeroFiddlesDlg*)pUserData)->mbAborted;
}
void CNeroFiddlesDlg::NeroAPIInit()
{
// initialization part, provide necessary information and check status
mbAborted = false;
// try to open the NeroAPI DLL
if (!NeroAPIGlueConnect (NULL))
{
AppendString("Cannot open NeroAPI.DLL");
// it makes no sense to continue after loading the DLL failed
return;
}
// the NeroAPI DLL could be openend, get version information
AppendString("Retrieving version information.");
WORD majhi, majlo, minhi, minlo;
NeroGetAPIVersionEx(&majhi, &majlo, &minhi, &minlo, NULL);
// format and display the version information
CString strVersion;
strVersion.Format("NeroAPI version %d.%d.%d.%d",
majhi, majlo, minhi, minlo);
AppendString(strVersion);
// setup of structures that the NeroAPI needs
AppendString("Filling NERO_SETTINGS structure");
// Information for registry access
strcpy(pcNeroFilesPath, "NeroFiles");
strcpy(pcVendor, "ahead");
strcpy(pcSoftware, "Nero - Burning Rom");
// use the US-English error message file
strcpy(pcLanguageFile, "Nero.txt");
nsSettings.nstNeroFilesPath = pcNeroFilesPath;
nsSettings.nstVendor = pcVendor;
// set pointers to various callback functions
nsSettings.nstIdle.ncCallbackFunction = IdleCallback;
// this pointer is required to access non-static variables from callback functions
nsSettings.nstIdle.ncUserData = this;
nsSettings.nstSoftware = pcSoftware;
nsSettings.nstUserDialog.ncCallbackFunction = UserDialog;
nsSettings.nstUserDialog.ncUserData = this;
nsSettings.nstLanguageFile =pcLanguageFile;
// npProgress will be used during the burn process
npProgress.npAbortedCallback = AbortedCallback;
npProgress.npAddLogLineCallback = AddLogLine;
npProgress.npDisableAbortCallback = NULL;
npProgress.npProgressCallback = ProgressCallback;
npProgress.npSetPhaseCallback = SetPhaseCallback;
npProgress.npUserData = this;
npProgress.npSetMajorPhaseCallback=NULL;
npProgress.npSubTaskProgressCallback=NULL;
// no devices available yet
pndiDeviceInfos = NULL;
// initialize the NeroAPI with nsSettings and the
// Serial Number that we got from the Registry
NEROAPI_INIT_ERROR initErr;
initErr = NeroInit (&nsSettings, NULL);
// display the result of NeroInit()
switch (initErr)
{
case NEROAPI_INIT_OK:
AppendString("Initialization of the NeroAPI successful.");
break;
case NEROAPI_INIT_INVALID_ARGS:
AppendString("The arguments are not valid.");
break;
case NEROAPI_INIT_INVALID_SERIAL_NUM:
AppendString("The Serial Number is not valid.");
break;
default:
AppendString("An error occured. The type of error cannot be determined.");
break;
}
// get a list of available drives
pndiDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_CD, NULL);
// check whether any devices have been found
if (!pndiDeviceInfos)
{
// no device found, let the user know
AppendString("NeroGetAvailableDrivesEx() returned no available devices.");
}
else
{
// devices found
// check the number of available devices to be sure
if (pndiDeviceInfos->nsdisNumDevInfos > 0)
{
// we have some devices, now fill the ComboBox
AppendString("Found the following devices:");
for (DWORD dDeviceCounter = 0; dDeviceCounter < pndiDeviceInfos->nsdisNumDevInfos; dDeviceCounter++)
{
AppendString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName);
// add the device name to the ComboBox and get the index number
int i = mcbxDevices.AddString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName);
// use the index number to access the corresponding entry
// connect the entry's ItemData pointer to a NERO_DEVICE_INFO structure
mcbxDevices.SetItemDataPtr(i, &pndiDeviceInfos->nsdisDevInfos[dDeviceCounter]);
}
// select the first ComboBox entry
mcbxDevices.SelectString(-1, pndiDeviceInfos->nsdisDevInfos[0].nsdiDeviceName);
}
else
{
AppendString("The number of available devices is 0.");
}
}
}
void CNeroFiddlesDlg::AppendString(CString str)
{
// a CString for temporary use
CString strBuffer;
// retrieve the content of the EditControl we use for messages
medtMessages.GetWindowText (strBuffer);
// add a new line if the EditControl is not empty
if (!strBuffer.IsEmpty())
{
strBuffer += "\r\n";
}
// append the string the function got as a parameter
strBuffer += str;
// update the EditiControl with the new content
medtMessages.SetWindowText (strBuffer);
// Scroll the edit control to the end
medtMessages.LineScroll (medtMessages.GetLineCount(), 0);
}
NeroUserDlgInOut NERO_CALLBACK_ATTR CNeroFiddlesDlg::UserDialog(void *pUserData, NeroUserDlgInOut type, void *data)
{
// handling of messages that require the user to perform an action
// for reasons of brevity we only deal with the messages that
// are absolutely mandatory for this application
switch (type)
{
case DLG_AUTO_INSERT:
return DLG_RETURN_CONTINUE;
break;
case DLG_DISCONNECT_RESTART:
return DLG_RETURN_ON_RESTART;
break;
case DLG_DISCONNECT:
return DLG_RETURN_CONTINUE;
break;
case DLG_AUTO_INSERT_RESTART:
return DLG_RETURN_EXIT;
break;
case DLG_RESTART:
return DLG_RETURN_EXIT;
break;
case DLG_SETTINGS_RESTART:
return DLG_RETURN_CONTINUE;
break;
case DLG_OVERBURN:
return DLG_RETURN_TRUE;
break;
case DLG_AUDIO_PROBLEMS:
return DLG_RETURN_EXIT;
break;
case DLG_FILESEL_IMAGE:
{
// create filter for image files
static char BASED_CODE szFilter[] = "Image Files (*.nrg)|*.nrg|All Files (*.*)|*.*||";
// create a CFileDialog object.
// usage : CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL,
// DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL,
// CWnd* pParentWnd = NULL );
//
// bOpenFileDialog = TRUE, create a File Open dialog
// lpszDefExt = NULL, do not automatically append a file extension
// dwFlags = OFN_OVERWRITEPROMPT, makes no sense during file open,
// just in case we decide to use File Save later
// szFilter = "Image Files (*.nrg)|*.nrg|All Files (*.*)|*.*||"
// pParentWnd = ((CNeroFiddlesDlg*)pUserData), our current Dialog window is the parent
CFileDialog dlgOpen(TRUE, NULL, "test.nrg", OFN_OVERWRITEPROMPT, szFilter, ((CNeroFiddlesDlg*)pUserData));
// check how the dialog was ended
if (dlgOpen.DoModal() == IDOK)
{
// user pressed "OK", copy the file name to the data parameter
strcpy((char*)data,dlgOpen.GetPathName());
// proceed with the burn process
return DLG_RETURN_TRUE;
}
else
{
// user canceled, do not proceed with the burn process
return DLG_BURNIMAGE_CANCEL;
}
}
break;
case DLG_WAITCD:
{
NERO_WAITCD_TYPE waitcdType = (NERO_WAITCD_TYPE) (int)data;
char *waitcdString = NeroGetLocalizedWaitCDTexts (waitcdType);
((CNeroFiddlesDlg*)pUserData)->AppendString(waitcdString);
NeroFreeMem(waitcdString);
return DLG_RETURN_EXIT;
break;
}
default:
break;
}
// default return value, in case we forgot to handle a request
return DLG_RETURN_EXIT;
}
BOOL NERO_CALLBACK_ATTR CNeroFiddlesDlg::ProgressCallback(void *pUserData, DWORD dwProgressInPercent)
{
// the NeroAPI updates the current progress counter
// set the progress bar to the percentage value that was passed to this function
((CNeroFiddlesDlg*)pUserData)->mpgsProgress.SetPos(dwProgressInPercent);
return true;
}
BOOL NERO_CALLBACK_ATTR CNeroFiddlesDlg::AbortedCallback(void *pUserData)
{
// do not ask the user if he really wants to abort
// just return the aborted flag
return ((CNeroFiddlesDlg*)pUserData)->mbAborted;
}
void NERO_CALLBACK_ATTR CNeroFiddlesDlg::AddLogLine(void *pUserData, NERO_TEXT_TYPE type, const char *text)
{
// Add the text that was passed to this function to the message log
CString csTemp(text);
((CNeroFiddlesDlg*)pUserData)->AppendString("Log line:" + csTemp);
return;
}
void NERO_CALLBACK_ATTR CNeroFiddlesDlg::SetPhaseCallback(void *pUserData, const char *text)
{
// display the current phase the burn process is currently going through
CString csTemp(text);
((CNeroFiddlesDlg*)pUserData)->AppendString("Phase: " + csTemp);
return;
}
void CNeroFiddlesDlg::NeroAPIFree()
{
// free the resources that have been used
// make sure there is something to free so we do not run into an exception
if (pndiDeviceInfos)
{
NeroFreeMem(pndiDeviceInfos);
}
// nothing to check before calling these functions
NeroClearErrors();
if(NeroDone())
{
AfxMessageBox("Detected memory leaks in NeroFiddles");
}
NeroAPIGlueDone();
return;
}
void CNeroFiddlesDlg::OnOK()
{
// TODO: Add extra validation here
// user decides to quit by pressing "OK"
NeroAPIFree();
CDialog::OnOK();
}
void CNeroFiddlesDlg::OnCancel()
{
// TODO: Add extra cleanup here
// user decides to quit by pressing "Cancel"
// we handle this like the "OK" button
NeroAPIFree();
CDialog::OnCancel();
}
void CNeroFiddlesDlg::OnAbort()
{
// TODO: Add your control notification handler code here
// nothing more required but setting the aborted flag
mbAborted = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -