📄 cloneburnerdlg.cpp
字号:
// This is a part of the High Performance CD Engine Library.
// Copyright (C) 2001-2003 Swift Software Group Incorporated
// All rights reserved.
//
// This source code is only intended as a supplement to the
// High Performance CD Engine Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// High Performance CD Engine product.
// AudioBurnerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CloneBurner.h"
#include "CloneBurnerDlg.h"
#include "DialogProgress.h"
#include "TocEntry.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BLOCKS_AT_ONCE 10
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCloneBurnerDlg dialog
CCloneBurnerDlg::CCloneBurnerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCloneBurnerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCloneBurnerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_AUDIO_ICON);
m_pEnumerator=NULL;
memset(&m_ctx, 0, sizeof(m_ctx));
m_hOperationStartedEvent=CreateEvent(NULL, TRUE, FALSE, NULL);
m_hNotifyEvent=CreateEvent(NULL, TRUE, FALSE, NULL);
InitializeCriticalSection(&m_cs);
m_notify.nPercent=0;
m_notify.strText="";
m_pDevice = NULL;
m_nDevicesCount = 0;
}
CCloneBurnerDlg::~CCloneBurnerDlg()
{
CloseHandle(m_hOperationStartedEvent);
CloseHandle(m_hNotifyEvent);
DeleteCriticalSection(&m_cs);
}
void CCloneBurnerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON_ERASE, m_btnErase);
DDX_Control(pDX, IDC_CHECK_QUICK, m_chkQuick);
DDX_Control(pDX, IDC_STATIC_FREE_SPACE, m_staticFreeSpace);
DDX_Control(pDX, IDC_COMBO_SPEED, m_comboSpeed);
DDX_Control(pDX, IDC_COMBO_DEVICES, m_comboDevices);
DDX_Control(pDX, IDC_COMBO_RAW_MODE, m_comboRawMode);
DDX_Control(pDX, IDC_CHECK_TEST, m_chkTest);
DDX_Control(pDX, IDC_CHECK_EJECT, m_chkEject);
DDX_Control(pDX, IDC_BUTTON_START, m_btnStart);
DDX_Control(pDX, IDC_EDIT_ROOT, m_editRootDir);
}
BEGIN_MESSAGE_MAP(CCloneBurnerDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_EJECTIN, OnButtonEjectin)
ON_BN_CLICKED(IDC_BUTTON_EJECTOUT, OnButtonEjectout)
ON_BN_CLICKED(IDC_BUTTON_ERASE, OnButtonErase)
ON_MESSAGE( WM_DEVICECHANGE, OnDeviceChange)
ON_CBN_SELCHANGE(IDC_COMBO_DEVICES, OnCbnSelchangeComboDevices)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnBnClickedButtonBrowse)
END_MESSAGE_MAP()
void CCloneBurnerDlg::SetDeviceControls(int nIndex)
{
m_nDevice=nIndex;
ICDDevice11* pDevice= (ICDDevice11*)m_pEnumerator->GetItem(m_arIndices[m_nDevice]);
if (pDevice==NULL)
{
TRACE("Function CCloneBurnerDlg::SetDeviceControls : Unable to get device object\nPossible reason : auto-insert notification enabled\nwhile writing (or any other) operation is in progress.\nThis is just a warning message - your CD is not damaged.");
return; // Protection from AI notification...
}
int nCapacity = pDevice->GetAvailableBlocks();
if (nCapacity == 0)
{
m_staticFreeSpace.SetWindowText("Insert a blank disc.");
m_btnStart.EnableWindow(FALSE);
m_nCapacity=0;
}
else
{
int nMin=(nCapacity)/(75*60);
BOOL bEmpty=pDevice->GetMediaIsBlank();
CString str;
if (bEmpty)
str.Format("%d min free (a blank disc)", nMin);
else
str.Format("%d min free (not a blank disc)", nMin);
m_staticFreeSpace.SetWindowText(str);
m_nCapacity=nCapacity;
m_btnStart.EnableWindow(m_nCapacity > 0);
}
int nCurSpeed, nCurSel;
nCurSel=m_comboSpeed.GetCurSel();
nCurSpeed=m_comboSpeed.GetItemData(nCurSel);
int nSpeed=pDevice->GetMaxWriteSpeed();
m_comboSpeed.ResetContent();
int nCnt = 0;
CString sSpeed;
for (int i = nSpeed; i > 0; i -= 2)
{
sSpeed.Format("x%d", i);
m_comboSpeed.InsertString(-1, sSpeed);
m_comboSpeed.SetItemData(nCnt++, i);
}
// Restore speed...
if (nCurSel != -1 && nCurSpeed <= nSpeed)
nSpeed = nCurSpeed;
sSpeed.Format("x%d", nSpeed);
m_comboSpeed.SelectString(-1, sSpeed);
BOOL bRW, bRWDisk;
bRW = pDevice->GetReWritePossible();
bRWDisk = pDevice->GetMediaIsReWritable();
if (bRW && bRWDisk)
{
m_chkQuick.EnableWindow();
m_btnErase.EnableWindow();
}
else
{
m_chkQuick.EnableWindow(FALSE);
m_btnErase.EnableWindow(FALSE);
}
pDevice->Release();
}
/////////////////////////////////////////////////////////////////////////////
// CCloneBurnerDlg message handlers
BOOL CCloneBurnerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_chkTest.SetCheck(FALSE);
m_chkEject.SetCheck(FALSE);
m_pEngine=hpCDE::CreateEngine();
BOOL bResult=m_pEngine->Initialize();
if (!bResult)
{
bResult=m_pEngine->Initialize(TRUE);
if (!bResult)
{
AfxMessageBox("Unable to initialize CD writing engine.");
EndModalLoop(-1);
if (m_pEnumerator)
{
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
}
m_pEnumerator=m_pEngine->GetDeviceEnumerator();
int nDevices=m_pEnumerator->GetCount();
if (!nDevices)
{
AfxMessageBox("No CD devices available.");
EndModalLoop(-1);
if (m_pEnumerator)
{
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
m_nDevicesCount=0;
for (int i=0; i < nDevices; i++)
{
ICDDevice * pDevice=m_pEnumerator->GetItem(i);
if (!pDevice)
continue;
BOOL bWrite = pDevice->GetWritePossible();
if (bWrite)
{
TCHAR tcsDesc[256]; TCHAR tchLetter;
pDevice->GetDescription(tcsDesc, 256);
tchLetter = pDevice->GetDriveLetter();
TCHAR tcsName[1000];
_stprintf(tcsName, _T("(%C:) - %s"), tchLetter, tcsDesc);
m_arDeviceNames.Add(tcsName);
m_arIndices.Add(i);
m_comboDevices.AddString(m_arDeviceNames[m_nDevicesCount++]);
}
pDevice->Release();
}
m_chkQuick.SetCheck(TRUE);
if (m_nDevicesCount)
{
m_comboDevices.SelectString(-1, m_arDeviceNames[0]);
SetDeviceControls(0);
}
else
{
AfxMessageBox("Unable ot open any CD writer device.");
EndModalLoop(-1);
if (m_pEnumerator) {
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
// 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);
}
}
DragAcceptFiles();
// 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
m_comboRawMode.AddString("RAW");
m_comboRawMode.AddString("RAW DATA (2352)");
m_comboRawMode.AddString("RAW DATA + SUB (2448)");
m_comboRawMode.SetCurSel(1);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCloneBurnerDlg::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 CCloneBurnerDlg::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 CCloneBurnerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCloneBurnerDlg::OnDestroy()
{
if (m_pEnumerator) {
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
m_pEngine->Shutdown();
m_pEngine->Release();
CDialog::OnDestroy();
}
void CCloneBurnerDlg::___PumpMessages()
{
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
DispatchMessage(&msg);
}
void CCloneBurnerDlg::OnButtonStart()
{
EnableWindow(FALSE);
CDialogProgress dlg;
dlg.Create();
dlg.ShowWindow(SW_SHOW);
dlg.UpdateWindow();
dlg.SetStatus("Initializing...");
int nSel;
m_ctx.bStopRequest=FALSE;
m_ctx.bErasing=FALSE;
m_ctx.bSimulate=m_chkTest.GetCheck();
m_ctx.bEject=m_chkEject.GetCheck();
nSel = m_comboSpeed.GetCurSel();
m_ctx.nSpeed = m_comboSpeed.GetItemData(nSel);
m_ctx.nRawMode = m_comboRawMode.GetCurSel();
ResetEvent(m_hOperationStartedEvent);
ResetEvent(m_hNotifyEvent);
DWORD dwId;
m_hThread=CreateThread(NULL, NULL, ThreadProc, this, NULL, &dwId);
WaitForSingleObject(m_hOperationStartedEvent, INFINITE);
while (WaitForSingleObject(m_hThread, 50)==WAIT_TIMEOUT) {
___PumpMessages();
if (dlg.m_bStopped)
m_ctx.bStopRequest=TRUE;
if (WaitForSingleObject(m_hNotifyEvent, 0)==WAIT_OBJECT_0) {
ResetEvent(m_hNotifyEvent);
EnterCriticalSection(&m_cs);
dlg.SetStatus(m_notify.strText);
dlg.SetProgress(m_notify.nPercent);
dlg.SetInternalBuffer(m_notify.nUsedCachePercent);
LeaveCriticalSection(&m_cs);
}
}
dlg.DestroyWindow();
EnableWindow();
BringWindowToTop();
SetActiveWindow();
m_notify.nPercent=0;
m_notify.nUsedCachePercent = 0;
m_notify.strText="";
m_comboDevices.SelectString(-1, m_arDeviceNames[m_nDevice]);
SetDeviceControls(m_nDevice);
}
LRESULT CCloneBurnerDlg::OnDeviceChange(WPARAM wParam, LPARAM lParam)
{
m_comboDevices.SelectString(-1, m_arDeviceNames[m_nDevice]);
SetDeviceControls(m_nDevice);
return 0;
}
void CCloneBurnerDlg::OnButtonEjectin()
{
ICDDevice* pDevice=m_pEnumerator->GetItem(m_arIndices[m_nDevice]);
pDevice->Eject(0);
pDevice->Release();
}
void CCloneBurnerDlg::OnButtonEjectout()
{
ICDDevice* pDevice=m_pEnumerator->GetItem(m_arIndices[m_nDevice]);
pDevice->Eject(1);
pDevice->Release();
}
void CCloneBurnerDlg::OnButtonErase()
{
EnableWindow(FALSE);
CDialogProgress dlg;
dlg.Create();
dlg.ShowWindow(SW_SHOW);
dlg.UpdateWindow();
dlg.GetDlgItem(IDOK)->EnableWindow(FALSE);
dlg.SetStatus("Erasing disc. Please wait...");
m_ctx.bErasing=TRUE;
m_ctx.bQuick=m_chkQuick.GetCheck();
ResetEvent(m_hOperationStartedEvent);
DWORD dwId;
m_hThread=CreateThread(NULL, NULL, ThreadProc, this, NULL, &dwId);
WaitForSingleObject(m_hOperationStartedEvent, INFINITE);
while (WaitForSingleObject(m_hThread, 0)==WAIT_TIMEOUT)
{
___PumpMessages();
Sleep(50);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -