PageSecond.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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: PageSecond.cpp
  12. |*
  13. |* PURPOSE: Implementation of the second page.
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "NVAPIExample.h"
  17. #include "PageSecond.h"
  18. #include "Sheet.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPageSecond dialog
  26. CPageSecond::CPageSecond(CSheet * pParent)
  27. : CPage(CPageSecond::IDD, pParent)
  28. , m_bFirstActivate (true)
  29. {
  30. //{{AFX_DATA_INIT(CPageSecond)
  31. //}}AFX_DATA_INIT
  32. }
  33. void CPageSecond::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CPage::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CPageSecond)
  37. DDX_Control(pDX, IDC_CHILD_DIALOG_PLACEHOLDER, c_ChildDialogPlaceholder);
  38. DDX_Control(pDX, IDC_SPEED, c_Speed);
  39. DDX_Control(pDX, IDC_RECORDER, c_Recorder);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CPageSecond, CPage)
  43. //{{AFX_MSG_MAP(CPageSecond)
  44. ON_CBN_SELCHANGE(IDC_RECORDER, OnSelchangeRecorder)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. bool CPageSecond::Create (void)
  48. {
  49. return CDialog::Create (m_lpszTemplateName, m_pParentWnd) != FALSE;
  50. }
  51. bool CPageSecond::OnNext (void)
  52. {
  53. // If "Next" button is clicked set the currently selected recorder and
  54. // speed to the common inter-page communication CPageData instance.
  55. //
  56. CPageData * pPageData = GetPageData ();
  57. pPageData->m_pDeviceInfo = c_Recorder.GetCurrentRecorder ();
  58. pPageData->m_dwBurnSpeed = c_Speed.GetSelectedSpeed ();
  59. return false;
  60. }
  61. void CPageSecond::OnChangeState (bool bActivate, bool bForward)
  62. {
  63. if (bActivate)
  64. {
  65. if (m_bFirstActivate)
  66. {
  67. m_bFirstActivate = false;
  68. // If the page is activated for the first time, fill in the
  69. // recorder combobox and update the speeds combobox accordingly.
  70. //
  71. c_Recorder.Initialize ();
  72. UpdateSpeeds ();
  73. }
  74. if (bForward)
  75. {
  76. // If the page is activated in the forward direction, we should
  77. // prepare for transcoding time and disk size estimation.
  78. //
  79. CWaitCursor wait;
  80. // Reset the estimation dialog's controls. Show the estimation
  81. // dialog and hide the estimation-done dialog.
  82. //
  83. m_dlgEstimating.c_Progress.SetPos (0);
  84. m_dlgEstimating.ShowWindow (SW_SHOW);
  85. m_dlgEstimateDone.ShowWindow (SW_HIDE);
  86. m_dlgEstimateDone.m_sEstimatedSize.Empty ();
  87. m_dlgEstimateDone.m_sEstimatedTime.Empty ();
  88. UpdateWindow ();
  89. CPageData * pPageData = GetPageData ();
  90. // Load and set the error string in case the estimation fails.
  91. //
  92. m_dlgEstimateDone.m_sEstimatedSize.LoadString (IDS_ERROR_GETTING_DISK_SIZE);
  93. m_dlgEstimateDone.m_sEstimatedTime.LoadString (IDS_ERROR_GETTING_TIME);
  94. // Now set the XML string to the NeroVisionAPI's Project
  95. // object.
  96. //
  97. BOOL bSuccess = pPageData->m_pProject->SetXMLString ((LPSTR)(LPCSTR) GetPageData ()->m_sXML);
  98. if (!bSuccess)
  99. {
  100. // On error, get the error text and display it.
  101. //
  102. IErrorPtr pError = pPageData->m_pProject->LastError;
  103. USES_CONVERSION;
  104. AfxMessageBox (W2CA (pError->ErrText));
  105. }
  106. else
  107. {
  108. // If XML setting succeeded, ask for disk size and
  109. // trancoding duration estimates.
  110. //
  111. __int64 iSize = 0;
  112. bSuccess = pPageData->m_pProject->EstimateDiskSize (&iSize);
  113. if (bSuccess)
  114. {
  115. // On success, format the disk size and put it on the
  116. // dialog.
  117. //
  118. CString sFormat;
  119. sFormat.LoadString (IDS_DISK_SIZE_FORMAT);
  120. m_dlgEstimateDone.m_sEstimatedSize.Format (sFormat, (int)(iSize/(1024*1024)));
  121. }
  122. // Now get the transcoding duration estimation. This might
  123. // take a while. We are passing an IProgressCallback interface
  124. // pointer which we are implementing. This will give us
  125. // an opportunity to move the progress bar and indicate
  126. // how long the process will take.
  127. //
  128. double dSeconds = 0;
  129. bSuccess = pPageData->m_pProject->EstimateCreateNeroBurnContextTime (this, &dSeconds);
  130. if (bSuccess)
  131. {
  132. // On success, format the time and set it on the
  133. // dialog.
  134. //
  135. CString sFormat;
  136. sFormat.LoadString (IDS_TIME_FORMAT);
  137. int iSeconds = (int) dSeconds;
  138. m_dlgEstimateDone.m_sEstimatedTime.Format (sFormat, iSeconds/60, iSeconds%60);
  139. }
  140. }
  141. // Transfer the data onto the dialog and switch the two dialogs.
  142. //
  143. m_dlgEstimateDone.UpdateData (FALSE);
  144. m_dlgEstimateDone.ShowWindow (SW_SHOW);
  145. m_dlgEstimating.ShowWindow (SW_HIDE);
  146. }
  147. }
  148. }
  149. BOOL CPageSecond::OnInitDialog()
  150. {
  151. CPage::OnInitDialog();
  152. // Create the two child dialogs.
  153. //
  154. VERIFY (m_dlgEstimateDone.Create (CEstimateDoneDlg::IDD, this));
  155. VERIFY (m_dlgEstimating.Create (CEstimatingDlg::IDD, this));
  156. // Place them in place of the placeholder.
  157. //
  158. CRect rcPlaceholder;
  159. c_ChildDialogPlaceholder.GetWindowRect (&rcPlaceholder);
  160. ScreenToClient (&rcPlaceholder);
  161. m_dlgEstimateDone.MoveWindow (&rcPlaceholder);
  162. m_dlgEstimating.MoveWindow (&rcPlaceholder);
  163. // Set the range of the progess bar.
  164. //
  165. m_dlgEstimating.c_Progress.SetRange (0, 100);
  166. return TRUE; // return TRUE unless you set the focus to a control
  167. // EXCEPTION: OCX Property Pages should return FALSE
  168. }
  169. void CPageSecond::UpdateSpeeds (void)
  170. {
  171. // Refresh the speeds combobox according to the recorder selected in
  172. // the recorder combobox.
  173. //
  174. c_Speed.RefreshSpeeds (c_Recorder.GetCurrentRecorder ());
  175. }
  176. void CPageSecond::OnSelchangeRecorder()
  177. {
  178. // When recorder selection changes, update the speeds.
  179. //
  180. UpdateSpeeds ();
  181. }
  182. STDMETHODIMP CPageSecond::raw_OnProgress (
  183. enum ProgressAction action,
  184. BSTR itemname,
  185. double currentRemain,
  186. double currentTotal,
  187. float currentFraction,
  188. double totalRemain,
  189. double totalTotal,
  190. float totalFraction)
  191. {
  192. // Update the progress bar and pump the messages so that everything
  193. // remains responsive during transcoding duration estimation.
  194. //
  195. int iPercent = (int) (currentFraction*100);
  196. m_dlgEstimating.c_Progress.SetPos (iPercent);
  197. m_dlgEstimating.c_Progress.UpdateWindow ();
  198. return S_OK;
  199. }
  200. STDMETHODIMP CPageSecond::raw_ShouldCancel (
  201. VARIANT_BOOL * pbCancel)
  202. {
  203. // The duration estimation cannot be canceled. It usually takes only
  204. // a few seconds. Everybody can wait this long ;-)
  205. //
  206. *pbCancel = VARIANT_FALSE;
  207. return S_OK;
  208. }