| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- // PagePreview.cpp : implementation file
- //
- #include "stdafx.h"
- #include "NVAPIExample.h"
- #include "NVAPIExampleDlg.h"
- #include "PagePreview.h"
- #include "PageData.h"
- #include "Sheet.h"
- #include "math.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPagePreview dialog
- CPagePreview::CPagePreview(CSheet * pParent)
- : CPage(CPagePreview::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPagePreview)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_preview = 0;
- }
- void CPagePreview::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPagePreview)
- DDX_Control(pDX, IDC_PREVIEW_SLIDER, m_slider);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPagePreview, CDialog)
- //{{AFX_MSG_MAP(CPagePreview)
- ON_WM_HSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPagePreview message handlers
- bool CPagePreview::Create (void)
- {
- // This is a CPage virtual function. Just create the dialog and return
- // success.
- //
- return CDialog::Create (m_lpszTemplateName, m_pParentWnd) != FALSE;
- }
- bool CPagePreview::OnBack (void)
- {
- // go back to first page
- CNVAPIExampleDlg * pParentSheet = (CNVAPIExampleDlg *) GetParent();
- if (pParentSheet)
- pParentSheet->SwitchPage(0);
- return true;
- }
- void CPagePreview::OnChangeState (bool bActivate, bool bForward)
- {
- // always preview all title, because there is no way to unselect item in a tree view
- if (bForward)
- {
- CPageData * pPageData = GetPageData ();
- if (pPageData)
- {
- // prepare preview struct
- BOOL bSuccess = pPageData->m_pProject->SetXMLString ((LPSTR)(LPCSTR) pPageData->m_sXML);
- if (bSuccess)
- {
- m_preview->SetPreviewContext(pPageData->m_pProject, (wchar_t*)0);
- NeroVisionAPI::IErrorPtr err = m_preview->LastError;
- if (err->ErrCode != NeroVisionAPI::NoError)
- MessageBox(err->ErrText);
- // set preview window
- RECT previewRect;
- CWnd* frame = GetDlgItem(IDC_PREVIEWFRAME);
- if (frame) {
- frame->GetClientRect(&previewRect);
- m_preview->SetPreviewWindow((long)frame->GetSafeHwnd(), previewRect.left, previewRect.top, previewRect.right, previewRect.bottom);
- m_preview->StartPreview();
- m_preview->BackgroundColor = RGB(0, 0, 32);
- m_preview->Callback = this;
- UpdateWindow();
- }
- }
- }
- }
- else
- {
- // stop preview before leave the page
- m_preview->StopPreview();
- }
- }
- BOOL CPagePreview::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- if (FAILED(m_preview.CreateInstance(__uuidof(NeroVisionAPI::Preview))))
- m_preview = 0;
- m_slider.SetRange(0, 1000);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- STDMETHODIMP CPagePreview::raw_NotifyPosChanged(double pos, int title, int chapter)
- {
- TCHAR buf[100];
- // show time and position of the playing title
- double durSec = m_preview->GetDuration();
- if (fabs(pos) > 0.01 && long(durSec / pos) < 1000) {
- // wrong value send by IPreview when viewing menu
- if (m_setSlider)
- {
- m_slider.SetPos(long(1000 * pos / durSec));
- }
- int durMin = int(durSec / 60);
- durSec -= durMin * 60;
- int posMin = int(pos / 60);
- pos -= posMin * 60;
- _stprintf(buf, TEXT("Title %d - Chapter %d - Time %02d:%04.1lf / %02d:%04.1lf"), title, chapter, posMin, pos, durMin, durSec);
- SetDlgItemText(IDC_PREVIEW_TEXT, buf);
- }
- return S_OK;
- }
- STDMETHODIMP CPagePreview::raw_NotifyPlaybackEnd()
- {
- m_slider.SetPos(0);
- SetDlgItemText(IDC_PREVIEW_TEXT, TEXT(""));
- return S_OK;
- }
- void CPagePreview::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // when user move slider position, try change preview position
- double dur = m_preview->GetDuration();
- if (dur > 0)
- {
- m_preview->put_Position(double(m_slider.GetPos()) * dur / 1000);
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
|