rawdevelopdlg.cpp
来自「canon 相机SDK,非常难得」· C++ 代码 · 共 1,977 行 · 第 1/4 页
CPP
1,977 行
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
cdError err;
m_hSource = NULL;
m_DevFaculty = 0;
m_hCallbackFunction = NULL;
m_CDevelop.EnableWindow( FALSE );
m_CDisconnect.EnableWindow( FALSE );
InitDevelopControl();
DisableDevelopControl();
/* CDSDK is changed the first stage. */
cdVersionInfo SVersion;
memset( &SVersion, 0, sizeof(cdVersionInfo) );
SVersion.Size = sizeof(cdVersionInfo);
SVersion.MajorVersion = 6;
SVersion.MinorVersion = 1;
err = CDStartSDK( &SVersion, 0 );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
return TRUE; // return TRUE unless you set the focus to a control
camerr:
char szErrStr[256];
wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
MessageBox( szErrStr );
EndDialog( 1 );
return FALSE;
}
void CRawDevelopDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRawDevelopDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRawDevelopDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRawDevelopDlg::OnConnect()
{
// TODO: Add your control notification handler code here
cdError err;
cdSourceInfo SSrcInfo;
CComSettingDlg* pComSettingDialog = new CComSettingDlg(this);
pComSettingDialog->SelectSource(&SSrcInfo);
delete pComSettingDialog;
if(SSrcInfo.SurceType == cdSRC_TYPE_INVALID) return;
/* A device is opened. */
err = CDOpenSource( &SSrcInfo, &m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
/* UI is locked so that information may not be changed. */
err = CDLockUI( m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
/* The function which receives the event from a camera is set up. */
err = CDRegisterEventCallbackFunction( m_hSource, CamCallBackFunc, (cdContext)this, &m_hCallbackFunction );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
/* Volumes are enumerated. */
cdHEnum hEnumVol;
cdHVolume hVolume;
cdHItem hItem;
cdVolumeInfo SVolInfo;
err = CDEnumVolumeReset( m_hSource, &hEnumVol );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
/* Volume including a DCIM directory is searched. */
while( (err = CDEnumVolumeNext( hEnumVol, &hVolume )) == cdOK )
{
/* The existence of memory card is checked. */
err = CDGetVolumeInfo( hVolume, &SVolInfo );
if( GETERRORID(err) != cdOK )
{
CDEnumVolumeRelease( hEnumVol );
goto camerr;
}
if( SVolInfo.TotalSpace )
{
/* A DCIM directory is searched. */
err = FindDCIMdirectory( hVolume, &hItem );
if( GETERRORID(err) != cdOK )
{
CDEnumVolumeRelease( hEnumVol );
goto camerr;
}
/* It investigates whether the handle of a DCIM directory was acquirable. */
if( hItem != NULL )
{
break;
}
}
}
if( GETERRORID(err) == cdENUM_NA )
{
MessageBox( "A DCIM directory was not found." );
CDEnumVolumeRelease( hEnumVol );
return;
}
else if( GETERRORID(err) != cdOK )
{
CDEnumVolumeRelease( hEnumVol );
goto camerr;
}
/* Listing of volume is ended. */
err = CDEnumVolumeRelease( hEnumVol );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
m_CFile.ResetContent();
/* The items in a DCIM directory are enumerated. */
cdHEnum hEnumImage;
cdHImageItem hImage;
cdItemInfo SItemInfo;
int index;
cdHEnum hEnumItemProp;
cdUInt32 BufSize;
cdBoolean fDevlop;
err = CDEnumImageItemReset( hItem, 2, cdENUM_HAS_THUMBNAIL, &hEnumImage );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
index = 0;
while( (err = CDEnumImageItemNext( hEnumImage, &hImage )) == cdOK )
{
/* The information on an image is acquired. */
err = CDGetItemInfo( hImage, &SItemInfo );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
goto camerr;
}
/* It checks in an image item. */
if( SItemInfo.Type&cdITEM_TYPE_IMAGE_ITEM )
{
/* It investigates in the image in which development is possible. */
err = CDOpenImage( hImage );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
goto camerr;
}
err = CDEnumImageItemPropertyReset( hImage, &hEnumItemProp );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
CDCloseImage( hImage );
goto camerr;
}
BufSize = sizeof(cdBoolean);
fDevlop = FALSE;
err = CDGetImageItemProperty( hImage,
cdIMG_PROP_PICT_NEED_DEVELOP,
&BufSize,
&fDevlop );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
CDCloseImage( hImage );
goto camerr;
}
err = CDEnumImageItemPropertyRelease( hEnumItemProp );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
CDCloseImage( hImage );
goto camerr;
}
err = CDCloseImage( hImage );
if( GETERRORID(err) != cdOK )
{
CDEnumItemRelease( hEnumImage );
goto camerr;
}
/* Only the file in which development is possible is displayed on a list. */
if( fDevlop )
{
m_CFile.AddString( SItemInfo.Name );
/* The handle of an item is related with the list box. */
m_CFile.SetItemData( index, hImage );
index++;
}
}
}
if( GETERRORID(err) != cdENUM_NA )
{
CDEnumItemRelease( hEnumImage );
goto camerr;
}
err = CDEnumImageItemRelease( hEnumImage );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
/* The lock of UI is canceled. */
err = CDUnlockUI( m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
if( m_CFile.GetCount() == 0)
{
m_CFile.AddString("There are no RAW images in the camera");
}
else
{
m_CDevelop.EnableWindow( TRUE );
}
m_CConnect.EnableWindow( FALSE );
m_CDisconnect.EnableWindow( TRUE );
return;
camerr:
char szErrStr[256];
wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
MessageBox( szErrStr );
if( m_hSource )
{
CDCloseSource( m_hSource );
m_hSource = NULL;
}
}
void CRawDevelopDlg::OnEnd()
{
// TODO: Add your control notification handler code here
cdError err;
if( m_hSource )
{
if( m_hCallbackFunction )
{
/* The function which receives the event from a camera is canceled. */
err = CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
m_hCallbackFunction = NULL;
}
/* A device is closed. */
err = CDCloseSource( m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
m_hSource = NULL;
}
m_CDisconnect.EnableWindow( FALSE );
m_CDevelop.EnableWindow( FALSE );
m_CConnect.EnableWindow( TRUE );
DisableDevelopControl();
EndDialog( 0 );
return;
camerr:
char szErrStr[256];
wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
MessageBox( szErrStr );
if( m_hSource )
{
if( m_hCallbackFunction )
{
CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
m_hCallbackFunction = NULL;
}
CDCloseSource( m_hSource );
m_hSource = NULL;
}
EndDialog( 0 );
}
void CRawDevelopDlg::OnDisconnect()
{
// TODO: Add your control notification handler code here
cdError err;
m_CFile.ResetContent();
if( m_hSource )
{
if( m_hCallbackFunction )
{
/* The function which receives the event from a camera is canceled. */
err = CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
m_hCallbackFunction = NULL;
}
/* A device is closed. */
err = CDCloseSource( m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
}
m_hSource = NULL;
}
m_CDisconnect.EnableWindow( FALSE );
m_CDevelop.EnableWindow( FALSE );
m_CConnect.EnableWindow( TRUE );
DisableDevelopControl();
return;
camerr:
char szErrStr[256];
wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
MessageBox( szErrStr );
}
void CRawDevelopDlg::OnDevelop()
{
// TODO: Add your control notification handler code here
cdError err;
cdHImageItem hImage;
cdHImageData hImgData;
char szPath[MAX_PATH];
char *pFormatList[4] = { "Jpeg Files (*.jpg)|*.jpg|All Files (*.*)|*.*||",
"Tiff Files (*.tif)|*.tif|All Files (*.*)|*.*||",
"RAW Files (*.raw)|*.raw|All Files (*.*)|*.*||",
"All Files (*.*)|*.*||" };
char *pExtensionList[3] = {"jpg","tif","raw"};
char *cpFormat;
char *cpExtension;
CProgress CPrg;
BOOL fRes;
hImage = (cdHImageItem)m_CFile.GetItemData( m_CFile.GetCurSel() );
if(!hImage) return;
/* Preservation form is acquired. */
cdImageFormat destFormat;
destFormat = (cdImageFormat)m_CFormat.GetItemData( m_CFormat.GetCurSel() );
switch( destFormat )
{
case cdFORMAT_JPEG_DCF:
cpFormat = pFormatList[0];
cpExtension = pExtensionList[0];
break;
case cdFORMAT_TIFF_DCF:
case cdFORMAT_TIFF_16:
cpFormat = pFormatList[1];
cpExtension = pExtensionList[1];
break;
case cdFORMAT_PIXMAP:
case cdFORMAT_PIXMAP_16:
cpFormat = pFormatList[2];
cpExtension = pExtensionList[2];
break;
default:
cpFormat = pFormatList[3];
cpExtension = NULL;
}
CFileDialog CGetPath( FALSE,
cpExtension,
NULL,
OFN_HIDEREADONLY | OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT,
cpFormat,
this );
/* The path which saves a file is acquired. */
if( CGetPath.DoModal() != IDOK )
{
return;
}
CString CSavePath;
CSavePath = CGetPath.GetPathName();
strcpy( szPath, CSavePath );
/* UI is locked so that information may not be changed. */
err = CDLockUI( m_hSource );
if( GETERRORID(err) != cdOK )
{
goto camerr;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?