home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Programare / magiccd / mcdbc111t.exe / %MAINDIR% / MFC / MCDBDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-03-08  |  12.8 KB  |  479 lines

  1. // MCDBDlg.cpp : implementation file
  2. //
  3.  
  4. #include "StdAfx.h"
  5. #include "MCDB.h"
  6. #include "MCDBDlg.h"
  7. #include "..\..\include\MCDBCls.h"
  8. #include <math.h>
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CAboutDlg dialog used for App About
  18.  
  19. class CAboutDlg : public CDialog
  20. {
  21. public:
  22.     CAboutDlg();
  23.  
  24. // Dialog Data
  25.     //{{AFX_DATA(CAboutDlg)
  26.     enum { IDD = IDD_ABOUTBOX };
  27.     //}}AFX_DATA
  28.  
  29.     // ClassWizard generated virtual function overrides
  30.     //{{AFX_VIRTUAL(CAboutDlg)
  31.     protected:
  32.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  33.     //}}AFX_VIRTUAL
  34.  
  35. // Implementation
  36. protected:
  37.     //{{AFX_MSG(CAboutDlg)
  38.     //}}AFX_MSG
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  43. {
  44.     //{{AFX_DATA_INIT(CAboutDlg)
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CAboutDlg)
  52.     //}}AFX_DATA_MAP
  53. }
  54.  
  55. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  56.     //{{AFX_MSG_MAP(CAboutDlg)
  57.         // No message handlers
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMCDBDlg dialog
  65.  
  66. CMCDBurner mcdb;
  67. void DebugOutPut(CString smsg, CMCDBDlg* ptr);
  68.  
  69.  
  70. CMCDBDlg::CMCDBDlg(CWnd* pParent /*=NULL*/)
  71.     : CDialog(CMCDBDlg::IDD, pParent)
  72. {
  73.     //{{AFX_DATA_INIT(CMCDBDlg)
  74.         // NOTE: the ClassWizard will add member initialization here
  75.     //}}AFX_DATA_INIT
  76.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  77.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  78. }
  79.  
  80. void CMCDBDlg::DoDataExchange(CDataExchange* pDX)
  81. {
  82.     CDialog::DoDataExchange(pDX);
  83.     //{{AFX_DATA_MAP(CMCDBDlg)
  84.     DDX_Control(pDX, IDC_MEMO, Memo1);
  85.     DDX_Control(pDX, IDC_DBS, dbs);
  86.     DDX_Control(pDX, IDC_SCS, scs);
  87.     DDX_Control(pDX, IDC_PB, pb);
  88.     DDX_Control(pDX, IDC_FILES, files);
  89.     DDX_Control(pDX, IDC_COMBO2, cbDrives);
  90.     //}}AFX_DATA_MAP
  91. }
  92.  
  93. BEGIN_MESSAGE_MAP(CMCDBDlg, CDialog)
  94.     //{{AFX_MSG_MAP(CMCDBDlg)
  95.     ON_WM_SYSCOMMAND()
  96.     ON_WM_PAINT()
  97.     ON_WM_QUERYDRAGICON()
  98.     ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
  99.     ON_BN_CLICKED(IDC_EJECT, OnEject)
  100.     ON_BN_CLICKED(IDC_BURN, OnBurn)
  101.     ON_WM_DESTROY()
  102.     ON_WM_TIMER()
  103.     ON_BN_CLICKED(IDC_ERASE, OnErase)
  104.     ON_BN_CLICKED(IDC_LOAD, OnLoad)
  105.     ON_NOTIFY(NM_DBLCLK, IDC_FILES, OnDblclkFiles)
  106.     //}}AFX_MSG_MAP
  107. END_MESSAGE_MAP()
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMCDBDlg message handlers
  111. BOOL CMCDBDlg::OnInitDialog()
  112. {
  113.     CDialog::OnInitDialog();
  114.  
  115.     // Add "About..." menu item to system menu.
  116.  
  117.     // IDM_ABOUTBOX must be in the system command range.
  118.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  119.     ASSERT(IDM_ABOUTBOX < 0xF000);
  120.  
  121.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  122.     if (pSysMenu != NULL)
  123.     {
  124.         CString strAboutMenu;
  125.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  126.         if (!strAboutMenu.IsEmpty())
  127.         {
  128.             pSysMenu->AppendMenu(MF_SEPARATOR);
  129.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  130.         }
  131.     }
  132.  
  133.     // Set the icon for this dialog.  The framework does this automatically
  134.     //  when the application's main window is not a dialog
  135.     SetIcon(m_hIcon, TRUE);            // Set big icon
  136.     SetIcon(m_hIcon, FALSE);        // Set small icon
  137.     
  138.     // TODO: Add extra initialization here
  139.     int i;
  140.     CString sDrive;
  141.     _TCHAR* cDrive;
  142.     for (i=0; i < mcdb.GetDeviceCount(); i++)
  143.     {
  144.         sDrive = mcdb.GetDeviceName(i);
  145.         cDrive = (_TCHAR *) (LPCTSTR) sDrive;
  146.  
  147.         cbDrives.InsertString(cbDrives.GetCount(), cDrive);
  148.     }
  149.  
  150.     if (cbDrives.GetCount() != 0)
  151.     {
  152.         cbDrives.SetCurSel(0);
  153.     }
  154.  
  155.     OnSelchangeCombo2();
  156.  
  157.     files.SetExtendedStyle(LVS_EX_CHECKBOXES |  LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
  158.                            LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_TRACKSELECT);
  159.  
  160.     LV_COLUMN lvColumn;
  161.     lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  162.     lvColumn.fmt = LVCFMT_LEFT;
  163.     lvColumn.cx = 25;
  164.     lvColumn.iSubItem = 0;
  165.     lvColumn.pszText = _T("R");
  166.     files.InsertColumn(0, &lvColumn);
  167.     lvColumn.cx = 300;
  168.     lvColumn.iSubItem = 1;
  169.     lvColumn.pszText = _T("File Name");
  170.     files.InsertColumn(1, &lvColumn);
  171.  
  172.     UINT dropMode;
  173.     dropMode = CFileDropListCtrl::DL_ACCEPT_FILES | CFileDropListCtrl::DL_ACCEPT_FOLDERS;
  174.     files.SetDropMode(dropMode);
  175.  
  176.     SetTimer(IDC_DLGTIMER, 100, NULL);
  177.     
  178. #ifdef _UNICODE
  179.     DebugOutPut("This is a demo application of Magic CD/DVD Burner C/C++ (UNICODE) Library.", this);
  180. #else
  181.     DebugOutPut("This is a demo application of Magic CD/DVD Burner C/C++ Library.", this);
  182. #endif    
  183.     DebugOutPut("For further information/queries, please visit: http://www.binarymagics.com", this);
  184.     
  185.     DebugOutPut("", this);
  186.     DebugOutPut("- Drag files/directories from Windows Explorer and drop into listbox.", this);
  187.     DebugOutPut("- Double click on an entry in listbox to delete it.", this);
  188.         
  189.     
  190.     return TRUE;  // return TRUE  unless you set the focus to a control
  191. }
  192.  
  193. void CMCDBDlg::OnSysCommand(UINT nID, LPARAM lParam)
  194. {
  195.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  196.     {
  197.         CAboutDlg dlgAbout;
  198.         dlgAbout.DoModal();
  199.     }
  200.     else
  201.     {
  202.         CDialog::OnSysCommand(nID, lParam);
  203.     }
  204. }
  205.  
  206. // If you add a minimize button to your dialog, you will need the code below
  207. //  to draw the icon.  For MFC applications using the document/view model,
  208. //  this is automatically done for you by the framework.
  209.  
  210. void CMCDBDlg::OnPaint() 
  211. {
  212.     if (IsIconic())
  213.     {
  214.         CPaintDC dc(this); // device context for painting
  215.  
  216.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  217.  
  218.         // Center icon in client rectangle
  219.         int cxIcon = GetSystemMetrics(SM_CXICON);
  220.         int cyIcon = GetSystemMetrics(SM_CYICON);
  221.         CRect rect;
  222.         GetClientRect(&rect);
  223.         int x = (rect.Width() - cxIcon + 1) / 2;
  224.         int y = (rect.Height() - cyIcon + 1) / 2;
  225.  
  226.         // Draw the icon
  227.         dc.DrawIcon(x, y, m_hIcon);
  228.     }
  229.     else
  230.     {
  231.         CDialog::OnPaint();
  232.     }
  233. }
  234.  
  235. // The system calls this to obtain the cursor to display while the user drags
  236. //  the minimized window.
  237. HCURSOR CMCDBDlg::OnQueryDragIcon()
  238. {
  239.     return (HCURSOR) m_hIcon;
  240. }
  241.  
  242. void CMCDBDlg::OnSelchangeCombo2()
  243. {
  244.     // TODO: Add your control notification handler code here
  245.     mcdb.SelectDevice(cbDrives.GetCurSel());
  246.     if (mcdb.DeviceIsBurner())
  247.     {
  248.         GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  249.     }
  250.     else
  251.     {
  252.         GetDlgItem(IDC_BURN)->EnableWindow(FALSE);
  253.     }
  254. }
  255.  
  256. void CMCDBDlg::OnEject() 
  257. {
  258.     // TODO: Add your control notification handler code here
  259.     DebugOutPut("Ejecting...", this);
  260.  
  261.     GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE);
  262.     GetDlgItem(IDC_BURN)->EnableWindow(FALSE);
  263.     GetDlgItem(IDC_ERASE)->EnableWindow(FALSE);
  264.     GetDlgItem(IDC_LOAD)->EnableWindow(FALSE);
  265.     mcdb.EjectMedium();
  266.     GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE);
  267.     GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  268.     GetDlgItem(IDC_ERASE)->EnableWindow(TRUE);
  269.     GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
  270.  
  271.     DebugOutPut("Eject Done.", this);
  272.     DebugOutPut("", this);
  273. }
  274.  
  275. void CMCDBDlg::OnBurn() 
  276. {
  277.     if ( mcdb.TestUnitReady() == FALSE )
  278.     {
  279.         DebugOutPut("Device or Disc is not ready.", this);
  280.         return;
  281.     }
  282.  
  283.     DebugOutPut("Starting Burn Operation.", this);
  284.     GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE);
  285.     GetDlgItem(IDC_BURN)->EnableWindow(FALSE);
  286.     GetDlgItem(IDC_ERASE)->EnableWindow(FALSE);
  287.     GetDlgItem(IDC_EJECT)->EnableWindow(FALSE);
  288.     GetDlgItem(IDC_LOAD)->EnableWindow(FALSE);
  289.     // TODO: Add your control notification handler code here
  290.     int i;
  291.     CString s;
  292.     WIN32_FIND_DATA FileData;
  293.     HANDLE hSearch;
  294.     _TCHAR* c;
  295.  
  296.     mcdb.ClearAll();
  297.     mcdb.ImportSession(1, "\\");
  298.     mcdb.SetVolumeID("BinaryMagics.com");
  299.     for (i=0; i < files.GetItemCount();i++)
  300.     {
  301.         s = files.GetItemText(i, 1);
  302.  
  303.         hSearch = FindFirstFile(s, &FileData);
  304.         if (hSearch == INVALID_HANDLE_VALUE)
  305.         {
  306.             return;
  307.         }
  308.  
  309.         c = (_TCHAR *) (LPCTSTR) s;
  310.         
  311.         if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  312.         {
  313. #ifdef _UNICODE
  314.             mcdb.InsertDirW(_T("\\"), c, _T("*.*"), TRUE, ((CButton*)GetDlgItem(IDC_SAVEPATH))->GetCheck()==BST_CHECKED?TRUE:FALSE);
  315. #else
  316.             mcdb.InsertDir(_T("\\"), c, _T("*.*"), TRUE, ((CButton*)GetDlgItem(IDC_SAVEPATH))->GetCheck()==BST_CHECKED?TRUE:FALSE);
  317. #endif
  318.         }
  319.         else if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  320.         {
  321. #ifdef _UNICODE
  322.             mcdb.InsertFileW(_T("\\"), c);
  323. #else
  324.             mcdb.InsertFile(_T("\\"), c);
  325. #endif
  326.         }
  327.     }
  328.  
  329.     mcdb.Prepare();
  330.  
  331.     if ( floor( (mcdb.GetImageSize() * 2048) / (1024 * 1024) ) > 128)
  332.     {
  333.         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);
  334.         DebugOutPut("Burn Operation Aborted.", this);
  335.         DebugOutPut("", this);
  336.         GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE);
  337.         GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  338.         GetDlgItem(IDC_ERASE)->EnableWindow(TRUE);
  339.         GetDlgItem(IDC_EJECT)->EnableWindow(TRUE);
  340.         GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
  341.         return;
  342.     }
  343.  
  344.     mcdb.Burn(&CMCDBDlg::WriteDone, this);
  345.     DebugOutPut("Burning Data...", this);
  346. }
  347.  
  348. void CMCDBDlg::OnDestroy() 
  349. {
  350.     KillTimer(IDC_DLGTIMER);
  351.     CDialog::OnDestroy();
  352. }
  353.  
  354. void CMCDBDlg::OnTimer(UINT nIDEvent) 
  355. {
  356.     // TODO: Add your message handler code here and/or call default
  357.     switch(nIDEvent)
  358.     {
  359.         case IDC_DLGTIMER:
  360.             double m, w;
  361.             _TCHAR buf[32];
  362.             
  363.             m = mcdb.GetImageSize();
  364.             w = mcdb.GetBlocksWritten();
  365.  
  366.             pb.SetRange32(0, (int) m);
  367.             pb.SetPos((int) w);
  368.  
  369.             _stprintf(buf, _T("%4.2f/%4.2f MB"), (double )((m * 2048)/ 1024 / 1024), (double )((w * 2048) / 1024 / 1024));
  370.             GetDlgItem(IDC_LSIZE)->SetWindowText(buf);
  371.             m = mcdb.GetCacheSize();
  372.             w = mcdb.GetCachePosition();
  373.             scs.SetRange32(0, (int) m);
  374.             scs.SetPos((int) w);
  375.             m = mcdb.GetDeviceBufferSize();
  376.             w = mcdb.GetDeviceBufferPosition();
  377.             dbs.SetRange32(0, (int) m);
  378.             dbs.SetPos((int) w);
  379.             
  380.             break;
  381.     }
  382.  
  383.     CDialog::OnTimer(nIDEvent);
  384. }
  385.  
  386. void CMCDBDlg::OnErase() 
  387. {
  388.     DebugOutPut("Starting Erase Operation.", this);
  389.     GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE);
  390.     GetDlgItem(IDC_BURN)->EnableWindow(FALSE);
  391.     GetDlgItem(IDC_ERASE)->EnableWindow(FALSE);
  392.     GetDlgItem(IDC_EJECT)->EnableWindow(FALSE);
  393.     GetDlgItem(IDC_LOAD)->EnableWindow(FALSE);
  394.     // TODO: Add your control notification handler code here
  395.     if (mcdb.Erasable() == TRUE)
  396.     {
  397.         mcdb.EraseDisc(TRUE, &CMCDBDlg::EraseDone, this);
  398.         DebugOutPut("Quick Erasing Media...", this);
  399.     }
  400. }
  401.  
  402. void __stdcall CMCDBDlg::EraseDone(BOOL FAILED, void *ptr)
  403. {
  404.     ((CMCDBDlg*) ptr)->GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE);
  405.     ((CMCDBDlg*) ptr)->GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  406.     ((CMCDBDlg*) ptr)->GetDlgItem(IDC_ERASE)->EnableWindow(TRUE);
  407.     ((CMCDBDlg*) ptr)->GetDlgItem(IDC_EJECT)->EnableWindow(TRUE);
  408.     ((CMCDBDlg*) ptr)->GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
  409.     ::DebugOutPut("Erase Operation Complete.", (CMCDBDlg*) ptr);
  410.     if (FAILED == TRUE)
  411.     {
  412.         ::DebugOutPut("Erase Operation Failed.", (CMCDBDlg*) ptr);
  413.     }
  414.     ::DebugOutPut("", (CMCDBDlg*) ptr);
  415. }
  416.  
  417. void __stdcall CMCDBDlg::WriteDone(BOOL FAILED, void *arg)
  418. {
  419.     ((CMCDBDlg*) arg)->GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE);
  420.     ((CMCDBDlg*) arg)->GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  421.     ((CMCDBDlg*) arg)->GetDlgItem(IDC_ERASE)->EnableWindow(TRUE);
  422.     ((CMCDBDlg*) arg)->GetDlgItem(IDC_EJECT)->EnableWindow(TRUE);
  423.     ((CMCDBDlg*) arg)->GetDlgItem(IDC_LOAD)->EnableWindow(TRUE);
  424.     ::DebugOutPut("Burn Operation Complete.", (CMCDBDlg*) arg);
  425.     if (FAILED == TRUE)
  426.     {
  427.         ::DebugOutPut("Burn Operation Failed.", (CMCDBDlg*) arg);
  428.     }
  429.     ::DebugOutPut("", (CMCDBDlg*) arg);
  430. }
  431.  
  432. void CMCDBDlg::OnDblclkFiles(NMHDR* pNMHDR, LRESULT* pResult) 
  433. {
  434.     // TODO: Add your control notification handler code here
  435.     files.DeleteItem(files.GetHotItem());
  436.     
  437.     *pResult = 0;
  438. }
  439.  
  440. void CMCDBDlg::OnLoad()
  441. {
  442.     // TODO: Add your control notification handler code here
  443.     DebugOutPut("Loading...", this);
  444.     GetDlgItem(IDC_DRIVES)->EnableWindow(FALSE);
  445.     GetDlgItem(IDC_BURN)->EnableWindow(FALSE);
  446.     GetDlgItem(IDC_ERASE)->EnableWindow(FALSE);
  447.     GetDlgItem(IDC_EJECT)->EnableWindow(FALSE);
  448.  
  449.     mcdb.LoadMedium();
  450.  
  451.     long lBlocks = mcdb.GetFreeBlocksOnDisc();
  452.     char buffer[20];
  453.     _ltoa(lBlocks, buffer, 10);
  454.     CString strValue = buffer;
  455.     strValue = strValue + " free blocks on disc.";
  456.     DebugOutPut(strValue, this);
  457.  
  458.     GetDlgItem(IDC_DRIVES)->EnableWindow(TRUE);
  459.     GetDlgItem(IDC_BURN)->EnableWindow(TRUE);
  460.     GetDlgItem(IDC_ERASE)->EnableWindow(TRUE);
  461.     GetDlgItem(IDC_EJECT)->EnableWindow(TRUE);
  462.  
  463.     DebugOutPut("Loading Done.", this);
  464.     DebugOutPut("", this);
  465. }
  466.  
  467. void DebugOutPut(CString smsg, CMCDBDlg* ptr)
  468. {
  469.     DWORD dwSel;
  470.     
  471.     dwSel = ptr->Memo1.GetSel();
  472.     ptr->Memo1.SetSel(HIWORD(dwSel), -1);
  473.     ptr->Memo1.ReplaceSel(smsg);
  474.  
  475.     dwSel = ptr->Memo1.GetSel();
  476.     ptr->Memo1.SetSel(HIWORD(dwSel), -1);
  477.     ptr->Memo1.ReplaceSel(_T("\r\n"));
  478. }
  479.