progress.cpp

来自「canon 相机SDK,非常难得」· C++ 代码 · 共 163 行

CPP
163
字号
// Progress.cpp : implementation file
//

#include "stdafx.h"
#include "RawDevelop.h"
#include "Progress.h"

#include "cdAPI.h"

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

/* Prototype declaration */
cdUInt32 cdSTDCALL DevelopProgressFunc(	cdUInt32			Progress,
										cdProgressStatus	Status );

/* Global variable definition */
cdUInt32	g_dwRetPrg;


/* The definition of the callback function for progress */
cdUInt32 cdSTDCALL DevelopProgressFunc(	cdUInt32			Progress,
										cdProgressStatus	Status,
										cdContext			Context )
{
	CProgress	*CpThis;
	
	CpThis = (CProgress*)Context;
	CpThis->SetProgressPos( Progress );
	return	g_dwRetPrg;
}

/* The function performed by the thread */
DWORD WINAPI	DevelopThreadProc( LPVOID	lpParameter )
{
	CProgress	*CpThis;
	
	CpThis = (CProgress*)lpParameter;
	CpThis->m_LastErr = CDGetDevelopedImageData(	CpThis->m_hImgData,
													CpThis->m_DestFormat,
													&CpThis->m_StgMediumOut,
													DevelopProgressFunc,
													(cdContext)CpThis,
													cdPROG_REPORT_PERIODICALLY );
	CpThis->PostMessage( CpThis->m_ThreadEndMessage );
	return	0;
}


/////////////////////////////////////////////////////////////////////////////
// CProgress dialog


CProgress::CProgress(CWnd* pParent /*=NULL*/)
	: CDialog(CProgress::IDD, pParent)
{
	//{{AFX_DATA_INIT(CProgress)
	//}}AFX_DATA_INIT
}


void CProgress::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProgress)
	DDX_Control(pDX, IDC_PROGRESS, m_Cprogress);
	DDX_Control(pDX, IDC_BUTTON, m_CCancel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProgress, CDialog)
	//{{AFX_MSG_MAP(CProgress)
	ON_BN_CLICKED(IDC_BUTTON, OnButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CProgress Internal function

void CProgress::SetProgressPos( int	iPos )
{
	m_Cprogress.SetPos( iPos );
}

BOOL	CProgress::StartDevelop(	cdHImageData	hImgData,
									cdImageFormat	destFormat,
									cdUInt32		Type,
									void			*vpParam )
{
	/* Data is set. */
	m_hImgData = hImgData;
	m_DestFormat = destFormat;
	
	m_StgMediumOut.Type = Type;
	if( Type == cdMEMTYPE_FILE )
	{
		m_StgMediumOut.u.lpszFileName = (cdChar*)vpParam;
	}
	else
	{
		m_StgMediumOut.u.pStream = (cdStream*)vpParam;
	}
	
	m_ThreadEndMessage = RegisterWindowMessage( "Information of a thread end" );
	if( m_ThreadEndMessage == 0 )
	{
		return	FALSE;
	}
	
	/* A progress dialog is displayed and developed. */
	if( DoModal() != IDOK )
	{
		return	FALSE;
	}
	
	return	TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CProgress message handlers

void CProgress::OnButton() 
{
	// TODO: Add your control notification handler code here
	g_dwRetPrg = cdOPERATION_CANCELLED;
}

BOOL CProgress::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	g_dwRetPrg = cdOK;
	m_LastErr = cdOK;
	
	/* Progress control is changed the first stage. */
	m_Cprogress.SetRange( 0, 100 );
	SetProgressPos( 0 );
	
	/* Negatives are developed using a thread. */
	AfxBeginThread(	(AFX_THREADPROC)DevelopThreadProc,
					this );
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

LRESULT CProgress::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( m_ThreadEndMessage == message )
	{
		EndDialog( IDOK );
		return	TRUE;
	}
	
	return CDialog::WindowProc(message, wParam, lParam);
}

⌨️ 快捷键说明

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