Dlg.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* NeroSDK / NeroCBUI
  10. |*
  11. |* PROGRAM: TestNeroCBUI
  12. |*
  13. |* PURPOSE: Sample application for the use of NeroCBUI
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "TestNeroCBUI.h"
  17. #include "Dlg.h"
  18. #include "BurnDlg.h"
  19. #include "PropertyPageBurnSettings.h"
  20. #include "PropertyPageImageInfo.h"
  21. #include "TestNeroCBUI.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CDlg dialog
  29. CDlg::CDlg(CWnd* pParent /*=NULL*/)
  30. : CDialog(CDlg::IDD, pParent)
  31. {
  32. //{{AFX_DATA_INIT(CDlg)
  33. //}}AFX_DATA_INIT
  34. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  35. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  36. m_pRoboInfos = NULL;
  37. /** This should be not possible yet. */
  38. if(SUCCEEDED(m_pRoboInfos.CoCreateInstance(__uuidof(RoboInfos))))
  39. {
  40. ASSERT(FALSE);
  41. m_pRoboInfos = NULL;
  42. }
  43. }
  44. CDlg::~CDlg ()
  45. {
  46. m_pRoboInfos = NULL;
  47. }
  48. void CDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CDlg)
  52. DDX_Control(pDX, IDC_BURN_WIZARD_MODE, c_WizardMode);
  53. DDX_Control(pDX, IDC_MEDIA_COMBO, m_MediaCombo);
  54. DDX_Control(pDX, IDC_MODAL_ERASE_DISC, c_ModalEraseDisc);
  55. DDX_Control(pDX, IDC_LANG_COMBO, m_Combo);
  56. DDX_Control(pDX, IDC_TEST_ERASE_DISC, c_TestEraseDisc);
  57. DDX_Control(pDX, IDC_TEST_DISC_INFO, c_TestDiscInfo);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CDlg, CDialog)
  61. //{{AFX_MSG_MAP(CDlg)
  62. ON_WM_PAINT()
  63. ON_WM_QUERYDRAGICON()
  64. ON_BN_CLICKED(IDC_TEST_ERASE_DISC, OnTestEraseDisc)
  65. ON_BN_CLICKED(IDC_TEST_DISC_INFO, OnTestDiscInfo)
  66. ON_WM_DESTROY()
  67. ON_BN_CLICKED(IDC_TEST_BURN_SETTINGS, OnTestBurnSettings)
  68. ON_BN_CLICKED(IDC_TEST_BURN_SETTINGS_OLE, OnTestBurnSettingsOle)
  69. ON_BN_CLICKED(IDC_TEST_BURN_PROGRESS, OnTestBurnProgress)
  70. ON_BN_CLICKED(IDC_TEST_IMAGE_INFO, OnTestImageInfo)
  71. ON_BN_CLICKED(IDC_TEST_CHOOSE_RECORDER, OnTestChooseRecorder)
  72. ON_BN_CLICKED(IDC_TEST_CHOOSE_SESSION, OnTestChooseSession)
  73. ON_CBN_SELCHANGE(IDC_LANG_COMBO, OnSelchangeLangCombo)
  74. ON_BN_CLICKED(IDC_TEST_ERASE_DISC_MODELESS, OnTestEraseDiscModeless)
  75. ON_BN_CLICKED(IDC_TEST_WAIT_FOR_MEDIA, OnTestWaitForMedia)
  76. ON_CBN_SELCHANGE(IDC_MEDIA_COMBO, OnSelchangeMediaCombo)
  77. ON_CBN_SELCHANGE(IDC_RECORDER, OnSelchangeRecorder)
  78. ON_BN_CLICKED(IDC_TEST_IMAGE_INFO_OLE, OnTestImageInfoOle)
  79. ON_BN_CLICKED(IDC_TEST_CONFIGURE_ROBOT, OnTestConfigureRobot)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CDlg message handlers
  84. BOOL CDlg::OnInitDialog()
  85. {
  86. CDialog::OnInitDialog();
  87. // Set the icon for this dialog. The framework does this automatically
  88. // when the application's main window is not a dialog
  89. SetIcon(m_hIcon, TRUE); // Set big icon
  90. SetIcon(m_hIcon, FALSE); // Set small icon
  91. BOOL bSuccess = FALSE;
  92. if (SUCCEEDED (m_pRecorderCombobox.CoCreateInstance (__uuidof (RecorderCombobox))))
  93. {
  94. CComQIPtr<IChildWindow> pChildWindow (m_pRecorderCombobox);
  95. CComBSTR bstr ("Custom append item");
  96. m_pRecorderCombobox->AppendCustomEntry (m_hIcon, bstr, (void *) 1);
  97. bstr = "Custom prepend item";
  98. m_pRecorderCombobox->PrependCustomEntry (m_hIcon, bstr, (void *) 1);
  99. if (pChildWindow)
  100. {
  101. pChildWindow.p->Subclass (GetDlgItem (IDC_RECORDER)->m_hWnd, &bSuccess);
  102. }
  103. // set this object as callback receiver
  104. m_pRecorderCombobox.p->put_Callbacks(this);
  105. }
  106. if (bSuccess && SUCCEEDED (m_pWriteSpeedCombobox.CoCreateInstance (__uuidof (SpeedCombobox))))
  107. {
  108. // set the default media type
  109. m_pWriteSpeedCombobox.p->put_MediaType(MEDIA_CD);
  110. m_pWriteSpeedCombobox->put_HideWhenEmpty (FALSE);
  111. CComQIPtr<IChildWindow> pChildWindow (m_pWriteSpeedCombobox);
  112. if (pChildWindow)
  113. {
  114. pChildWindow.p->Subclass (GetDlgItem (IDC_WRITESPEEDS)->m_hWnd, &bSuccess);
  115. }
  116. }
  117. BOOL bEnable = bSuccess && ((CApp*)AfxGetApp)->m_bNeroAPIInitOk;
  118. c_TestDiscInfo.EnableWindow (bEnable);
  119. c_TestEraseDisc.EnableWindow (bEnable);
  120. c_ModalEraseDisc.SetCheck (1);
  121. c_WizardMode.SetCheck (1);
  122. m_MediaCombo.SetCurSel(0);
  123. return TRUE; // return TRUE unless you set the focus to a control
  124. }
  125. // If you add a minimize button to your dialog, you will need the code below
  126. // to draw the icon. For MFC applications using the document/view model,
  127. // this is automatically done for you by the framework.
  128. void CDlg::OnPaint()
  129. {
  130. if (IsIconic())
  131. {
  132. CPaintDC dc(this); // device context for painting
  133. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  134. // Center icon in client rectangle
  135. int cxIcon = GetSystemMetrics(SM_CXICON);
  136. int cyIcon = GetSystemMetrics(SM_CYICON);
  137. CRect rect;
  138. GetClientRect(&rect);
  139. int x = (rect.Width() - cxIcon + 1) / 2;
  140. int y = (rect.Height() - cyIcon + 1) / 2;
  141. // Draw the icon
  142. dc.DrawIcon(x, y, m_hIcon);
  143. }
  144. else
  145. {
  146. CDialog::OnPaint();
  147. }
  148. }
  149. // The system calls this to obtain the cursor to display while the user drags
  150. // the minimized window.
  151. HCURSOR CDlg::OnQueryDragIcon()
  152. {
  153. return (HCURSOR) m_hIcon;
  154. }
  155. void CDlg::OnTestEraseDisc()
  156. {
  157. NEROAPI_CDRW_ERASE_MODE mode = NEROAPI_ERASE_QUICK;
  158. // Declare a smart pointer to INERO_SCSI_DEVICE_INFO interface. Create
  159. // an instance of DiscInfoDlg class.
  160. //
  161. CComPtr<INERO_SCSI_DEVICE_INFO> pNSDI;
  162. if (SUCCEEDED (pNSDI.CoCreateInstance (__uuidof (EraseSettingsDlg))))
  163. {
  164. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  165. ATLASSERT (pRecorderNSDI);
  166. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  167. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  168. pNSDI->put_NERO_SCSI_DEVICE_INFO ( pDeviceInfo );
  169. CComQIPtr<IEraseSettingsDlg> pEraseSettingsDlg (pNSDI);
  170. ATLASSERT (pEraseSettingsDlg.p != NULL);
  171. bool bModelessErase = c_ModalEraseDisc.GetCheck () == 0;
  172. pEraseSettingsDlg->put_ModelessErase (bModelessErase);
  173. if (bModelessErase)
  174. {
  175. pEraseSettingsDlg->put_Callbacks (this);
  176. }
  177. // Declare a smart pointer to IModalDialog interface and call its
  178. // DoModal method.
  179. //
  180. CComPtr<IModalDialog> pModalDialog;
  181. int iRet = 0;
  182. if(SUCCEEDED(pNSDI.QueryInterface(&pModalDialog)))
  183. pModalDialog->DoModal (m_hWnd, &iRet);
  184. if (!bModelessErase)
  185. {
  186. // Display different information depending on the return value.
  187. //
  188. switch (iRet)
  189. {
  190. case IDOK:
  191. {
  192. CString str, sDevice;
  193. NERO_SCSI_DEVICE_INFO * pDeviceInfo;
  194. // Get the last current selection in the recorder combobox.
  195. //
  196. pNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  197. sDevice.Format ("Selected device was \"%s\".", (pDeviceInfo != NULL && pDeviceInfo->nsdiDeviceName[0] != '\0')? pDeviceInfo->nsdiDeviceName: "[no device selected]");
  198. str.Format ("%s\nUser selected OK and erase process completed successfully!", sDevice);
  199. AfxMessageBox (str);
  200. }
  201. break;
  202. case IDCANCEL:
  203. AfxMessageBox ("The dialog was canceled!");
  204. break;
  205. default:
  206. {
  207. CString str;
  208. str.Format ("There was an error displaying the dialog box!");
  209. AfxMessageBox (str);
  210. }
  211. }
  212. }
  213. else
  214. {
  215. CComQIPtr<IEraseSettingsDlg2> pEraseSettingsDlg2 (pNSDI);
  216. if(pEraseSettingsDlg2.p)
  217. {
  218. HWND hWndDlg;
  219. pEraseSettingsDlg2->get_ModelessDlgHWND(&hWndDlg);
  220. ATLASSERT(hWndDlg);
  221. /*
  222. if(hWndDlg)
  223. VERIFY(::CloseWindow(hWndDlg));
  224. */
  225. }
  226. }
  227. }
  228. }
  229. void CDlg::OnTestDiscInfo()
  230. {
  231. // Declare a smart pointer to INERO_SCSI_DEVICE_INFO interface. Create
  232. // an instance of DiscInfoDlg class.
  233. //
  234. CComPtr<INERO_SCSI_DEVICE_INFO> pNSDI;
  235. if (SUCCEEDED (pNSDI.CoCreateInstance (__uuidof (DiscInfoDlg))))
  236. {
  237. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  238. ATLASSERT (pRecorderNSDI);
  239. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  240. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  241. pNSDI->put_NERO_SCSI_DEVICE_INFO ( pDeviceInfo );
  242. // Declare a smart pointer to IModalDialog interface and call its
  243. // DoModal method.
  244. //
  245. CComPtr<IModalDialog> pModalDialog;
  246. int iRet = 0;
  247. if(SUCCEEDED(pNSDI->QueryInterface(&pModalDialog)))
  248. pModalDialog->DoModal (m_hWnd,&iRet);
  249. // Display different information depending on the return value.
  250. //
  251. switch (iRet)
  252. {
  253. case IDOK:
  254. {
  255. CString str, sDevice;
  256. NERO_SCSI_DEVICE_INFO * pDeviceInfo;
  257. // Get the last current selection in the recorder combobox.
  258. //
  259. pNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  260. sDevice.Format ("%s", (pDeviceInfo != NULL && pDeviceInfo->nsdiDeviceName[0] != '\0')? pDeviceInfo->nsdiDeviceName: "[no device selected]");
  261. str.Format ("Everything was fine.\nThe user's last selection was \"%s\".", sDevice);
  262. AfxMessageBox (str);
  263. }
  264. break;
  265. case IDCANCEL:
  266. AfxMessageBox ("The dialog was canceled!");
  267. break;
  268. default:
  269. {
  270. CString str;
  271. str.Format ("There was an error displaying the dialog box!");
  272. AfxMessageBox (str);
  273. }
  274. }
  275. }
  276. }
  277. void CDlg::OnDestroy()
  278. {
  279. CDialog::OnDestroy();
  280. m_pRecorderCombobox = NULL;
  281. m_pWriteSpeedCombobox = NULL;
  282. }
  283. void CDlg::OnTestBurnSettings()
  284. {
  285. CComPtr<IBurnSettings> pBurnSettings;
  286. if (SUCCEEDED (pBurnSettings.CoCreateInstance (__uuidof (BurnSettings))))
  287. {
  288. pBurnSettings.p->put_BurnFlags (NBF_BUF_UNDERRUN_PROT|NBF_SPEED_IN_KBS|NBF_DAO|NBF_VERIFY);
  289. }
  290. CPropertyPageBurnSettings page;
  291. if (page.m_pMfcPropertyPage != NULL)
  292. {
  293. CComQIPtr<INERO_SCSI_DEVICE_INFO> pNSDI (page.m_pMfcPropertyPage);
  294. ATLASSERT (pNSDI);
  295. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  296. ATLASSERT (pRecorderNSDI);
  297. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  298. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  299. pNSDI.p->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  300. CComQIPtr<IBurnSettingsDlg> pBurnSettingsDlg (page.m_pMfcPropertyPage);
  301. pBurnSettingsDlg.p->put_MediaType (SelectedMediaType());
  302. pBurnSettingsDlg.p->put_BurnSettings (pBurnSettings);
  303. CPropertySheet sheet;
  304. sheet.AddPage (&page);
  305. if (IDOK == sheet.DoModal ())
  306. {
  307. DWORD dwBurnFlags = 0;
  308. DWORD dwSpeed = 0;
  309. // These values aren't displayed. They only serve for debugging
  310. // purposes.
  311. //
  312. pBurnSettings.p->get_BurnFlags (&dwBurnFlags);
  313. pBurnSettings.p->get_Speed (&dwSpeed);
  314. }
  315. }
  316. }
  317. void CDlg::OnTestBurnSettingsOle()
  318. {
  319. // Create BurnSettings object.
  320. //
  321. CComPtr<IBurnSettings> pBurnSettings;
  322. if (SUCCEEDED (pBurnSettings.CoCreateInstance (__uuidof (BurnSettings))))
  323. {
  324. pBurnSettings.p->put_BurnFlags (NBF_BUF_UNDERRUN_PROT|NBF_SPEED_IN_KBS|NBF_DAO|NBF_VERIFY);
  325. }
  326. // Create BurnSettingsParam object and fill it with data.
  327. //
  328. CComPtr<IBurnSettingsDlg> pParam;
  329. if (SUCCEEDED (pParam.CoCreateInstance (__uuidof (BurnSettingsDlgParam))))
  330. {
  331. pParam->put_BurnSettings (pBurnSettings);
  332. pParam->put_MediaType (SelectedMediaType ());
  333. CComQIPtr<INERO_SCSI_DEVICE_INFO> pNSDIParam (pParam);
  334. ATLASSERT (pNSDIParam);
  335. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  336. ATLASSERT (pRecorderNSDI);
  337. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  338. pRecorderNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  339. pNSDIParam->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  340. }
  341. IUnknown * pUnk = pParam;
  342. OleCreatePropertyFrame (m_hWnd, 0, 0, L"Title", 1, &pUnk, 1, (LPCLSID) &__uuidof (BurnSettingsDlg), 0, NULL, NULL);
  343. }
  344. void CDlg::OnTestBurnProgress()
  345. {
  346. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  347. ATLASSERT (pRecorderNSDI);
  348. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  349. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  350. #if 1 // test the burn progress dialog of NeroCBUI
  351. CBurnDlg dlg;
  352. dlg.m_pDeviceInfo = pDeviceInfo;
  353. dlg.m_bWizardMode = c_WizardMode.GetCheck () != 0;
  354. dlg.DoModal ();
  355. #else // test the UserDlgHandler of NeroCBUI (don't forget to adapt the path to the image)
  356. ((CApp *)AfxGetApp ())->SetUserDlgParentHWND (m_hWnd);
  357. ((CApp *)AfxGetApp ())->ResetUserDlgAbort();
  358. NERO_WRITE_IMAGE m_neroImage;
  359. memset(&m_neroImage,0,sizeof(NERO_WRITE_IMAGE));
  360. m_neroImage.nwiImageFileName[0] = '\0';
  361. m_neroImage.nwiLongImageFileName = "c:\\test.nrg";
  362. NERO_DEVICEHANDLE handle = NeroOpenDevice(pDeviceInfo);
  363. NERO_PROGRESS * progress = NeroCreateProgress ();
  364. if(handle)
  365. {
  366. int result = NeroBurn(handle,NERO_BURN_IMAGE_MEDIA, &m_neroImage, NBF_WRITE|NBF_DETECT_NON_EMPTY_CDRW|NBF_DAO,0, progress);
  367. char * p = NeroGetLastError ();
  368. if (p)
  369. {
  370. AfxMessageBox (p);
  371. }
  372. NeroFreeMem (p);
  373. }
  374. else
  375. {
  376. ASSERT(FALSE);
  377. }
  378. NeroFreeMem (progress);
  379. #endif
  380. }
  381. void CDlg::OnTestImageInfo()
  382. {
  383. CPropertyPageImageInfo page;
  384. CComQIPtr<IImageInfoDlg> pImageInfoDlg (page.m_pMfcPropertyPage);
  385. ATLASSERT (pImageInfoDlg.p != NULL);
  386. if (pImageInfoDlg.p != NULL)
  387. {
  388. static char szFilter[] = "Nero Images (*.nrg)|*.nrg|ISO Images (*.iso)|*.iso|All Files (*.*)|*.*||";
  389. CFileDialog fd (TRUE,"nrg",NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter, this);
  390. if (IDOK == fd.DoModal ())
  391. {
  392. CComBSTR bstrFilename (fd.GetPathName ());
  393. pImageInfoDlg->put_ImageFilename (bstrFilename);
  394. CPropertySheet sheet;
  395. sheet.AddPage (&page);
  396. if (IDOK == sheet.DoModal ())
  397. {
  398. }
  399. }
  400. }
  401. }
  402. void CDlg::OnTestChooseRecorder()
  403. {
  404. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  405. ATLASSERT (pRecorderNSDI);
  406. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  407. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  408. CComPtr<INERO_SCSI_DEVICE_INFO> pNSDI;
  409. if (SUCCEEDED (pNSDI.CoCreateInstance (__uuidof (ChooseRecorderDlg))))
  410. {
  411. // Set the initial selection blindly to zero-th device.
  412. //
  413. pNSDI->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  414. // Declare a smart pointer to IModalDialog interface and call its
  415. // DoModal method.
  416. //
  417. CComQIPtr<IModalDialog> pModalDialog (pNSDI);
  418. ATLASSERT (pModalDialog.p != NULL);
  419. int iRet = 0;
  420. pModalDialog->DoModal (m_hWnd, &iRet);
  421. // Display different information depending on the return value.
  422. //
  423. switch (iRet)
  424. {
  425. case IDOK:
  426. {
  427. CString str, sDevice;
  428. NERO_SCSI_DEVICE_INFO * pDeviceInfo;
  429. // Get the last current selection in the recorder combobox.
  430. //
  431. pNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  432. sDevice.Format ("%s", (pDeviceInfo != NULL && pDeviceInfo->nsdiDeviceName[0] != '\0')? pDeviceInfo->nsdiDeviceName: "[no device selected]");
  433. str.Format ("The user's selection was \"%s\".", sDevice);
  434. AfxMessageBox (str);
  435. }
  436. break;
  437. case IDCANCEL:
  438. AfxMessageBox ("The dialog was canceled!");
  439. break;
  440. default:
  441. {
  442. CString str;
  443. str.Format ("There was an error displaying the dialog box!");
  444. AfxMessageBox (str);
  445. }
  446. }
  447. }
  448. }
  449. void CDlg::OnTestChooseSession()
  450. {
  451. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  452. ATLASSERT (pRecorderNSDI);
  453. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  454. pRecorderNSDI.p->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  455. CComPtr<INERO_SCSI_DEVICE_INFO> pNSDI;
  456. if (SUCCEEDED (pNSDI.CoCreateInstance (__uuidof (ChooseSessionDlg))))
  457. {
  458. // Set the initial selection blindly to zero-th device.
  459. //
  460. pNSDI->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  461. // Declare a smart pointer to IModalDialog interface and call its
  462. // DoModal method.
  463. //
  464. CComQIPtr<IModalDialog> pModalDialog (pNSDI);
  465. ATLASSERT (pModalDialog.p != NULL);
  466. int iRet = 0;
  467. pModalDialog->DoModal (m_hWnd, &iRet);
  468. // Display different information depending on the return value.
  469. //
  470. switch (iRet)
  471. {
  472. case IDOK:
  473. {
  474. CString str;
  475. CComQIPtr<IChooseSessionDlg> pChooseSessionDlg (pNSDI);
  476. ATLASSERT (pChooseSessionDlg.p != NULL);
  477. DWORD dwTrackNumber;
  478. pChooseSessionDlg->get_TrackNumber (&dwTrackNumber);
  479. str.Format ("The user selected track #%d.", dwTrackNumber);
  480. AfxMessageBox (str);
  481. }
  482. break;
  483. case IDCANCEL:
  484. AfxMessageBox ("The dialog was canceled!");
  485. break;
  486. default:
  487. {
  488. CString str;
  489. str.Format ("There was an error displaying the dialog box!");
  490. AfxMessageBox (str);
  491. }
  492. }
  493. }
  494. }
  495. void CDlg::OnSelchangeLangCombo()
  496. {
  497. int iSel=m_Combo.GetCurSel();
  498. if(iSel>=0)
  499. {
  500. int iLen = m_Combo.GetLBTextLen(iSel);
  501. CString csLang;
  502. m_Combo.GetLBText(iSel,csLang);
  503. CComPtr<IInitSettings> pInitSettings;
  504. // we can safely create a new instance of the InitSettings object,
  505. // since NeroCBUI will only allow one instance of this object and therefore
  506. // we will receive the already existing object
  507. if (SUCCEEDED (pInitSettings.CoCreateInstance (__uuidof (InitSettings))))
  508. {
  509. if(pInitSettings->put_LanguageCode((const signed char*)(const char*)csLang)!=S_OK)
  510. {
  511. AfxMessageBox("Setting the language failed!");
  512. m_Combo.SetCurSel(-1);
  513. }
  514. }
  515. else
  516. {
  517. AfxMessageBox("Failed to get an instance of the IInitSettings interface!");
  518. }
  519. }
  520. }
  521. void CDlg::OnTestEraseDiscModeless()
  522. {
  523. // Get the selected recorder from the combo and set it to the
  524. // object.
  525. //
  526. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  527. ATLASSERT (pRecorderNSDI);
  528. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  529. pRecorderNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  530. // Create EraseDiscDlg object.
  531. //
  532. CComPtr<IModelessDialog> pModelessEraseDiscDialog;
  533. if (SUCCEEDED (pModelessEraseDiscDialog.CoCreateInstance (__uuidof (EraseDiscDlg))))
  534. {
  535. CComQIPtr<IEraseDiscDlg3> pEraseDiscDlg (pModelessEraseDiscDialog);
  536. ATLASSERT (pEraseDiscDlg.p != NULL);
  537. // Let the dialog know the device. Don't use direct handle, it is
  538. // more convenient this way.
  539. //
  540. CComQIPtr<INERO_SCSI_DEVICE_INFO> pNSDI (pModelessEraseDiscDialog);
  541. ATLASSERT (pNSDI.p != NULL);
  542. pNSDI->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  543. // This is a trick as well as a whole IEraseDiscCallbacks interface
  544. // implementation, but it will do.
  545. //
  546. pEraseDiscDlg->put_Callbacks (this);
  547. // Create the dialog.
  548. //
  549. HWND hWndDlg;
  550. pModelessEraseDiscDialog->Create (m_hWnd, NULL, &hWndDlg);
  551. }
  552. }
  553. STDMETHODIMP CDlg::OnEraseDone (IEraseDiscDlg * pEraseDiscDlg)
  554. {
  555. // Erase process has been completed.
  556. //
  557. CString str;
  558. CComBSTR bstr;
  559. USES_CONVERSION;
  560. int iResult = 0;
  561. // Get the results...
  562. //
  563. pEraseDiscDlg->get_ErasingResultString (&bstr);
  564. pEraseDiscDlg->get_ErasingResult (&iResult);
  565. // Format and display the results...
  566. //
  567. str.Format ("Reported result was: %d.\nReported message was: \"%s\".", iResult, W2CA (bstr));
  568. AfxMessageBox (str);
  569. return S_OK;
  570. }
  571. STDMETHODIMP CDlg::OnFilterRecorder(LPCNERO_SCSI_DEVICE_INFO pDeviceInfo, BOOL * pbAccept)
  572. {
  573. ASSERT (pDeviceInfo != NULL);
  574. ASSERT (pbAccept != NULL);
  575. // Filter out the devices that are not capable of burning.
  576. //
  577. if (pDeviceInfo->nsdiDevType == NEA_SCSI_DEVTYPE_CDROM ||
  578. pDeviceInfo->nsdiDevType == NEA_SCSI_DEVTYPE_UNKNOWN ||
  579. pDeviceInfo->nsdiDevType == NEA_SCSI_DEVTYPE_UNSUPPORTED_WORM ||
  580. (pDeviceInfo->nsdiCapabilities & NSDI_ALLOWED) == 0)
  581. {
  582. // We don't want CDROMs, unknown and unsupported drives
  583. *pbAccept = FALSE;
  584. }
  585. else
  586. {
  587. *pbAccept = TRUE;
  588. }
  589. return S_OK;
  590. }
  591. STDMETHODIMP CDlg::OnFilterEnd()
  592. {
  593. return S_OK;
  594. }
  595. STDMETHODIMP CDlg::OnContentRefreshed()
  596. {
  597. // here we check, if the selected recorder changed and set the selected recorder
  598. // in the write speed combo box
  599. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  600. ATLASSERT (pRecorderNSDI);
  601. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  602. pRecorderNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  603. CComQIPtr<INERO_SCSI_DEVICE_INFO> pSpeedNSDI (m_pWriteSpeedCombobox);
  604. ATLASSERT (pSpeedNSDI);
  605. pSpeedNSDI->put_NERO_SCSI_DEVICE_INFO (pDeviceInfo);
  606. return S_OK;
  607. }
  608. STDMETHODIMP CDlg::OnCurSelInUseStatusChange(BOOL bInUse)
  609. {
  610. // normally one would deactivate the burn button if bInUse
  611. // is TRUE and activate it otherwise
  612. return S_OK;
  613. }
  614. void CDlg::OnTestWaitForMedia()
  615. {
  616. // Get the selected recorder from the combo.
  617. //
  618. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI (m_pRecorderCombobox);
  619. ATLASSERT (pRecorderNSDI);
  620. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  621. pRecorderNSDI->get_NERO_SCSI_DEVICE_INFO (&pDeviceInfo);
  622. if (pDeviceInfo != NULL)
  623. {
  624. NERO_DEVICEHANDLE deviceHandle = NeroOpenDevice (pDeviceInfo);
  625. if (deviceHandle != NULL)
  626. {
  627. CComPtr<IWaitForMediaDlg> pWaitForMedia;
  628. if (SUCCEEDED (pWaitForMedia.CoCreateInstance (__uuidof (WaitForMediaDlg))))
  629. {
  630. BOOL bAbort = FALSE;
  631. pWaitForMedia->WaitForMedia (m_hWnd, deviceHandle, SelectedMediaType(), NBF_WRITE, NULL, &bAbort);
  632. CString str;
  633. str.Format ("The outcome of the operation was %sto abort!", bAbort? "": "NOT ");
  634. AfxMessageBox (str);
  635. }
  636. NeroCloseDevice (deviceHandle);
  637. }
  638. }
  639. }
  640. void CDlg::OnSelchangeMediaCombo()
  641. {
  642. m_pWriteSpeedCombobox.p->put_MediaType(SelectedMediaType());
  643. }
  644. NERO_MEDIA_TYPE CDlg::SelectedMediaType()
  645. {
  646. NERO_MEDIA_TYPE mediatype=MEDIA_CD; // default value
  647. int iSel=m_MediaCombo.GetCurSel();
  648. if(iSel>=0)
  649. {
  650. CString csMedia;
  651. m_MediaCombo.GetLBText(iSel,csMedia);
  652. if(csMedia=="CD")
  653. {
  654. mediatype=MEDIA_CD;
  655. }
  656. else if(csMedia=="DVD")
  657. {
  658. mediatype=MEDIA_DVD_ANY;
  659. }
  660. else if(csMedia=="HDB")
  661. {
  662. mediatype=MEDIA_HDB;
  663. }
  664. else if(csMedia=="BD")
  665. {
  666. mediatype=MEDIA_BD_ANY;
  667. }
  668. else
  669. {
  670. ASSERT(false);
  671. }
  672. }
  673. return mediatype;
  674. }
  675. void CDlg::OnSelchangeRecorder()
  676. {
  677. OnContentRefreshed ();
  678. }
  679. void CDlg::OnTestImageInfoOle()
  680. {
  681. static char szFilter[] = "Nero Images (*.nrg)|*.nrg|ISO Images (*.iso)|*.iso|All Files (*.*)|*.*||";
  682. CFileDialog fd (TRUE,"nrg",NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter, this);
  683. if (IDOK == fd.DoModal ())
  684. {
  685. CComPtr<IImageInfoDlg> pParam;
  686. if (SUCCEEDED (pParam.CoCreateInstance (__uuidof (ImageInfoDlgParam))))
  687. {
  688. CComBSTR bstrFilename (fd.GetPathName ());
  689. pParam->put_ImageFilename (bstrFilename);
  690. IUnknown * pUnk = pParam;
  691. OleCreatePropertyFrame (m_hWnd, 0, 0, L"Title", 1, &pUnk, 1, (LPCLSID) &__uuidof (ImageInfoDlg), 0, NULL, NULL);
  692. }
  693. }
  694. }
  695. void CDlg::OnTestConfigureRobot()
  696. {
  697. /** Create robo configure dialog. */
  698. CComPtr<IConfigureRoboDlg> pRoboDlg;
  699. HRESULT hResult = pRoboDlg.CoCreateInstance(__uuidof(ConfigureRoboDlg));
  700. if(SUCCEEDED(hResult))
  701. {
  702. CComQIPtr<IConfigureRoboDlgCallbacks> pConfRoboDlgCallbacks(this);
  703. pRoboDlg->put_Callbacks(pConfRoboDlgCallbacks);
  704. pRoboDlg->put_RoboInfos(m_pRoboInfos);
  705. // Declare a smart pointer to IModalDialog interface and call its DoModal method.
  706. CComPtr<IModalDialog> pModalDialog;
  707. int iRet = 0;
  708. hResult = pRoboDlg->QueryInterface(&pModalDialog);
  709. if(SUCCEEDED(hResult))
  710. pModalDialog->DoModal(m_hWnd,&iRet);
  711. switch (iRet)
  712. {
  713. case IDOK:
  714. {
  715. DWORD dwCount = 0;
  716. CString csTemp = "";
  717. pRoboDlg->get_RoboInfos(&(m_pRoboInfos.p));
  718. m_pRoboInfos->get_Count(&dwCount);
  719. csTemp.Format("The dialog was confirmed.\nRecevied %d recorder(s) with robot driver associated.", dwCount);
  720. AfxMessageBox(csTemp);
  721. }
  722. break;
  723. case IDCANCEL:
  724. AfxMessageBox ("The dialog was canceled!");
  725. break;
  726. default:
  727. {
  728. CString str;
  729. str.Format ("There was an error displaying the dialog box!");
  730. AfxMessageBox (str);
  731. }
  732. }
  733. }
  734. else
  735. {
  736. CString msg = "????";
  737. switch(hResult)
  738. {
  739. case REGDB_E_CLASSNOTREG: msg = "Class not registered!!!"; break;
  740. case CLASS_E_NOAGGREGATION: msg = "No aggregation!!!"; break;
  741. case E_NOINTERFACE: msg = "No interface!!!"; break;
  742. default: ASSERT(FALSE); break;
  743. }
  744. AfxMessageBox(msg);
  745. }
  746. pRoboDlg = NULL;
  747. }
  748. STDMETHODIMP CDlg::OnConfigureRobot(IRoboInfo* pRoboInfo)
  749. {
  750. ASSERT(pRoboInfo != NULL);
  751. if(pRoboInfo != NULL)
  752. {
  753. CString csInfo = GetRoboInfoString(pRoboInfo);
  754. CString csMsg;
  755. csMsg.Format("CDlg::OnConfigureRobot\n%s", csInfo);
  756. AfxMessageBox(csMsg);
  757. }
  758. return S_OK;
  759. }
  760. STDMETHODIMP CDlg::OnTestRobot(IRoboInfo* pRoboInfo)
  761. {
  762. ASSERT(pRoboInfo != NULL);
  763. if(pRoboInfo != NULL)
  764. {
  765. CString csInfo = GetRoboInfoString(pRoboInfo);
  766. CString csMsg;
  767. csMsg.Format("CDlg::OnTestRobot\n%s", csInfo);
  768. AfxMessageBox(csMsg);
  769. }
  770. return S_OK;
  771. }
  772. STDMETHODIMP CDlg::OnRobotPortChanged(IRoboInfo* pRoboInfo)
  773. {
  774. ASSERT(pRoboInfo != NULL);
  775. if(pRoboInfo != NULL)
  776. {
  777. CString csInfo = GetRoboInfoString(pRoboInfo);
  778. CString csMsg;
  779. csMsg.Format("CDlg::OnRobotPortChanged\n%s", csInfo);
  780. AfxMessageBox(csMsg);
  781. }
  782. return S_OK;
  783. }
  784. STDMETHODIMP CDlg::OnRobotBlankCdrw(IRoboInfo* pRoboInfo, BOOL bChecked)
  785. {
  786. ASSERT(pRoboInfo != NULL);
  787. if(pRoboInfo != NULL)
  788. {
  789. CString csInfo = GetRoboInfoString(pRoboInfo);
  790. CString csMsg;
  791. csMsg.Format("CDlg::OnRobotBlankCdrw\n%s\nnChecked: %d", csInfo, bChecked);
  792. AfxMessageBox(csMsg);
  793. }
  794. return S_OK;
  795. }
  796. CString CDlg::GetRoboInfoString(IRoboInfo* pRoboInfo)
  797. {
  798. CString csInfo;
  799. ASSERT(pRoboInfo != NULL);
  800. if(pRoboInfo != NULL)
  801. {
  802. /** Get device name... */
  803. LPNERO_SCSI_DEVICE_INFO pDeviceInfo = NULL;
  804. CComQIPtr<INERO_SCSI_DEVICE_INFO> pRecorderNSDI(pRoboInfo);
  805. ATLASSERT(pRecorderNSDI.p != NULL);
  806. if(pRecorderNSDI.p != NULL)
  807. pRecorderNSDI->get_NERO_SCSI_DEVICE_INFO(&pDeviceInfo);
  808. CString csRecName = (pDeviceInfo != NULL) ? pDeviceInfo->nsdiDeviceName : "Unknown Recorder Device!";
  809. CComBSTR bstrName;
  810. USES_CONVERSION;
  811. /** and robo name ...*/
  812. pRoboInfo->get_RoboName(&bstrName);
  813. CString csRoboName = (bstrName != NULL) ? W2A(bstrName): "";
  814. if(csRoboName.IsEmpty())
  815. csRoboName = "<No Robot>";
  816. /** and printer name...*/
  817. pRoboInfo->get_PrinterName(&bstrName);
  818. CString csPrinterName = (bstrName != NULL) ? W2A(bstrName): "";
  819. if(csPrinterName.IsEmpty())
  820. csPrinterName = "<No Printer>";
  821. /** and port type...*/
  822. DWORD dwPortType;
  823. pRoboInfo->get_PortType(&dwPortType);
  824. /** and port number. */
  825. DWORD dwPortNo;
  826. pRoboInfo->get_PortNumber(&dwPortNo);
  827. /** Assembly the info message. */
  828. csInfo.Format("\nRecorder:\t%s\nRobot:\t\t%s\nPrinter:\t\t%s\nPort Type:\t%d\nPort Number:\t%d", csRecName, csRoboName, csPrinterName, dwPortType, dwPortNo);
  829. }
  830. return csInfo;
  831. }