PagePreview.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // PagePreview.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "NVAPIExample.h"
  5. #include "NVAPIExampleDlg.h"
  6. #include "PagePreview.h"
  7. #include "PageData.h"
  8. #include "Sheet.h"
  9. #include "math.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CPagePreview dialog
  17. CPagePreview::CPagePreview(CSheet * pParent)
  18. : CPage(CPagePreview::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CPagePreview)
  21. // NOTE: the ClassWizard will add member initialization here
  22. //}}AFX_DATA_INIT
  23. m_preview = 0;
  24. }
  25. void CPagePreview::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CPagePreview)
  29. DDX_Control(pDX, IDC_PREVIEW_SLIDER, m_slider);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CPagePreview, CDialog)
  33. //{{AFX_MSG_MAP(CPagePreview)
  34. ON_WM_HSCROLL()
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CPagePreview message handlers
  39. bool CPagePreview::Create (void)
  40. {
  41. // This is a CPage virtual function. Just create the dialog and return
  42. // success.
  43. //
  44. return CDialog::Create (m_lpszTemplateName, m_pParentWnd) != FALSE;
  45. }
  46. bool CPagePreview::OnBack (void)
  47. {
  48. // go back to first page
  49. CNVAPIExampleDlg * pParentSheet = (CNVAPIExampleDlg *) GetParent();
  50. if (pParentSheet)
  51. pParentSheet->SwitchPage(0);
  52. return true;
  53. }
  54. void CPagePreview::OnChangeState (bool bActivate, bool bForward)
  55. {
  56. // always preview all title, because there is no way to unselect item in a tree view
  57. if (bForward)
  58. {
  59. CPageData * pPageData = GetPageData ();
  60. if (pPageData)
  61. {
  62. // prepare preview struct
  63. BOOL bSuccess = pPageData->m_pProject->SetXMLString ((LPSTR)(LPCSTR) pPageData->m_sXML);
  64. if (bSuccess)
  65. {
  66. m_preview->SetPreviewContext(pPageData->m_pProject, (wchar_t*)0);
  67. NeroVisionAPI::IErrorPtr err = m_preview->LastError;
  68. if (err->ErrCode != NeroVisionAPI::NoError)
  69. MessageBox(err->ErrText);
  70. // set preview window
  71. RECT previewRect;
  72. CWnd* frame = GetDlgItem(IDC_PREVIEWFRAME);
  73. if (frame) {
  74. frame->GetClientRect(&previewRect);
  75. m_preview->SetPreviewWindow((long)frame->GetSafeHwnd(), previewRect.left, previewRect.top, previewRect.right, previewRect.bottom);
  76. m_preview->StartPreview();
  77. m_preview->BackgroundColor = RGB(0, 0, 32);
  78. m_preview->Callback = this;
  79. UpdateWindow();
  80. }
  81. }
  82. }
  83. }
  84. else
  85. {
  86. // stop preview before leave the page
  87. m_preview->StopPreview();
  88. }
  89. }
  90. BOOL CPagePreview::OnInitDialog()
  91. {
  92. CDialog::OnInitDialog();
  93. if (FAILED(m_preview.CreateInstance(__uuidof(NeroVisionAPI::Preview))))
  94. m_preview = 0;
  95. m_slider.SetRange(0, 1000);
  96. return TRUE; // return TRUE unless you set the focus to a control
  97. // EXCEPTION: OCX Property Pages should return FALSE
  98. }
  99. STDMETHODIMP CPagePreview::raw_NotifyPosChanged(double pos, int title, int chapter)
  100. {
  101. TCHAR buf[100];
  102. // show time and position of the playing title
  103. double durSec = m_preview->GetDuration();
  104. if (fabs(pos) > 0.01 && long(durSec / pos) < 1000) {
  105. // wrong value send by IPreview when viewing menu
  106. if (m_setSlider)
  107. {
  108. m_slider.SetPos(long(1000 * pos / durSec));
  109. }
  110. int durMin = int(durSec / 60);
  111. durSec -= durMin * 60;
  112. int posMin = int(pos / 60);
  113. pos -= posMin * 60;
  114. _stprintf(buf, TEXT("Title %d - Chapter %d - Time %02d:%04.1lf / %02d:%04.1lf"), title, chapter, posMin, pos, durMin, durSec);
  115. SetDlgItemText(IDC_PREVIEW_TEXT, buf);
  116. }
  117. return S_OK;
  118. }
  119. STDMETHODIMP CPagePreview::raw_NotifyPlaybackEnd()
  120. {
  121. m_slider.SetPos(0);
  122. SetDlgItemText(IDC_PREVIEW_TEXT, TEXT(""));
  123. return S_OK;
  124. }
  125. void CPagePreview::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  126. {
  127. // when user move slider position, try change preview position
  128. double dur = m_preview->GetDuration();
  129. if (dur > 0)
  130. {
  131. m_preview->put_Position(double(m_slider.GetPos()) * dur / 1000);
  132. }
  133. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  134. }