?? nerofiddlesdlg.cpp
字號:
/******************************************************************************
|* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|* PARTICULAR PURPOSE.
|*
|* Copyright 1995-2003 Ahead Software AG. All Rights Reserved.
|*-----------------------------------------------------------------------------
|* PROJECT: neroFiddles NeroAPI Example
|*
|* FILE: neroFiddlesDlg.cpp
|*
|* PURPOSE: Implementation of a dialog for interaction with the user.
******************************************************************************/
// neroFiddlesDlg.cpp : implementation file
//
#include "stdafx.h"
#include "neroFiddles.h"
#include "neroFiddlesDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNeroFiddlesDlg dialog
CNeroFiddlesDlg::CNeroFiddlesDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNeroFiddlesDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNeroFiddlesDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNeroFiddlesDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNeroFiddlesDlg)
DDX_Control(pDX, IDOK, mOK);
DDX_Control(pDX, IDCANCEL, mCancel);
DDX_Control(pDX, IDC_ABORT, mbtnAbort);
DDX_Control(pDX, IDC_PROGRESS1, mpgsProgress);
DDX_Control(pDX, IDC_MESSAGES, medtMessages);
DDX_Control(pDX, IDC_FILENAME, medtFileName);
DDX_Control(pDX, IDC_DEVICES, mcbxDevices);
DDX_Control(pDX, IDC_BURN, mbtnBurn);
DDX_Control(pDX, IDC_BROWSE, mbtnBrowse);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNeroFiddlesDlg, CDialog)
//{{AFX_MSG_MAP(CNeroFiddlesDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_BURN, OnBurn)
ON_BN_CLICKED(IDC_ABORT, OnAbort)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNeroFiddlesDlg message handlers
BOOL CNeroFiddlesDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// Initialize the NeroAPI
NeroAPIInit();
return TRUE; // return TRUE unless you set the focus to a control
}
void CNeroFiddlesDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CNeroFiddlesDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNeroFiddlesDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNeroFiddlesDlg::OnBrowse()
{
// browse for the MP3 file that is supposed to be burned on CD
// provide information about the file type that we want to open
static char BASED_CODE szFilter[] = "MP3 Files (*.mp3)|*.mp3|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_FILEMUSTEXIST, only accepts file names for files that are present
// szFilter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||"
// pParentWnd = this, our current Dialog window is the parent
CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, szFilter, this);
// do nothing if IDCANCEL is returned
if (dlgOpen.DoModal() == IDOK)
{
// retrieve and display the selected file name
mstrPathName = dlgOpen.GetPathName();
mstrFileName = dlgOpen.GetFileName();
medtFileName.SetWindowText(mstrPathName);
// check whether any devices have been found
if (pndiDeviceInfos->nsdisNumDevInfos > 0)
{
// make the "Burn" button accessible
mbtnBurn.EnableWindow(true);
}
}
}
void CNeroFiddlesDlg::OnBurn()
{
// TODO: Add your control notification handler code here
// perform the burn process
// check whether a file has been selected
if (mstrFileName == "")
{
// Tell the user what went wrong
AppendString("You have to choose a file before you can start burning!");
}
else
{
// a file has been selected; fill the NERO_ISO_ITEM struct
strcpy(mniiFile.fileName, mstrFileName);
strcpy(mniiFile.sourceFilePath, mstrPathName);
mniiFile.isDirectory=FALSE;
mniiFile.isReference=FALSE;
// we only have one item
mniiFile.nextItem=NULL;
// no CD stamp, artist or title required
writeCD.nwcdpCDStamp=NULL;
writeCD.nwcdArtist=NULL;
writeCD.nwcdTitle=NULL;
// no CD Extra information available
writeCD.nwcdCDExtra=FALSE;
// we have no Audio tracks
writeCD.nwcdNumTracks=0;
// we want to write to a CD
writeCD.nwcdMediaType = MEDIA_CD;
// get the currently selected device from the ComboBox
int i = mcbxDevices.GetCurSel();
// retrieve the NERO_SCSI_DEVICE_INFO pointer for the selected device
// and assign it to a local variable
NERO_SCSI_DEVICE_INFO* nsdiDevice = (NERO_SCSI_DEVICE_INFO*)mcbxDevices.GetItemDataPtr(i);
// try to open the selected device
ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
// check whether a valid handle was returned
if (!ndhDeviceHandle)
{
// no handle available; tell the user what happened
AppendString("Device could not be opened: "+(CString)nsdiDevice->nsdiDeviceName);
}
else
{
// we have a valid device handle
// while burning the "Abort" button needs to be enabled
// all the other buttons and controls have to be disabled
mbtnAbort.EnableWindow(true);
mCancel.EnableWindow(false);
mOK.EnableWindow(false);
mcbxDevices.EnableWindow(false);
mbtnBrowse.EnableWindow(false);
mbtnBurn.EnableWindow(false);
// set the range for the progress control, we will display percent
mpgsProgress.SetRange(0,100);
// create an ISO track
// usage : NeroCreateIsoTrack(struct NERO_ISO_ITEM *root, const char *name,
// BOOL useJoliet, BOOL useMode2);
//
// root = mniiFile, the NERO_ISO_ITEM we filled before
// name = neroFiddles
writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(&mniiFile, "neroFiddles", NCITEF_CREATE_ISO_FS|NCITEF_USE_JOLIET);
// start the burn process by calling NeroBurn
// usage:NEROAPI_BURN_ERROR NADLL_ATTR NeroBurn( NERO_DEVICEHANDLE aDeviceHandle,
// NERO_CD_FORMAT CDFormat, const void* pWriteCD, DWORD dwFlags, DWORD dwSpeedInX,
// NERO_PROGRESS* pNeroProgress);
//
// aDeviceHandle = ndhDeviceHandle, the handle we got from NeroOpenDevice()
// CDFormat = NERO_ISO_AUDIO_CD
// pWriteCD = writeCD
// dwFlags = NBF_WRITE, do not simulate - burn!
// dwSpeedInX = 0, use maximum speed
// pNeroProgress = npProgress, filled during NeroAPIInit()
int iRes = NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD, NBF_WRITE, 0, &npProgress);
// free memory that was allocated for the track
NeroFreeIsoTrack(writeCD.nwcdIsoTrack);
// close the device
NeroCloseDevice(ndhDeviceHandle);
// burning is finished, disable "Abort" activate all other controls
mbtnAbort.EnableWindow(false);
mCancel.EnableWindow(true);
mOK.EnableWindow(true);
mcbxDevices.EnableWindow(true);
mbtnBrowse.EnableWindow(true);
mbtnBurn.EnableWindow(true);
// clear the progress bar
mpgsProgress.SetPos(0);
// make sure that aborted flag is not set if "Burn" button is pressed again
mbAborted = false;
// retrieve the error log
char* Log = NeroGetErrorLog();
// display the error log contents
AppendString(Log);
// free the log
NeroFreeMem(Log);
// tell the user how the burn process was finished
switch(iRes)
{
case NEROAPI_BURN_OK:
AppendString ("BurnCD() : burn successful");
break;
case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
AppendString ("BurnCD() : unknown CD format");
break;
case NEROAPI_BURN_INVALID_DRIVE:
AppendString ("BurnCD() : invalid drive");
break;
case NEROAPI_BURN_FAILED:
AppendString ("BurnCD() : burn failed");
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -