NVAPIExample.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 / NVAPIExample
  10. |*
  11. |* PROGRAM: NVAPIExample.cpp
  12. |*
  13. |* PURPOSE: CWinApp derived class.
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "NVAPIExample.h"
  17. #include "NVAPIExampleDlg.h"
  18. #include "SplashThread.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. BEGIN_MESSAGE_MAP(CNVAPIExampleApp, CWinApp)
  25. //{{AFX_MSG_MAP(CNVAPIExampleApp)
  26. // NOTE - the ClassWizard will add and remove mapping macros here.
  27. // DO NOT EDIT what you see in these blocks of generated code!
  28. //}}AFX_MSG
  29. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  30. END_MESSAGE_MAP()
  31. CNVAPIExampleApp::CNVAPIExampleApp()
  32. {
  33. // TODO: add construction code here,
  34. // Place all significant initialization in InitInstance
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. // The one and only CNVAPIExampleApp object
  38. CNVAPIExampleApp theApp;
  39. // This is a static member variable important for NeroAPI initialization.
  40. //
  41. NERO_SETTINGS CNVAPIExampleApp::ns =
  42. {
  43. NULL,
  44. "Nero",
  45. "Nero Burning ROM",
  46. "Nero.txt",
  47. {NeroIdleCallback, &theApp},
  48. {NeroUserDialog, &theApp},
  49. FALSE,
  50. 0
  51. };
  52. BOOL CNVAPIExampleApp::InitInstance()
  53. {
  54. // Standard initialization
  55. // If you are not using these features and wish to reduce the size
  56. // of your final executable, you should remove from the following
  57. // the specific initialization routines you do not need.
  58. #ifdef _AFXDLL
  59. Enable3dControls(); // Call this when using MFC in a shared DLL
  60. #else
  61. Enable3dControlsStatic(); // Call this when linking to MFC statically
  62. #endif
  63. // Start the thread that will bring up the splash dialog...
  64. //
  65. CSplashThread * pSplashThread;
  66. pSplashThread = (CSplashThread *) AfxBeginThread (RUNTIME_CLASS (CSplashThread));
  67. // Initialize COM...
  68. //
  69. HRESULT hr = CoInitialize (NULL);
  70. if (SUCCEEDED (hr))
  71. {
  72. // Load NeroAPI...
  73. //
  74. if (! NeroAPIGlueConnect (NULL))
  75. {
  76. AfxMessageBox (IDS_NEROAPI_GLUE_CONNECT_FAILED);
  77. }
  78. else
  79. {
  80. // Initialize NeroAPI...
  81. //
  82. NEROAPI_INIT_ERROR err = NeroInit (&ns, NULL);
  83. if (err != NEROAPI_INIT_OK)
  84. {
  85. AfxMessageBox (IDS_NERO_INIT_FAILED);
  86. }
  87. else
  88. {
  89. // The dialog's constructor will do some additional lengthy
  90. // work such as initializing MSXML parser...
  91. //
  92. CNVAPIExampleDlg dlg;
  93. m_pMainWnd = &dlg;
  94. // Hide the splash screen now that everything is ready...
  95. //
  96. pSplashThread->m_pMainWnd->ShowWindow (SW_HIDE);
  97. dlg.DoModal();
  98. }
  99. }
  100. }
  101. if (pSplashThread != NULL)
  102. {
  103. // Close the splash window. This will effectively terminate the
  104. // splash thread as well.
  105. //
  106. pSplashThread->m_pMainWnd->PostMessage (WM_CLOSE);
  107. }
  108. // Since the dialog has been closed, return FALSE so that we exit the
  109. // application, rather than start the application's message pump.
  110. return FALSE;
  111. }
  112. int CNVAPIExampleApp::ExitInstance()
  113. {
  114. // Clean up the NeroAPI...
  115. //
  116. NeroDone ();
  117. NeroAPIGlueDone ();
  118. CoUninitialize ();
  119. return CWinApp::ExitInstance();
  120. }
  121. // This is a helper method used for pumping the messages in long operations
  122. // that hijack the main app's thread.
  123. //
  124. void CNVAPIExampleApp::PumpMessages (void) const
  125. {
  126. MSG msg;
  127. while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
  128. {
  129. if (!AfxGetApp ()->PumpMessage ())
  130. {
  131. ::PostQuitMessage (0);
  132. break;
  133. }
  134. }
  135. }
  136. // NeroAPI's idle callback impementation.
  137. //
  138. BOOL NERO_CALLBACK_ATTR CNVAPIExampleApp::NeroIdleCallback (void *pUserData)
  139. {
  140. CNVAPIExampleApp * pThis = (CNVAPIExampleApp *) pUserData;
  141. // When NeroAPI is idle, let's pump messages to keep everything nicely
  142. // responsive.
  143. //
  144. pThis->PumpMessages ();
  145. // Forward the idle callback request to the main app's window using a
  146. // user defined message.
  147. //
  148. return (BOOL) pThis->GetMainWnd ()->SendMessage (UM_NERO_IDLE_CALLBACK);
  149. }
  150. // NeroAPI's user dialog callback impementation.
  151. //
  152. NeroUserDlgInOut NERO_CALLBACK_ATTR CNVAPIExampleApp::NeroUserDialog (void *pUserData, NeroUserDlgInOut type, void *data)
  153. {
  154. CNVAPIExampleApp * pThis = (CNVAPIExampleApp *) pUserData;
  155. // Forward the user dialog callback to the main app's windows using a
  156. // user defined message and return whatever the handler returns to us.
  157. //
  158. return (NeroUserDlgInOut) pThis->GetMainWnd ()->SendMessage (UM_NERO_USER_DIALOG, (WPARAM) type, (LPARAM) data);
  159. }