📄 progress.cpp
字号:
// Progress.cpp : implementation file
//
#include "stdafx.h"
#include "RelCtrl.h"
#include "Progress.h"
#include "MyStream.h"
#include "cdAPI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef GETERRORID
#define GETERRORID( x ) (cdERROR_ERRORID_MASK&x)
#endif
/////////////////////////////////////////////////////////////////////////////
// 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);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProgress, CDialog)
//{{AFX_MSG_MAP(CProgress)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProgress Internal function
/* The definition of the callback function for progress */
cdUInt32 cdSTDCALL CProgress::ReleaseProgressFunc( cdUInt32 Progress,
cdProgressStatus Status,
cdContext Context )
{
CProgress *CpThis;
CpThis = (CProgress*)Context;
CpThis->SetProgressPos( Progress );
return cdOK;
}
/* The function performed by the thread */
UINT CProgress::ReleaseThreadProc( LPVOID lpParameter )
{
cdStgMedium MyMedium;
cdReleaseImageInfo RelImgInfo;
char szFileName[MAX_PATH],szExt[MAX_PATH],szPrefix[MAX_PATH];
static int i=0;
CProgress *CpThis;
cdUInt32 NumData;
cdStream FilStream;
CpThis = (CProgress*)lpParameter;
for( NumData=CpThis->m_NumData; NumData>0; NumData--, i++ )
{
/* A preservation file name is decided. */
if( CDGetReleasedData( CpThis->m_hSource,
NULL,
0,
0,
&RelImgInfo,
NULL ) != cdOK )
{
break;
}
switch( RelImgInfo.DataType )
{
case cdDATA_TYPE_THUMBNAIL:
strcpy(szPrefix, "TH");
strcpy(szExt, "JPG");
break;
case cdDATA_TYPE_PICTURE:
strcpy(szPrefix, "FV");
if(RelImgInfo.Format == 1)
{
strcpy(szExt, "JPG");
}
else
{
strcpy(szExt, "CRW");
}
break;
case cdDATA_TYPE_PLUS_JPEG:
strcpy(szPrefix, "FP");
strcpy(szExt, "JPG");
break;
}
wsprintf( szFileName, "%s%s%06d.%s",
CpThis->m_szSavePath, szPrefix, i, szExt );
/* A stream is initialized. */
CreateMyFilStream( &FilStream, szFileName );
MyMedium.Type = cdMEMTYPE_STREAM;
MyMedium.u.pStream = &FilStream;
/* Data is acquired. */
CpThis->m_LastErr = CDGetReleasedData( CpThis->m_hSource,
ReleaseProgressFunc,
(cdContext)CpThis,
cdPROG_REPORT_PERIODICALLY,
&RelImgInfo,
&MyMedium );
/* A stream is released. */
ReleaseMyFilStream( &FilStream );
if( GETERRORID(CpThis->m_LastErr) != cdOK )
{
break;
}
}
CpThis->PostMessage( CpThis->m_ThreadEndMessage );
return 0;
}
void CProgress::SetProgressPos( int iPos )
{
m_CProgress.SetPos( iPos );
}
BOOL CProgress::GetReleaseData( cdHSource hSource,
cdUInt32 NumData,
char *szSavePath )
{
/* Data is set. */
m_hSource = hSource;
m_NumData = NumData;
strcpy( m_szSavePath, szSavePath );
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
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);
}
BOOL CProgress::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_LastErr = cdOK;
/* Progress control is changed the first stage. */
m_CProgress.SetRange( 0, 100 );
SetProgressPos( 0 );
/* Negatives are Release using a thread. */
AfxBeginThread( (AFX_THREADPROC)ReleaseThreadProc,
(LPVOID)this );
return TRUE; // return TRUE unless you set the focus to a control
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -