TestNeroCBUI.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 "NeroCBUIGlue.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CApp
  26. BEGIN_MESSAGE_MAP(CApp, CWinApp)
  27. //{{AFX_MSG_MAP(CApp)
  28. // NOTE - the ClassWizard will add and remove mapping macros here.
  29. // DO NOT EDIT what you see in these blocks of generated code!
  30. //}}AFX_MSG
  31. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CApp construction
  35. CApp::CApp()
  36. {
  37. m_bNeroAPIInitOk = false;
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // The one and only CApp object
  41. CApp theApp;
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CApp initialization
  44. BOOL CApp::InitInstance()
  45. {
  46. // Standard initialization
  47. // If you are not using these features and wish to reduce the size
  48. // of your final executable, you should remove from the following
  49. // the specific initialization routines you do not need.
  50. /** Enable3dControls is nno longer necesary in VS .NET. */
  51. #if _MFC_VER < 0x0700
  52. #ifdef _AFXDLL
  53. Enable3dControls(); // Call this when using MFC in a shared DLL
  54. #else
  55. Enable3dControlsStatic(); // Call this when linking to MFC statically
  56. #endif
  57. #endif
  58. CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
  59. SetupNeroAPI ();
  60. CDlg dlg;
  61. m_pMainWnd = &dlg;
  62. int nResponse = dlg.DoModal();
  63. if (nResponse == IDOK)
  64. {
  65. // TODO: Place code here to handle when the dialog is
  66. // dismissed with OK
  67. }
  68. else if (nResponse == IDCANCEL)
  69. {
  70. // TODO: Place code here to handle when the dialog is
  71. // dismissed with Cancel
  72. }
  73. // Since the dialog has been closed, return FALSE so that we exit the
  74. // application, rather than start the application's message pump.
  75. return FALSE;
  76. }
  77. int CApp::ExitInstance()
  78. {
  79. CleanupNeroAPI ();
  80. CoUninitialize ();
  81. return CWinApp::ExitInstance();
  82. }
  83. void CApp::SetupNeroAPI (void)
  84. {
  85. NEROAPI_INIT_ERROR err;
  86. // Initialize the NeroAPI glue code.
  87. //
  88. BOOL bSuccess = NeroAPIGlueConnect(NULL);
  89. if (bSuccess)
  90. {
  91. // Now, initialize the NeroAPI itself.
  92. //
  93. m_NeroSettings.nstUserDialog.ncUserData=this;
  94. m_NeroSettings.nstIdle.ncUserData=this;
  95. err = NeroInit (&m_NeroSettings, NULL);
  96. // Now, create the InitSettings NeroCBUI object and pass it the
  97. // NeroAPI module handle.
  98. //
  99. if (err == NEROAPI_INIT_OK && SUCCEEDED (m_pInitSettings.CoCreateInstance (__uuidof (InitSettings))))
  100. {
  101. // Release the object immediately so we can test successive
  102. // creation.
  103. //
  104. m_pInitSettings = NULL;
  105. if (SUCCEEDED (m_pInitSettings.CoCreateInstance (__uuidof (InitSettings))))
  106. {
  107. m_pInitSettings->put_HMODULE (NeroAPIGlueGetModuleHandle ());
  108. m_pInitSettings->put_AppTitle ((const signed char*)"Test NeroCBUI");
  109. CComPtr<IInitSettings> pInitSettingsForTest;
  110. HRESULT hr = pInitSettingsForTest.CoCreateInstance (__uuidof (InitSettings));
  111. // The following are tests for proper operation of singleton
  112. // implementation. The second create must succeed and its
  113. // interface pointers must be litterally equal as they point
  114. // to the very same object.
  115. //
  116. ATLASSERT (SUCCEEDED (hr));
  117. ATLASSERT (pInitSettingsForTest.p == m_pInitSettings.p);
  118. }
  119. CComPtr<IUnknown> pCompatibilityMgr;
  120. pCompatibilityMgr.Attach(NeroCBUIGlueGetCompatibilityMgr(NeroAPIGlueGetModuleHandle(),NULL));
  121. m_pInitSettings->put_CompatibilityMgr(pCompatibilityMgr);
  122. bSuccess = SUCCEEDED (m_pDlgHandler.CoCreateInstance (__uuidof (UserDlgHandler)));
  123. ATLASSERT (bSuccess);
  124. }
  125. }
  126. m_pInitSettings = NULL;
  127. m_bNeroAPIInitOk = (err == NEROAPI_INIT_OK) && bSuccess;
  128. }
  129. void CApp::SetUserDlgParentHWND (HWND hWnd)
  130. {
  131. if (m_pDlgHandler.p != NULL)
  132. {
  133. m_pDlgHandler->put_ParentHWND (hWnd);
  134. }
  135. }
  136. void CApp::ResetUserDlgAbort()
  137. {
  138. if (m_pDlgHandler.p != NULL)
  139. {
  140. m_pDlgHandler->put_Aborted (FALSE);
  141. }
  142. }
  143. void CApp::CleanupNeroAPI (void)
  144. {
  145. m_pInitSettings = NULL;
  146. m_pDlgHandler = NULL;
  147. NeroDone ();
  148. NeroAPIGlueDone ();
  149. }
  150. NERO_SETTINGS CApp::m_NeroSettings = {
  151. NULL,
  152. "Ahead",
  153. "Nero - Burning Rom",
  154. "Nero.txt",
  155. {CApp::IdleCallback, 0},
  156. {CApp::UserDialog, 0},
  157. FALSE,
  158. 0};
  159. BOOL NERO_CALLBACK_ATTR CApp::IdleCallback (void *pUserData)
  160. {
  161. MSG msg;
  162. while (::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  163. {
  164. if (!AfxGetThread()->PumpMessage())
  165. {
  166. ::PostQuitMessage(0);
  167. break;
  168. }
  169. }
  170. // Do MFC's idle processing.
  171. //
  172. LONG lIdle = 0;
  173. while (AfxGetThread ()->OnIdle (lIdle++))
  174. ;
  175. BOOL bAborted = FALSE;
  176. CApp * pThis = (CApp *) pUserData;
  177. // here we check if the user pressed abort in one of the dialogs
  178. // of the NeroCBUI user dlg handler
  179. // don't forget to reset the abort flag in the user dlg handler
  180. // before starting a new burn process.
  181. if (pThis->m_pDlgHandler.p != NULL)
  182. {
  183. pThis->m_pDlgHandler->get_Aborted (&bAborted);
  184. }
  185. return bAborted;
  186. }
  187. NeroUserDlgInOut NERO_CALLBACK_ATTR CApp::UserDialog(void *pUserData, NeroUserDlgInOut type, void *data)
  188. {
  189. // We use the user dlg handler of NeroCBUI, so we don't have to take care
  190. // about this ourselves. If an application would need to so it could also
  191. // use the user dlg handler of NeroCBUI only for specific NeroUserDlgInOut types
  192. // and handle the rest by itself.
  193. //
  194. // To enable the use of UserDlgHandler in TestNeroCBUI you have to change
  195. // OnTestBurnProgress in Dlg.cpp
  196. NeroUserDlgInOut result;
  197. ASSERT(pUserData);
  198. if(pUserData && SUCCEEDED(((CApp*)pUserData)->m_pDlgHandler->HandleUserDlg(type,data,&result)))
  199. {
  200. return result;
  201. }
  202. else
  203. {
  204. ATLASSERT(FALSE);
  205. }
  206. return DLG_RETURN_NOT_HANDLED;
  207. }