⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagefirst.cpp

📁 Nero刻录工具的插件编程SDK
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
|* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|* PARTICULAR PURPOSE.
|* 
|* Copyright 1995-2004 Ahead Software AG. All Rights Reserved.
|*-----------------------------------------------------------------------------
|* NeroSDK / NVAPIExample
|*
|* PROGRAM: PageFirst.cpp
|*
|* PURPOSE: Implementation of the first page.
******************************************************************************/

#include "stdafx.h"
#include "NVAPIExample.h"
#include "PageFirst.h"
#include "PageData.h"
#include "Sheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// This is our custom message.
// 
#define UM_QUIT_WITH_DELAY		(WM_APP + 1)


CPageFirst::CPageFirst(CSheet * pParent)
	: CPage(CPageFirst::IDD, pParent)
	, m_iVideoItemSequence (1)
	, m_iSlideshowItemSequence (1)
{
	//{{AFX_DATA_INIT(CPageFirst)
	m_iProjectType = 0;
	//}}AFX_DATA_INIT
}


void CPageFirst::DoDataExchange(CDataExchange* pDX)
{
	CPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageFirst)
	DDX_Control(pDX, IDC_SAVE, c_Save);
	DDX_Control(pDX, IDC_REMOVE, c_Remove);
	DDX_Control(pDX, IDC_PROJECT_TYPE, c_ProjectType);
	DDX_Control(pDX, IDC_LOAD, c_Load);
	DDX_Control(pDX, IDC_INSERT_VIDEO, c_InsertVideo);
	DDX_Control(pDX, IDC_INSERT_SLIDE, c_InsertSlide);
	DDX_Control(pDX, IDC_INSERT_IMAGE, c_InsertImage);
	DDX_Control(pDX, IDC_TRANSITION_TYPE, c_TransitionType);
	DDX_Control(pDX, IDC_CONTENT, c_Content);
	DDX_CBIndex(pDX, IDC_PROJECT_TYPE, m_iProjectType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageFirst, CPage)
//{{AFX_MSG_MAP(CPageFirst)
	ON_BN_CLICKED(IDC_LOAD, OnLoad)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_INSERT_VIDEO, OnInsertVideo)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	ON_BN_CLICKED(IDC_INSERT_SLIDE, OnInsertSlide)
	ON_NOTIFY(TVN_SELCHANGED, IDC_CONTENT, OnSelchangedContent)
	ON_CBN_SELCHANGE(IDC_TRANSITION_TYPE, OnSelchangeTransitionType)
	ON_BN_CLICKED(IDC_INSERT_IMAGE, OnInsertImage)
	ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_CONTENT, OnBeginlabeleditContent)
	//}}AFX_MSG_MAP
	ON_MESSAGE(UM_QUIT_WITH_DELAY, OnQuitWithDelay)
END_MESSAGE_MAP()

