home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2001 December / PCpro_2001_12.IMG / cdr / backup / instantbackup / InstantBackupTimedemo.exe / data1.cab / Instant_Write_API / iwapitestDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-05  |  8.2 KB  |  314 lines

  1. // iwapitestDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iwapitest.h"
  6. #include "iwapitestDlg.h"
  7. #include "iwapi.hpp"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CAboutDlg dialog used for App About
  17.  
  18. class CAboutDlg : public CDialog
  19. {
  20. public:
  21.     CAboutDlg();
  22.  
  23. // Dialog Data
  24.     //{{AFX_DATA(CAboutDlg)
  25.     enum { IDD = IDD_ABOUTBOX };
  26.     //}}AFX_DATA
  27.  
  28.     // ClassWizard generated virtual function overrides
  29.     //{{AFX_VIRTUAL(CAboutDlg)
  30.     protected:
  31.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  32.     //}}AFX_VIRTUAL
  33.  
  34. // Implementation
  35. protected:
  36.     //{{AFX_MSG(CAboutDlg)
  37.     //}}AFX_MSG
  38.     DECLARE_MESSAGE_MAP()
  39. };
  40.  
  41. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  42. {
  43.     //{{AFX_DATA_INIT(CAboutDlg)
  44.     //}}AFX_DATA_INIT
  45. }
  46.  
  47. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CAboutDlg)
  51.     //}}AFX_DATA_MAP
  52. }
  53.  
  54. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  55.     //{{AFX_MSG_MAP(CAboutDlg)
  56.         // No message handlers
  57.     //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CIwapitestDlg dialog
  62.  
  63. CIwapitestDlg::CIwapitestDlg(CWnd* pParent /*=NULL*/)
  64.     : CDialog(CIwapitestDlg::IDD, pParent)
  65. {
  66.     //{{AFX_DATA_INIT(CIwapitestDlg)
  67.         // NOTE: the ClassWizard will add member initialization here
  68.     //}}AFX_DATA_INIT
  69.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  70.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  71. }
  72.  
  73. void CIwapitestDlg::DoDataExchange(CDataExchange* pDX)
  74. {
  75.     CDialog::DoDataExchange(pDX);
  76.     //{{AFX_DATA_MAP(CIwapitestDlg)
  77.     DDX_Control(pDX, IDC_PROGRESSBAR, m_ProgressBar);
  78.     DDX_Control(pDX, IDC_LVDEVICES, m_DeviceList);
  79.     //}}AFX_DATA_MAP
  80. }
  81.  
  82. BEGIN_MESSAGE_MAP(CIwapitestDlg, CDialog)
  83.     //{{AFX_MSG_MAP(CIwapitestDlg)
  84.     ON_WM_SYSCOMMAND()
  85.     ON_WM_PAINT()
  86.     ON_WM_QUERYDRAGICON()
  87.     ON_BN_CLICKED(IDC_INITAPI, OnInitapi)
  88.     ON_BN_CLICKED(IDC_TESTFORMAT, OnTestformat)
  89.     ON_NOTIFY(LVN_ODSTATECHANGED, IDC_LVDEVICES, OnLvdevicesStateChanged)
  90.     ON_NOTIFY(LVN_ITEMCHANGED, IDC_LVDEVICES, OnItemchangedLvdevices)
  91.     ON_BN_CLICKED(IDC_TESTFINALIZE, OnTestfinalize)
  92.     //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CIwapitestDlg message handlers
  97.  
  98. BOOL CIwapitestDlg::OnInitDialog()
  99. {
  100.     CDialog::OnInitDialog();
  101.  
  102.     // Add "About..." menu item to system menu.
  103.  
  104.     // IDM_ABOUTBOX must be in the system command range.
  105.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  106.     ASSERT(IDM_ABOUTBOX < 0xF000);
  107.  
  108.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  109.     if (pSysMenu != NULL)
  110.     {
  111.         CString strAboutMenu;
  112.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  113.         if (!strAboutMenu.IsEmpty())
  114.         {
  115.             pSysMenu->AppendMenu(MF_SEPARATOR);
  116.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  117.         }
  118.     }
  119.  
  120.     // Set the icon for this dialog.  The framework does this automatically
  121.     //  when the application's main window is not a dialog
  122.     SetIcon(m_hIcon, TRUE);            // Set big icon
  123.     SetIcon(m_hIcon, FALSE);        // Set small icon
  124.     
  125.     // TODO: Add extra initialization here
  126.     
  127.     m_DeviceList.InsertColumn(0, "Devices", LVCFMT_LEFT, 140, 0);
  128.     m_DeviceList.InsertColumn(1, "Disctyp", LVCFMT_LEFT, 140, 0);
  129.  
  130.  
  131.     m_ProgressBar.SetPos(0);
  132.     
  133.     return TRUE;  // return TRUE  unless you set the focus to a control
  134. }
  135.  
  136. void CIwapitestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  137. {
  138.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  139.     {
  140.         CAboutDlg dlgAbout;
  141.         dlgAbout.DoModal();
  142.     }
  143.     else
  144.     {
  145.         CDialog::OnSysCommand(nID, lParam);
  146.     }
  147. }
  148.  
  149. // If you add a minimize button to your dialog, you will need the code below
  150. //  to draw the icon.  For MFC applications using the document/view model,
  151. //  this is automatically done for you by the framework.
  152.  
  153. void CIwapitestDlg::OnPaint() 
  154. {
  155.     if (IsIconic())
  156.     {
  157.         CPaintDC dc(this); // device context for painting
  158.  
  159.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  160.  
  161.         // Center icon in client rectangle
  162.         int cxIcon = GetSystemMetrics(SM_CXICON);
  163.         int cyIcon = GetSystemMetrics(SM_CYICON);
  164.         CRect rect;
  165.         GetClientRect(&rect);
  166.         int x = (rect.Width() - cxIcon + 1) / 2;
  167.         int y = (rect.Height() - cyIcon + 1) / 2;
  168.  
  169.         // Draw the icon
  170.         dc.DrawIcon(x, y, m_hIcon);
  171.     }
  172.     else
  173.     {
  174.         CDialog::OnPaint();
  175.     }
  176. }
  177.  
  178. // The system calls this to obtain the cursor to display while the user drags
  179. //  the minimized window.
  180. HCURSOR CIwapitestDlg::OnQueryDragIcon()
  181. {
  182.     return (HCURSOR) m_hIcon;
  183. }
  184.  
  185. void CIwapitestDlg::OnInitapi() 
  186. {
  187.     // Load the API and load the device info
  188.     m_DLLHandle = LoadLibrary("iwsdk.dll");
  189.     if (m_DLLHandle != NULL)
  190.     {
  191.         Initialize = (PInitialize)GetProcAddress(m_DLLHandle, "Initialize");
  192.         DeInitialize = (PDeInitialize)GetProcAddress(m_DLLHandle, "DeInitialize");
  193.         GetDevices = (PGetDevices)GetProcAddress(m_DLLHandle, "GetDevices");
  194.         GetDeviceInfo = (PGetDeviceInfo)GetProcAddress(m_DLLHandle, "GetDeviceInfo");
  195.         FormatDisc = (PFormatDisc)GetProcAddress(m_DLLHandle, "FormatDevice");
  196.         FinalizeDisc= (PFinalizeDisc)GetProcAddress(m_DLLHandle, "FinalizeDevice");
  197.  
  198.         Initialize();        
  199.         GetDevices(m_Devices);
  200.         m_DeviceList.DeleteAllItems();
  201.         CString IDString;
  202.         for (unsigned int i=0; i < m_Devices->DriveCount; i++)
  203.         {
  204.            IDString = m_Devices->List[i].ID.FullIDString;
  205.            m_DeviceList.InsertItem(LVIF_TEXT|LVIF_STATE|LVIF_PARAM, i, IDString.Left(28), 
  206.                 i == 0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, (long)&m_Devices->List[i]);                      
  207.         }
  208.     }
  209. }
  210.  
  211. bool __stdcall FormatProgress(char DriveLetter, int Status, int Percent, DWORD Reference)
  212. {
  213.   if (Reference)
  214.   {
  215.     CIwapitestDlg *Dialog = reinterpret_cast <CIwapitestDlg*>(Reference);
  216.     Dialog->OnProgress(DriveLetter, Status, Percent);
  217.   }
  218.   return true;
  219. }
  220.  
  221. bool __stdcall FinalizeProgress(char DriveLetter, int Status, int Percent, DWORD Reference)
  222. {
  223.   if (Reference)
  224.   {
  225.     CIwapitestDlg *Dialog = reinterpret_cast <CIwapitestDlg*>(Reference);
  226.      Dialog->OnFinalizeProgress(DriveLetter, Status, Percent);
  227.   }
  228.   return true;
  229. }
  230.  
  231.  
  232. bool CIwapitestDlg::OnProgress(char DriveLetter, int Status, int Percent)
  233. {  
  234.   m_ProgressBar.SetPos(Percent);
  235.   if (Status != 0)
  236.   {
  237.      SetDlgItemText(IDC_PROGRESS, "End of Format");
  238.   }
  239.   return true;
  240. }
  241.  
  242. bool CIwapitestDlg::OnFinalizeProgress(char DriveLetter, int Status, int Percent)
  243. {  
  244.   m_ProgressBar.SetPos(Percent);
  245.   if (Status != 0)
  246.   {
  247.      SetDlgItemText(IDC_PROGRESS, "End of Format");
  248.   }
  249.   return true;
  250. }
  251.  
  252.  
  253. void CIwapitestDlg::OnTestformat() 
  254. {
  255.    CString DiscLabel;
  256.    m_ProgressBar.SetRange(0, 100);
  257.    TFormatSettings Settings;
  258.    Settings.EraseType = etNone;   
  259.    Settings.FormatType = ftDataInc;
  260.    Settings.UDFVersion = uv150;
  261.    
  262.    DiscLabel = "TestDisc";
  263.  
  264.    lstrcpyn(Settings.DiscLabel, DiscLabel, 18); 
  265.  
  266.    Settings.cbProgress = FormatProgress;
  267.    Settings.Reference = reinterpret_cast<DWORD> (this);
  268.    int i = m_DeviceList.GetSelectionMark();
  269.    if (i >= 0)
  270.    {
  271.       PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);      
  272.       FormatDisc(Info->DriveLetter, Settings);
  273.    }
  274. }
  275.  
  276. void CIwapitestDlg::OnLvdevicesStateChanged(NMHDR* pNMHDR, LRESULT* pResult) 
  277. {
  278.     NMLVODSTATECHANGE* pStateChanged = (NMLVODSTATECHANGE*)pNMHDR;
  279.     if (pStateChanged->uNewState & LVIS_SELECTED)
  280.     {
  281.         PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(pStateChanged->iFrom);
  282.     }
  283.     *pResult = 0;
  284. }
  285.  
  286. void CIwapitestDlg::OnItemchangedLvdevices(NMHDR* pNMHDR, LRESULT* pResult) 
  287. {
  288.     CString DriveLetter;
  289.     NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  290.     int i = m_DeviceList.GetSelectionMark();
  291.     if (i >= 0)
  292.     {
  293.       PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);
  294.       DriveLetter = Info->DriveLetter;
  295.       SetDlgItemText(IDC_STATUSTEXT, DriveLetter);
  296.     }
  297.     *pResult = 0;
  298. }
  299.  
  300.  
  301. void CIwapitestDlg::OnTestfinalize() 
  302. {
  303.    m_ProgressBar.SetRange(0, 100);    
  304.    TFinalizeSettings Settings;
  305.    Settings.cbProgress = FinalizeProgress;
  306.    Settings.Reference = reinterpret_cast<DWORD> (this);
  307.    int i = m_DeviceList.GetSelectionMark();
  308.    if (i >= 0)
  309.    {
  310.       PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);      
  311.       FinalizeDisc(Info->DriveLetter, Settings);
  312.    }
  313. }
  314.