home *** CD-ROM | disk | FTP | other *** search
Wrap
// MCDBDlg.cpp : implementation file // #include "StdAfx.h" #include "MCDB.h" #include "MCDBDlg.h" #include "..\..\include\MCDBCls.h" #include <math.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() ///////////////////////////////////////////////////////////////////////////// // CMCDBDlg dialog CMCDBurner mcdb; void DebugOutPut(CString smsg, CMCDBDlg* ptr); CMCDBDlg::CMCDBDlg(CWnd* pParent /*=NULL*/) : CDialog(CMCDBDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMCDBDlg) // 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 CMCDBDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMCDBDlg) DDX_Control(pDX, IDC_MEMO, Memo1); DDX_Control(pDX, IDC_DBS, dbs); DDX_Control(pDX, IDC_SCS, scs); DDX_Control(pDX, IDC_PB, pb); DDX_Control(pDX, IDC_FILES, files); DDX_Control(pDX, IDC_COMBO2, cbDrives); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMCDBDlg, CDialog) //{{AFX_MSG_MAP(CMCDBDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2) ON_BN_CLICKED(IDC_EJECT, OnEject) ON_BN_CLICKED(IDC_BURN, OnBurn) ON_WM_DESTROY() ON_WM_TIMER() ON_BN_CLICKED(IDC_ERASE, OnErase) ON_BN_CLICKED(IDC_LOAD, OnLoad) ON_NOTIFY(NM_DBLCLK, IDC_FILES, OnDblclkFiles) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMCDBDlg message handlers BOOL CMCDBDlg::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 int i; CString sDrive; _TCHAR* cDrive; for (i=0; i < mcdb.GetDeviceCount(); i++) { sDrive = mcdb.GetDeviceName(i); cDrive = (_TCHAR *) (LPCTSTR) sDrive; cbDrives.InsertString(cbDrives.GetCount(), cDrive); } if (cbDrives.GetCount() != 0) { cbDrives.SetCurSel(0); } OnSelchangeCombo2(); files.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_TRACKSELECT); LV_COLUMN lvColumn; lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 25; lvColumn.iSubItem = 0; lvColumn.pszText = _T("R"); files.InsertColumn(0, &lvColumn); lvColumn.cx = 300; lvColumn.iSubItem = 1; lvColumn.pszText = _T("File Name"); files.InsertColumn(1, &lvColumn); UINT dropMode; dropMode = CFileDropListCtrl::DL_ACCEPT_FILES | CFileDropListCtrl::DL_ACCEPT_FOLDERS; files.SetDropMode(dropMode); SetTimer(IDC_DLGTIMER, 100, NULL); #ifdef _UNICODE DebugOutPut("This is a demo application of Magic CD/DVD Burner C/C++ (UNICODE) Library.", this); #else DebugOutPut("This is a demo application of Magic CD/DVD Burner C/C++ Library.", this); #endif DebugOutPut("For further information/queries, please visit: http://www.binarymagics.com", this); DebugOutPut("", this); DebugOutPut("- Drag files/directories from Windows Explorer and drop into listbox.", this); DebugOutPut("- Double click on an entry in listbox to delete it.", this); return TRUE; // return TRUE unless you set the focus to a control } void CMCDBDlg::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 CMCDBDlg::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 CMCDBDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMCDBDlg::OnSelchangeCombo2() { // TODO: Add your control notification handler code here mcdb.SelectDevice(cbDrives.GetCurSel()); if (mcdb.DeviceIsBurner()) { GetDlgItem(IDC_BURN)->EnableWindow(TRUE); } else { GetDlgItem(IDC_BURN)->EnableWindow(FALSE); } } void CMCDBDlg::OnEject() { // TODO: Add your control notification handler code here DebugOutPut("Ejecting...", this); GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE); GetDlgItem(IDC_BURN)->EnableWindow(FALSE); GetDlgItem(IDC_ERASE)->EnableWindow(FALSE); GetDlgItem(IDC_LOAD)->EnableWindow(FALSE); mcdb.EjectMedium(); GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE); GetDlgItem(IDC_BURN)->EnableWindow(TRUE); GetDlgItem(IDC_ERASE)->EnableWindow(TRUE); GetDlgItem(IDC_LOAD)->EnableWindow(TRUE); DebugOutPut("Eject Done.", this); DebugOutPut("", this); } void CMCDBDlg::OnBurn() { if ( mcdb.TestUnitReady() == FALSE ) { DebugOutPut("Device or Disc is not ready.", this); return; } DebugOutPut("Starting Burn Operation.", this); GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE); GetDlgItem(IDC_BURN)->EnableWindow(FALSE); GetDlgItem(IDC_ERASE)->EnableWindow(FALSE); GetDlgItem(IDC_EJECT)->EnableWindow(FALSE); GetDlgItem(IDC_LOAD)->EnableWindow(FALSE); // TODO: Add your control notification handler code here int i; CString s; WIN32_FIND_DATA FileData; HANDLE hSearch; _TCHAR* c; mcdb.ClearAll(); mcdb.ImportSession(1, "\\"); mcdb.SetVolumeID("BinaryMagics.com"); for (i=0; i < files.GetItemCount();i++) { s = files.GetItemText(i, 1); hSearch = FindFirstFile(s, &FileData); if (hSearch == INVALID_HANDLE_VALUE) { return; } c = (_TCHAR *) (LPCTSTR) s; if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { #ifdef _UNICODE mcdb.InsertDirW(_T("\\"), c, _T("*.*"), TRUE, ((CButton*)GetDlgItem(IDC_SAVEPATH))->GetCheck()==BST_CHECKED?TRUE:FALSE); #else mcdb.InsertDir(_T("\\"), c, _T("*.*"), TRUE, ((CButton*)GetDlgItem(IDC_SAVEPATH))->GetCheck()==BST_CHECKED?TRUE:FALSE); #endif } else if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { #ifdef _UNICODE mcdb.InsertFileW(_T("\\"), c); #else mcdb.InsertFile(_T("\\"), c); #endif } } mcdb.Prepare(); if ( floor( (mcdb.GetImageSize() * 2048) / (1024 * 1024) ) > 128) { MessageBox(_T("Demo does not support burning of data more than 128 MB\n\nFor getting fully functional Magic CD/DVD Burner C++ Library and ActiveX Control, please visit:\n\nhttp://www.binarymagics.com"), _T("Demo Limitation"), MB_ICONINFORMATION | MB_OK); DebugOutPut("Burn Operation Aborted.", this); DebugOutPut("", this); GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE); GetDlgItem(IDC_BURN)->EnableWindow(TRUE); GetDlgItem(IDC_ERASE)->EnableWindow(TRUE); GetDlgItem(IDC_EJECT)->EnableWindow(TRUE); GetDlgItem(IDC_LOAD)->EnableWindow(TRUE); return; } mcdb.Burn(&CMCDBDlg::WriteDone, this); DebugOutPut("Burning Data...", this); } void CMCDBDlg::OnDestroy() { KillTimer(IDC_DLGTIMER); CDialog::OnDestroy(); } void CMCDBDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default switch(nIDEvent) { case IDC_DLGTIMER: double m, w; _TCHAR buf[32]; m = mcdb.GetImageSize(); w = mcdb.GetBlocksWritten(); pb.SetRange32(0, (int) m); pb.SetPos((int) w); _stprintf(buf, _T("%4.2f/%4.2f MB"), (double )((m * 2048)/ 1024 / 1024), (double )((w * 2048) / 1024 / 1024)); GetDlgItem(IDC_LSIZE)->SetWindowText(buf); m = mcdb.GetCacheSize(); w = mcdb.GetCachePosition(); scs.SetRange32(0, (int) m); scs.SetPos((int) w); m = mcdb.GetDeviceBufferSize(); w = mcdb.GetDeviceBufferPosition(); dbs.SetRange32(0, (int) m); dbs.SetPos((int) w); break; } CDialog::OnTimer(nIDEvent); } void CMCDBDlg::OnErase() { DebugOutPut("Starting Erase Operation.", this); GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE); GetDlgItem(IDC_BURN)->EnableWindow(FALSE); GetDlgItem(IDC_ERASE)->EnableWindow(FALSE); GetDlgItem(IDC_EJECT)->EnableWindow(FALSE); GetDlgItem(IDC_LOAD)->EnableWindow(FALSE); // TODO: Add your control notification handler code here if (mcdb.Erasable() == TRUE) { mcdb.EraseDisc(TRUE, &CMCDBDlg::EraseDone, this); DebugOutPut("Quick Erasing Media...", this); } } void __stdcall CMCDBDlg::EraseDone(BOOL FAILED, void *ptr) { ((CMCDBDlg*) ptr)->GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE); ((CMCDBDlg*) ptr)->GetDlgItem(IDC_BURN)->EnableWindow(TRUE); ((CMCDBDlg*) ptr)->GetDlgItem(IDC_ERASE)->EnableWindow(TRUE); ((CMCDBDlg*) ptr)->GetDlgItem(IDC_EJECT)->EnableWindow(TRUE); ((CMCDBDlg*) ptr)->GetDlgItem(IDC_LOAD)->EnableWindow(TRUE); ::DebugOutPut("Erase Operation Complete.", (CMCDBDlg*) ptr); if (FAILED == TRUE) { ::DebugOutPut("Erase Operation Failed.", (CMCDBDlg*) ptr); } ::DebugOutPut("", (CMCDBDlg*) ptr); } void __stdcall CMCDBDlg::WriteDone(BOOL FAILED, void *arg) { ((CMCDBDlg*) arg)->GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE); ((CMCDBDlg*) arg)->GetDlgItem(IDC_BURN)->EnableWindow(TRUE); ((CMCDBDlg*) arg)->GetDlgItem(IDC_ERASE)->EnableWindow(TRUE); ((CMCDBDlg*) arg)->GetDlgItem(IDC_EJECT)->EnableWindow(TRUE); ((CMCDBDlg*) arg)->GetDlgItem(IDC_LOAD)->EnableWindow(TRUE); ::DebugOutPut("Burn Operation Complete.", (CMCDBDlg*) arg); if (FAILED == TRUE) { ::DebugOutPut("Burn Operation Failed.", (CMCDBDlg*) arg); } ::DebugOutPut("", (CMCDBDlg*) arg); } void CMCDBDlg::OnDblclkFiles(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here files.DeleteItem(files.GetHotItem()); *pResult = 0; } void CMCDBDlg::OnLoad() { // TODO: Add your control notification handler code here DebugOutPut("Loading...", this); GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE); GetDlgItem(IDC_BURN)->EnableWindow(FALSE); GetDlgItem(IDC_ERASE)->EnableWindow(FALSE); GetDlgItem(IDC_EJECT)->EnableWindow(FALSE); mcdb.LoadMedium(); long lBlocks = mcdb.GetFreeBlocksOnDisc(); char buffer[20]; _ltoa(lBlocks, buffer, 10); CString strValue = buffer; strValue = strValue + " free blocks on disc."; DebugOutPut(strValue, this); GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE); GetDlgItem(IDC_BURN)->EnableWindow(TRUE); GetDlgItem(IDC_ERASE)->EnableWindow(TRUE); GetDlgItem(IDC_EJECT)->EnableWindow(TRUE); DebugOutPut("Loading Done.", this); DebugOutPut("", this); } void DebugOutPut(CString smsg, CMCDBDlg* ptr) { DWORD dwSel; dwSel = ptr->Memo1.GetSel(); ptr->Memo1.SetSel(HIWORD(dwSel), -1); ptr->Memo1.ReplaceSel(smsg); dwSel = ptr->Memo1.GetSel(); ptr->Memo1.SetSel(HIWORD(dwSel), -1); ptr->Memo1.ReplaceSel(_T("\r\n")); }