📄 chtrecnerodlg.cpp
字号:
// ChtRecNeroDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ChtRecNero.h"
#include "ChtRecNeroDlg.h"
#include "EraseOption.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef struct _tag_RInfo{
bool isDir;
CString FullName;
}RInfo,*PRInfo;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CChtRecNeroDlg dialog
CChtRecNeroDlg::CChtRecNeroDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChtRecNeroDlg::IDD, pParent)
, m_pFile(NULL)
, m_pniiFile(NULL)
, m_pnwcWriteCD(NULL)
, m_pndiDeviceInfos(NULL)
{
//{{AFX_DATA_INIT(CChtRecNeroDlg)
m_strMediaType = _T("");
m_strPlusValue = _T("");
m_strCapValue = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_strTotalSize="";
m_dTotalSize=0;
m_NeroCDInfo=NULL;
m_dFileNum=0;
m_hAccelTable=::LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACCELERATOR1));
}
void CChtRecNeroDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChtRecNeroDlg)
DDX_Control(pDX, IDC_TREE1, m_Tree);
DDX_Control(pDX, IDC_ERASE, m_btnErase);
DDX_Control(pDX, IDC_REMOVE, m_btnRemove);
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Control(pDX, IDC_PROGRESS1, m_pgsProgress);
DDX_Control(pDX, IDC_FILELIST, m_lstFileList);
DDX_Control(pDX, IDC_DEVICES, m_cbxDevices);
DDX_Control(pDX, IDC_BURN, m_btnBurn);
DDX_Control(pDX, IDC_BROWSE, m_btnBrowse);
DDX_Text(pDX, IDC_CURMEDIATYPEVALUE, m_strMediaType);
DDX_Text(pDX, IDC_PLUSVALUE, m_strPlusValue);
DDX_Text(pDX, IDC_CAPVALUE, m_strCapValue);
DDX_Text(pDX, IDC_WAITRECLENVALUE, m_strTotalSize);
DDX_Text(pDX, IDC_FILENUMVALUE, m_dFileNum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChtRecNeroDlg, CDialog)
//{{AFX_MSG_MAP(CChtRecNeroDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
ON_BN_CLICKED(IDC_BURN, OnBurn)
ON_LBN_SELCHANGE(IDC_FILELIST, OnSelchangeFilelist)
ON_BN_CLICKED(IDC_ERASE, OnEraseCDRW)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_NOTIFY(NM_RCLICK, IDC_TREE1, OnRclickTree1)
ON_COMMAND(ID_MENUADD, OnMenuadd)
ON_COMMAND(ID_MENUNEW, OnMenunew)
ON_NOTIFY(TVN_ENDLABELEDIT, IDC_TREE1, OnEndlabeleditTree1)
ON_COMMAND(ID_MENUFIDEL, OnMenufidel)
ON_COMMAND(ID_MENUFODEL, OnMenufodel)
ON_NOTIFY(NM_SETFOCUS, IDC_TREE1, OnSetfocusTree1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChtRecNeroDlg message handlers
BOOL CChtRecNeroDlg::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
((CButton*)GetDlgItem(IDC_CONTINUE))->SetCheck(BST_CHECKED);;
// TODO: Add extra initialization here
NeroAPIInit();
if(m_pndiDeviceInfos->nsdisNumDevInfos!=1)
{
int i = m_cbxDevices.GetCurSel();
NERO_SCSI_DEVICE_INFO* nsdiDevice =(NERO_SCSI_DEVICE_INFO*)m_cbxDevices.GetItemDataPtr(i);
m_ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
if (!m_ndhDeviceHandle)
{
AfxMessageBox("Device could not be opened: "+(CString)nsdiDevice->nsdiDeviceName);
}
else
{
m_strMediaType= "<no media>";
DWORD dwFlags=0;
m_NeroCDInfo=NeroGetCDInfo (m_ndhDeviceHandle, dwFlags);
if (NULL != m_NeroCDInfo)
{
char * psMedia = NeroGetTypeNameOfMedia (m_NeroCDInfo->ncdiMediaType, NULL);
if (psMedia != NULL && psMedia[0] != '\0')
{
m_strMediaType=CString(psMedia);
if(m_strMediaType=="CD-RW")
m_btnErase.EnableWindow(true);
NeroFreeMem (psMedia);
}
else
{
m_strMediaType= "<no media>";
}
m_strPlusValue.Format("%dM",(int)((float)m_NeroCDInfo->ncdiFreeCapacityInBlocks/359849*700));
m_strCapValue.Format("%dM",(int)((float)m_NeroCDInfo->ncdiTotalCapacity/359849*700));
}
else{m_btnBurn.EnableWindow(false);}
UpdateData(FALSE);
NeroFreeMem (m_NeroCDInfo);
}
NeroCloseDevice(m_ndhDeviceHandle);
}
else{m_btnBrowse.EnableWindow(false);
AfxMessageBox("No Real Drive");}
m_SmallImageList.Create(16, 16, ILC_COLOR8 | ILC_MASK, 9, 9);
int tr=m_SmallImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON));
TV_INSERTSTRUCT tvInsert;
HTREEITEM hItem;
m_Tree.SetImageList(&m_SmallImageList,TVSIL_NORMAL);
tvInsert.item.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
tvInsert.hParent=NULL;
tvInsert.hInsertAfter=TVI_LAST;
tvInsert.item.pszText="新建";
tvInsert.item.iImage=0;
tvInsert.item.iSelectedImage=0;
hItem=m_Tree.InsertItem(&tvInsert);
return TRUE; // return TRUE unless you set the focus to a control
}
void CChtRecNeroDlg::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 CChtRecNeroDlg::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 CChtRecNeroDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CChtRecNeroDlg::OnBrowse()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilterAudio[] = "MP3 Files (*.mp3)|*.mp3|AllFiles (*.*)|*.*||";
static char BASED_CODE szFilterData[] = "All Files (*.*)|*.*||";
CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_FILEMUSTEXIST |OFN_ALLOWMULTISELECT, szFilterData, this);
if (dlgOpen.DoModal() == IDOK)
{
POSITION pos = dlgOpen.GetStartPosition();
while (pos != NULL)
{
CString filename = dlgOpen.GetNextPathName(pos);
if (m_lstFileList.FindString(0, filename) == LB_ERR)
{
m_lstFileList.AddString(filename);
HANDLE hFile;
DWORD dwFileSize;
hFile = CreateFile(filename, GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
dwFileSize = GetFileSize(hFile, NULL);
m_dTotalSize+=dwFileSize;
m_strTotalSize.Format("%ldM",m_dTotalSize/1024/1024);
m_dFileNum++;
UpdateData(FALSE);
InvalidateRect(NULL,FALSE);
CloseHandle(hFile);
}
}
if (m_pndiDeviceInfos->nsdisNumDevInfos > 0)
{
m_btnBurn.EnableWindow(true);
}
}
m_btnBurn.EnableWindow(true);//11 13++++++
}
void CChtRecNeroDlg::OnRemove()
{
int selCount = m_lstFileList.GetSelCount();
if (selCount > 0)
{
int* selection = new int[selCount];
m_lstFileList.GetSelItems(selCount, selection);
for (int i = selCount - 1; i >= 0; --i)
{
CString filename;
m_lstFileList.GetText(selection[i],filename);
HANDLE hFile;
DWORD dwFileSize;
hFile = CreateFile(filename, GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
dwFileSize = GetFileSize(hFile, NULL);
m_dTotalSize-=dwFileSize;
m_strTotalSize.Format("%dM",m_dTotalSize/1024/1024);
m_dFileNum--;
UpdateData(FALSE);
m_lstFileList.DeleteString(selection[i]);
CloseHandle(hFile);
}
delete[] selection;
}
m_btnRemove.EnableWindow(false);
}
void CChtRecNeroDlg::OnSelchangeFilelist()
{
int selCount=m_lstFileList.GetSelCount();
TRACE("chang is %d\n",selCount);
m_btnRemove.EnableWindow(selCount >0 );
}
void CChtRecNeroDlg::OnBurn()
{
HTREEITEM hItem=m_Tree.GetRootItem();
if(m_Tree.GetChildItem(hItem)==NULL)//11 15 加
return;
if (/*m_lstFileList.GetCount() == */0)
{
AfxMessageBox("You have to choose some files before you can start burning!");
}
else
{
int iNumAudio = 1;
if(m_pnwcWriteCD != NULL)
free(m_pnwcWriteCD), m_pnwcWriteCD = NULL;
size_t stTheSize = sizeof(NERO_WRITE_CD);
m_pnwcWriteCD = (NERO_WRITE_CD*)malloc(stTheSize);
memset(m_pnwcWriteCD, 0, stTheSize);
NERO_ISO_ITEM* niiPrevItem = 0;
// for (int index = 0; index < m_lstFileList.GetCount(); ++index)
// {
// 11 13---------------------------------------------
HTREEITEM hItem=m_Tree.GetRootItem();
hItem=m_Tree.GetChildItem(hItem);
while(hItem)
{
bool isDirectory=((PRInfo)m_Tree.GetItemData(hItem))->isDir;
NERO_ISO_ITEM* pniiNewItem = NeroCreateIsoItem();
memset(pniiNewItem, 0, sizeof(NERO_ISO_ITEM));
if (m_pniiFile == 0)
m_pniiFile = pniiNewItem;
if(isDirectory==TRUE)
{
if(!m_Tree.GetChildItem(hItem))
{//AfxMessageBox("dsdsd");
CString dirname=m_Tree.GetItemText(hItem);
pniiNewItem->longFileName = strdup(dirname);
pniiNewItem->longSourceFilePath = strdup("");
pniiNewItem->isDirectory =TRUE;
pniiNewItem->isReference = FALSE;
pniiNewItem->unicodeFileName = NULL;
pniiNewItem->nextItem = NULL;
}
else
{
CString dirname=m_Tree.GetItemText(hItem);
pniiNewItem->longFileName = strdup(dirname);
pniiNewItem->longSourceFilePath = strdup("");
pniiNewItem->isDirectory =TRUE;
pniiNewItem->isReference = FALSE;
pniiNewItem->unicodeFileName = NULL;
pniiNewItem->nextItem = NULL;
hItem=m_Tree.GetChildItem(hItem);
pniiNewItem->subDirFirstItem=DeepIntoNode(hItem,pniiNewItem);
hItem=m_Tree.GetParentItem(hItem);
//晚上加
//晚上加
/*if(niiPrevItem)
niiPrevItem->nextItem = pniiNewItem;
niiPrevItem = pniiNewItem;
hItem=m_Tree.GetNextSiblingItem(hItem);*/
}
}
else
{
CString filename=((PRInfo)m_Tree.GetItemData(hItem))->FullName;
char path[MAX_PATH];
char* name;
GetFullPathName(filename, MAX_PATH, path, &name);
pniiNewItem->longFileName = strdup(name);
pniiNewItem->longSourceFilePath = strdup(path);
pniiNewItem->isDirectory =FALSE;
pniiNewItem->isReference = FALSE;
pniiNewItem->unicodeFileName = NULL;
pniiNewItem->nextItem = NULL;
}
if(niiPrevItem)
niiPrevItem->nextItem = pniiNewItem;
niiPrevItem = pniiNewItem;
hItem=m_Tree.GetNextSiblingItem(hItem);
}
/*CString pathname;
m_lstFileList.GetText(0, pathname);
char path[MAX_PATH];
char* name;
GetFullPathName(pathname, MAX_PATH, path, &name);
NERO_ISO_ITEM* pniiNewItem = NeroCreateIsoItem();
memset(pniiNewItem, 0, sizeof(NERO_ISO_ITEM));
if (m_pniiFile == 0)
m_pniiFile = pniiNewItem;
//++++++++++++++++++++++++++++++++++++++++
CString pathname1;
m_lstFileList.GetText(0, pathname1);
char path1[MAX_PATH];
char* name1;
GetFullPathName(pathname1, MAX_PATH, path1, &name1);
m_lstFileList.GetText(1, pathname1);
//char path[MAX_PATH];
//char* name;
GetFullPathName(pathname1, MAX_PATH, path1, &name1);
NERO_ISO_ITEM* pniiNewItem1 = NeroCreateIsoItem();
memset(pniiNewItem1, 0, sizeof(NERO_ISO_ITEM));
if (m_pniiFile == 0)
m_pniiFile = pniiNewItem1;
pniiNewItem1->longFileName = strdup(name1);
pniiNewItem1->longSourceFilePath = strdup(path1);
pniiNewItem1->isDirectory =FALSE;
pniiNewItem1->isReference =FALSE;
pniiNewItem1->unicodeFileName = NULL;
pniiNewItem1->nextItem = NULL;
pniiNewItem->subDirFirstItem=pniiNewItem1;
//+++++++++++++++++++++++++++++
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -