home *** CD-ROM | disk | FTP | other *** search
- // iwapitestDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "iwapitest.h"
- #include "iwapitestDlg.h"
- #include "iwapi.hpp"
-
- #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()
-
- /////////////////////////////////////////////////////////////////////////////
- // CIwapitestDlg dialog
-
- CIwapitestDlg::CIwapitestDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CIwapitestDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CIwapitestDlg)
- // 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 CIwapitestDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CIwapitestDlg)
- DDX_Control(pDX, IDC_PROGRESSBAR, m_ProgressBar);
- DDX_Control(pDX, IDC_LVDEVICES, m_DeviceList);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CIwapitestDlg, CDialog)
- //{{AFX_MSG_MAP(CIwapitestDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_INITAPI, OnInitapi)
- ON_BN_CLICKED(IDC_TESTFORMAT, OnTestformat)
- ON_NOTIFY(LVN_ODSTATECHANGED, IDC_LVDEVICES, OnLvdevicesStateChanged)
- ON_NOTIFY(LVN_ITEMCHANGED, IDC_LVDEVICES, OnItemchangedLvdevices)
- ON_BN_CLICKED(IDC_TESTFINALIZE, OnTestfinalize)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CIwapitestDlg message handlers
-
- BOOL CIwapitestDlg::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
-
- m_DeviceList.InsertColumn(0, "Devices", LVCFMT_LEFT, 140, 0);
- m_DeviceList.InsertColumn(1, "Disctyp", LVCFMT_LEFT, 140, 0);
-
-
- m_ProgressBar.SetPos(0);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CIwapitestDlg::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 CIwapitestDlg::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 CIwapitestDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CIwapitestDlg::OnInitapi()
- {
- // Load the API and load the device info
- m_DLLHandle = LoadLibrary("iwsdk.dll");
- if (m_DLLHandle != NULL)
- {
- Initialize = (PInitialize)GetProcAddress(m_DLLHandle, "Initialize");
- DeInitialize = (PDeInitialize)GetProcAddress(m_DLLHandle, "DeInitialize");
- GetDevices = (PGetDevices)GetProcAddress(m_DLLHandle, "GetDevices");
- GetDeviceInfo = (PGetDeviceInfo)GetProcAddress(m_DLLHandle, "GetDeviceInfo");
- FormatDisc = (PFormatDisc)GetProcAddress(m_DLLHandle, "FormatDevice");
- FinalizeDisc= (PFinalizeDisc)GetProcAddress(m_DLLHandle, "FinalizeDevice");
-
- Initialize();
- GetDevices(m_Devices);
- m_DeviceList.DeleteAllItems();
- CString IDString;
- for (unsigned int i=0; i < m_Devices->DriveCount; i++)
- {
- IDString = m_Devices->List[i].ID.FullIDString;
- m_DeviceList.InsertItem(LVIF_TEXT|LVIF_STATE|LVIF_PARAM, i, IDString.Left(28),
- i == 0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, (long)&m_Devices->List[i]);
- }
- }
- }
-
- bool __stdcall FormatProgress(char DriveLetter, int Status, int Percent, DWORD Reference)
- {
- if (Reference)
- {
- CIwapitestDlg *Dialog = reinterpret_cast <CIwapitestDlg*>(Reference);
- Dialog->OnProgress(DriveLetter, Status, Percent);
- }
- return true;
- }
-
- bool __stdcall FinalizeProgress(char DriveLetter, int Status, int Percent, DWORD Reference)
- {
- if (Reference)
- {
- CIwapitestDlg *Dialog = reinterpret_cast <CIwapitestDlg*>(Reference);
- Dialog->OnFinalizeProgress(DriveLetter, Status, Percent);
- }
- return true;
- }
-
-
- bool CIwapitestDlg::OnProgress(char DriveLetter, int Status, int Percent)
- {
- m_ProgressBar.SetPos(Percent);
- if (Status != 0)
- {
- SetDlgItemText(IDC_PROGRESS, "End of Format");
- }
- return true;
- }
-
- bool CIwapitestDlg::OnFinalizeProgress(char DriveLetter, int Status, int Percent)
- {
- m_ProgressBar.SetPos(Percent);
- if (Status != 0)
- {
- SetDlgItemText(IDC_PROGRESS, "End of Format");
- }
- return true;
- }
-
-
- void CIwapitestDlg::OnTestformat()
- {
- CString DiscLabel;
- m_ProgressBar.SetRange(0, 100);
- TFormatSettings Settings;
- Settings.EraseType = etNone;
- Settings.FormatType = ftDataInc;
- Settings.UDFVersion = uv150;
-
- DiscLabel = "TestDisc";
-
- lstrcpyn(Settings.DiscLabel, DiscLabel, 18);
-
- Settings.cbProgress = FormatProgress;
- Settings.Reference = reinterpret_cast<DWORD> (this);
- int i = m_DeviceList.GetSelectionMark();
- if (i >= 0)
- {
- PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);
- FormatDisc(Info->DriveLetter, Settings);
- }
- }
-
- void CIwapitestDlg::OnLvdevicesStateChanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NMLVODSTATECHANGE* pStateChanged = (NMLVODSTATECHANGE*)pNMHDR;
- if (pStateChanged->uNewState & LVIS_SELECTED)
- {
- PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(pStateChanged->iFrom);
- }
- *pResult = 0;
- }
-
- void CIwapitestDlg::OnItemchangedLvdevices(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CString DriveLetter;
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- int i = m_DeviceList.GetSelectionMark();
- if (i >= 0)
- {
- PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);
- DriveLetter = Info->DriveLetter;
- SetDlgItemText(IDC_STATUSTEXT, DriveLetter);
- }
- *pResult = 0;
- }
-
-
- void CIwapitestDlg::OnTestfinalize()
- {
- m_ProgressBar.SetRange(0, 100);
- TFinalizeSettings Settings;
- Settings.cbProgress = FinalizeProgress;
- Settings.Reference = reinterpret_cast<DWORD> (this);
- int i = m_DeviceList.GetSelectionMark();
- if (i >= 0)
- {
- PDeviceInfo Info = (PDeviceInfo)m_DeviceList.GetItemData(i);
- FinalizeDisc(Info->DriveLetter, Settings);
- }
- }
-