BOOL CPageFirst::OnInitDialog() 
{
	CPage::OnInitDialog();

	// On the first update, set the proper state of controls.
	// 
	UpdateControls ();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

bool CPageFirst::Create (void)
{
	// This is a CPage virtual function. Just create the dialog and return
	// success.
	// 
	return CDialog::Create (m_lpszTemplateName, m_pParentWnd) != FALSE;
}

bool CPageFirst::OnNext (void)
{
	// This method will be called whenever a main window's Next button is
	// clicked. We can use it to override the default behavior by returning
	// true.
	// 
	IXMLDOMDocumentPtr pDocument = BuildXML ();

	if (pDocument != NULL)
	{
		// If XML was built successfully, set it to the common page
		// data and let the default behavior of the button switch
		// to the next page.
		// 
		USES_CONVERSION;
		GetPageData ()->m_sXML = W2CA (pDocument->xml);

		return false;
	}
	else
	{
		// If there was an error building XML, report it and don't
		// switch to the next page.
		// 
		AfxMessageBox (IDS_ERROR_BUILDING_XML);

		return true;
	}
}

void CPageFirst::OnChangeState (bool bActivate, bool bForward)
{
	if (bActivate && bForward)
	{
		// If we are activated in the forward direction (normally only
		// once at the beginning), check if project object was
		// successfully created. If not, fail miserably as we can't
		// proceed without it. We will actually post a message to ourselves
		// to delay the quitting and to allow the main window to be
		// displayed.
		// 
		if (GetPageData ()->m_pProject == NULL)
		{
			PostMessage (UM_QUIT_WITH_DELAY);
		}
	}
}

LRESULT CPageFirst::OnQuitWithDelay (WPARAM wParam, LPARAM lParam)
{
	// This handler will be called if NeroVisionAPI's Project object
	// could not have been created. We can't do anything but quit.
	// 
	AfxMessageBox (IDS_ERROR_INITIALIZING_NERO_VISION_API);
	PostQuitMessage (0);

	return 0;
}

void CPageFirst::OnLoad() 
{
	// This is a Load handler. Ask for a file to load.
	// 
	CString sFilter;
	sFilter.LoadString (IDS_XML_FILES_FILTER);
	CFileDialog dlg (TRUE, "xml", NULL,
		OFN_EXPLORER|OFN_HIDEREADONLY,
		sFilter, this);
	
	if (IDOK == dlg.DoModal ())
	{
		// If ok was clicked, create an instance of XML document and
		// load the document. If loaded successfully, parse the XML file
		// and fill the dialog controls accordingly.
		// 
		try
		{
			// Create object instance...
			// 
			IXMLDOMDocumentPtr pDocument;
			EVAL_HR (pDocument.CreateInstance ("Msxml2.DOMDocument.3.0"));

			// Load the document...
			// 
			VARIANT_BOOL bSuccess;
			bSuccess = pDocument->load ((LPCSTR) dlg.GetPathName ());
			EVAL_HR (bSuccess? S_OK: E_FAIL);

			// Parse the document...
			// 
			ParseXMLDocument (pDocument);
		}
		catch (...)
		{
			// If an error occurs, delete everything and display an error.
			// 
			c_Content.DeleteAllItems ();
			AfxMessageBox (IDS_ERROR_LOADING_XML);
		}

		// No matter if the document is loaded successfully or not,
		// update the controls to reflect the new state.
		// 
		UpdateControls ();
	}
}

void CPageFirst::OnSave() 
{
	// This is the save XML handler.
	// 
	IXMLDOMDocumentPtr pDocument;

	// Build the XML from the project settings.
	// 
	pDocument = BuildXML ();

	if (pDocument == NULL)
	{
		// If ther is an error, notify the user.
		// 
		AfxMessageBox (IDS_ERROR_BUILDING_XML);
	}
	else
	{
		// If no error, ask the user for a filename to save the XML to.
		// 
		CString sFilter;
		sFilter.LoadString (IDS_XML_FILES_FILTER);
		CFileDialog dlg (FALSE, "xml", NULL,
			OFN_HIDEREADONLY|OFN_EXPLORER|OFN_OVERWRITEPROMPT,
			sFilter, this);
		
		if (IDOK == dlg.DoModal ())
		{
			// If filename is given, use the document's save method to save
			// the XML to a file.
			// 
			try
			{
				EVAL_HR (pDocument->save ((LPCSTR) dlg.GetPathName ()));
			}
			catch (...)
			{
				// Display a message on error.
				// 
				AfxMessageBox (IDS_ERROR_SAVING_XML);
			}
		}
	}
}


void CPageFirst::OnInsertVideo() 
{
	// This is a handler to insert video to project. Ask for a video
	// filename.
	// 
	CString sFilter;
	sFilter.LoadString (IDS_VIDEO_FILES_FILTER);
	CFileDialog dlg (TRUE, NULL, NULL,
		OFN_EXPLORER|OFN_HIDEREADONLY,
		sFilter, this);
	
	if (IDOK == dlg.DoModal ())
	{
		// If video file is selected insert it into project.
		// 
		CString sFormat;
		CString sVideoItemName;
		sFormat.LoadString (IDS_VIDEO_TITLE_FORMAT);
		sVideoItemName.Format (sFormat, m_iVideoItemSequence++);
	
		InsertVideo (sVideoItemName, dlg.GetPathName ());

		// After insertion, update the controls.
		// 
		UpdateControls ();
	}
}

void CPageFirst::InsertVideo (LPCSTR psVideoItemName, LPCSTR psPath)
{
	// This method inserts the video into the project (tree ctrl).
	// 
	HTREEITEM hVideoItem = c_Content.InsertItem (psVideoItemName, 0, 0);
	
	c_Content.InsertItem (psPath, 0, 0, hVideoItem);
	c_Content.SetItemData (hVideoItem, CONTENTTYPE::VIDEOTITLE);
	
	c_Content.Expand (hVideoItem, TVE_EXPAND);
}

void CPageFirst::OnRemove() 
{
	// This is a remove handler. First find the selected tree item.
	// 
	HTREEITEM hSelectedItem = c_Content.GetSelectedItem ();
	
	// If there is one...
	// 
	if (hSelectedItem != NULL)
	{
		// Find the root item of the selected item.
		// 
		for (HTREEITEM hParentItem = hSelectedItem;
			hParentItem != NULL;
			hSelectedItem = hParentItem, hParentItem = c_Content.GetParentItem (hSelectedItem))
				;
		
		// Now remove it...
		// 
		c_Content.DeleteItem (hSelectedItem);
		
		UpdateControls ();
	}
}

void CPageFirst::OnInsertSlide() 
{
	// This method inserts an image into the project (tree ctrl) along
	// with the two transitions (one before and one after the image).
	// 
	CString sFilter;
	sFilter.LoadString (IDS_IMAGE_FILES_FILTER);
	CFileDialog dlg (TRUE, NULL, NULL,
		OFN_EXPLORER|OFN_HIDEREADONLY,
		sFilter, this);
	
	if (IDOK == dlg.DoModal ())
	{
		CString sFormat;
		CString sSlideshowItemName;
		sFormat.LoadString (IDS_SLIDE_SHOW_FORMAT);
		sSlideshowItemName.Format (sFormat, m_iSlideshowItemSequence++);
		
		HTREEITEM hSlideItem = InsertSlideshow (sSlideshowItemName);

		// Insert an "empty" transition before and after the image.
		// 
		InsertTransition (hSlideItem);
		InsertImage (hSlideItem, dlg.GetPathName ());
		InsertTransition (hSlideItem);
		
		c_Content.Expand (hSlideItem, TVE_EXPAND);
		
		UpdateControls ();
	}
}

HTREEITEM CPageFirst::InsertSlideshow (LPCSTR psSlideshowName)
{
	// This is a helper method for inserting a slide show image.
	// 
	HTREEITEM hSlideItem = c_Content.InsertItem (psSlideshowName, 0, 0);
	c_Content.SetItemData (hSlideItem, CONTENTTYPE::SLIDESHOW);

	return hSlideItem;
}

void CPageFirst::InsertTransition (HTREEITEM hSlideItem, CPageFirst::TRANSITION transition)
{
	// This is a helper method for inserting a transition.
	// 
	HTREEITEM hTransition = c_Content.InsertItem ("", 0, 0, hSlideItem);
	ChangeTransition (hTransition, transition);
}

void CPageFirst::InsertImage (HTREEITEM hSlideItem, LPCSTR psImagePath)
{
	// This is a helper method for inserting an image after an initial
	// image has been inserted into a slideshow with InsertSlideshow.
	// 
	HTREEITEM hPathName = c_Content.InsertItem (psImagePath, 0, 0, hSlideItem);
	c_Content.SetItemData (hPathName, TRANSITION::INVALID);
}

void CPageFirst::ChangeTransition (HTREEITEM hItem, const TRANSITION transition)
{
	// This method is used for changing the transition type in the project.
	// First make sure the transition is valid.
	// 
	ASSERT (NONE <= transition && transition <= MOVEOUT);

	CString str;
	CString sFormat;
	CString sTransitionName;
	
	// Get the actual transition name from the combobox. The strings should
	// be in the same order as the TRANSITION enums.
	// 
	c_TransitionType.GetLBText ((int) transition, sTransitionName);
	
	// Get the transition formatting string from the string table and
	// create the final string that we are going to set to this item.
	// 
	sFormat.LoadString (IDS_TRANSITION_FORMAT);
	str.Format (sFormat, sTransitionName);
	
	c_Content.SetItemText (hItem, str);
	c_Content.SetItemData (hItem, transition);
}

void CPageFirst::OnSelchangedContent(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	
	// Every time the selection of tree ctrl changes, update the controls'
	// states.
	// 
	UpdateControls ();
	
	*pResult = 0;
}

void CPageFirst::UpdateControls (void)
{
	// This method updates the controls' states according to the state
	// of the project.
	// 
	HTREEITEM hSelectedItem = c_Content.GetSelectedItem ();

	// Save button should be enabled if there is at least one item in
	// the project tree ctrl (if there is something worth saving).
	// Remove button should be enbled if something is selected.
	// 
	c_Save.EnableWindow (c_Content.GetFirstVisibleItem () != NULL);
	c_Remove.EnableWindow (hSelectedItem != NULL);

	bool bEnableTransitionType = false;
	bool bEnableInsertImage = false;
	HTREEITEM hItemParent = c_Content.GetParentItem (hSelectedItem);
	
	if (hItemParent != NULL)
	{
		// This is the second level of items. See if the parent is a
		// slideshow item.
		// 
		if (c_Content.GetItemData (hItemParent) == CONTENTTYPE::SLIDESHOW)
		{
			// Yes it is a slideshow. Now check to see if the particular
			// item is a transition item.
			// 
			TRANSITION transition = (TRANSITION) c_Content.GetItemData (hSelectedItem);
			bEnableTransitionType = transition != TRANSITION::INVALID;
			if (bEnableTransitionType)
			{
				// Set the transition of the currently selected item.
				// 
				c_TransitionType.SetCurSel ((int) transition);
			}

			bEnableInsertImage = true;
		}
	}
	else
	{
		bEnableInsertImage = hSelectedItem != NULL &&
							c_Content.GetItemData (hSelectedItem) == CONTENTTYPE::SLIDESHOW;
	}

	// Enable transition type combobox and insert image button according
	// to the conditions evaluated previously.
	// 
	c_TransitionType.EnableWindow (bEnableTransitionType);
	c_InsertImage.EnableWindow (bEnableInsertImage);
}

void CPageFirst::OnSelchangeTransitionType() 
{
	// When selection changes in the transition type combo box, update the
	// transition type of the item in the treectrl.
	// 
	HTREEITEM hSelectedItem = c_Content.GetSelectedItem ();
	
	if (hSelectedItem != NULL)
	{
		HTREEITEM hItemParent = c_Content.GetParentItem (hSelectedItem);
		if (hItemParent != NULL)
		{
			if (c_Content.GetItemData (hItemParent) == CONTENTTYPE::SLIDESHOW)
			{
				ChangeTransition (hSelectedItem, (TRANSITION) c_TransitionType.GetCurSel ());
			}
		}
	}
}

void CPageFirst::OnInsertImage() 
{
	// This method inserts an image into the project (tree ctrl) after an
	// initial slideshow has been created with InsertSlideshow.
	// 
	HTREEITEM hSelectedItem = c_Content.GetSelectedItem ();

	if (hSelectedItem != NULL)
	{
		HTREEITEM hParentItem = c_Content.GetParentItem (hSelectedItem);

		if (c_Content.GetItemData (hParentItem != NULL? hParentItem: hSelectedItem) == CONTENTTYPE::SLIDESHOW)
		{
			CString sFilter;
			sFilter.LoadString (IDS_IMAGE_FILES_FILTER);
			CFileDialog dlg (TRUE, NULL, NULL,
				OFN_EXPLORER|OFN_HIDEREADONLY,
				sFilter, this);
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -