📄 maddialog.cpp
字号:
// MADDialog.cpp : implementation file
//
#include "stdafx.h"
#include "RSIP.h"
#include "MADDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MADDialog dialog
MADDialog::MADDialog(CWnd* pParent /*=NULL*/)
: CDialog(MADDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(MADDialog)
//}}AFX_DATA_INIT
m_aLessImgArray.RemoveAll();
m_aMoreImgArray.RemoveAll();
m_nLessImgCount = 0;
m_nMoreImgCount = 0;
m_nImgWidth = 0;
m_nImgHeight = 0;
}
MADDialog::~MADDialog()
{
CString *pszTemp;
for(int i=0; i<m_nLessImgCount; i++)
{
pszTemp = (CString *)(m_aLessImgArray[i]);
delete pszTemp;
}
m_aLessImgArray.RemoveAll();
for(int j=0; j<m_nMoreImgCount; j++)
{
pszTemp = (CString *)(m_aMoreImgArray[j]);
delete pszTemp;
}
m_aMoreImgArray.RemoveAll();
}
void MADDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MADDialog)
DDX_Control(pDX, IDC_MORE_LIST, m_moreList);
DDX_Control(pDX, IDC_LESS_LIST, m_lessList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MADDialog, CDialog)
//{{AFX_MSG_MAP(MADDialog)
ON_BN_CLICKED(IDC_MORE_ADD, OnMoreAdd)
ON_BN_CLICKED(IDC_MORE_DELETE, OnMoreDelete)
ON_BN_CLICKED(IDC_MORE_RESET, OnMoreReset)
ON_BN_CLICKED(IDC_LESS_ADD, OnLessAdd)
ON_BN_CLICKED(IDC_LESS_DELETE, OnLessDelete)
ON_BN_CLICKED(IDC_LESS_RESET, OnLessReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MADDialog message handlers
void MADDialog::OnMoreAdd()
{
CFileDialog fileDlg(TRUE,"*.DAT",NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
"Image Files(*.dat)|*.dat||",this);
char lpstrFile[2048];
lpstrFile[0]='\0';
fileDlg.m_ofn.lpstrFile=lpstrFile;
fileDlg.m_ofn.nMaxFile=2048;
if ( fileDlg.DoModal() == IDOK )
{
POSITION pos = fileDlg.GetStartPosition();
while ( pos != NULL )
{
CString * lpstrPathName = new CString();
*lpstrPathName = fileDlg.GetNextPathName( pos );
if(m_nMoreImgCount == 0)
{
CString szInfFileName;
CFile infFile;
lpstrPathName->TrimLeft();
lpstrPathName->TrimRight();
szInfFileName = lpstrPathName->Left(lpstrPathName->GetLength()-4) + ".inf";
if(0 != infFile.Open(szInfFileName,CFile::modeRead))
{
infFile.Seek(2*sizeof(DWORD)+sizeof(int)+258,CFile::begin);
infFile.Read(&m_nImgWidth,sizeof(int));
infFile.Read(&m_nImgHeight,sizeof(int));
infFile.Close();
}
CFile File;
if(0 == File.Open(*lpstrPathName,CFile::modeRead))
{
MessageBox("打不开数据文件!",
"错误",
MB_OK|MB_ICONINFORMATION);
delete lpstrPathName;
return;
}
if(File.GetLength() != m_nImgWidth * m_nImgHeight)
{
MessageBox("文件大小不匹配!",
"错误",
MB_OK|MB_ICONINFORMATION);
File.Close();
delete lpstrPathName;
return;
}
File.Close();
}
else
{
CFile File;
if(0 == File.Open(*lpstrPathName,CFile::modeRead))
{
MessageBox("打不开数据文件!",
"错误",
MB_OK|MB_ICONINFORMATION);
delete lpstrPathName;
return;
}
if(File.GetLength() != m_nImgWidth*m_nImgHeight)
{
MessageBox("文件大小不匹配!",
"错误",
MB_OK|MB_ICONINFORMATION);
File.Close();
delete lpstrPathName;
return;
}
File.Close();
}
m_moreList.AddString(*lpstrPathName);
m_moreList.SetCurSel(m_nMoreImgCount);
m_aMoreImgArray.Add(lpstrPathName);
m_nMoreImgCount ++;
}
}
}
void MADDialog::OnMoreDelete()
{
int nCurSel = m_moreList.GetCurSel();
if(nCurSel < 0)
return;
CString *pszTemp;
pszTemp = (CString *)(m_aMoreImgArray[nCurSel]);
delete pszTemp;
m_aMoreImgArray.RemoveAt(nCurSel);
m_moreList.DeleteString(nCurSel);
m_moreList.SetCurSel(0);
m_nMoreImgCount --;
}
void MADDialog::OnMoreReset()
{
CString *pszTemp;
for(int i=0;i<m_nMoreImgCount;i++)
{
pszTemp = (CString *)(m_aMoreImgArray[i]);
delete pszTemp;
}
m_aMoreImgArray.RemoveAll();
m_nMoreImgCount = 0;
m_moreList.ResetContent();
m_nImgHeight = 0;
m_nImgWidth = 0;
}
void MADDialog::OnLessAdd()
{
CFileDialog fileDlg(TRUE,"*.DAT",NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
"Image Files(*.dat)|*.dat||",this);
char lpstrFile[2048];
lpstrFile[0]='\0';
fileDlg.m_ofn.lpstrFile=lpstrFile;
fileDlg.m_ofn.nMaxFile=2048;
if ( fileDlg.DoModal() == IDOK )
{
POSITION pos = fileDlg.GetStartPosition();
while ( pos != NULL )
{
CString * lpstrPathName = new CString();
*lpstrPathName = fileDlg.GetNextPathName( pos );
if(m_nLessImgCount == 0)
{
CString szInfFileName;
CFile infFile;
lpstrPathName->TrimLeft();
lpstrPathName->TrimRight();
szInfFileName = lpstrPathName->Left(lpstrPathName->GetLength()-4) + ".inf";
if(0 != infFile.Open(szInfFileName,CFile::modeRead))
{
infFile.Seek(2*sizeof(DWORD)+sizeof(int)+258,CFile::begin);
infFile.Read(&m_nImgWidth,sizeof(int));
infFile.Read(&m_nImgHeight,sizeof(int));
infFile.Close();
}
CFile File;
if(0 == File.Open(*lpstrPathName,CFile::modeRead))
{
MessageBox("打不开数据文件!",
"错误",
MB_OK|MB_ICONINFORMATION);
delete lpstrPathName;
return;
}
if(File.GetLength() != m_nImgWidth * m_nImgHeight)
{
MessageBox("文件大小不匹配!",
"错误",
MB_OK|MB_ICONINFORMATION);
File.Close();
delete lpstrPathName;
return;
}
File.Close();
}
else
{
CFile File;
if(0 == File.Open(*lpstrPathName,CFile::modeRead))
{
MessageBox("打不开数据文件!",
"错误",
MB_OK|MB_ICONINFORMATION);
delete lpstrPathName;
return;
}
if(File.GetLength() != m_nImgWidth*m_nImgHeight)
{
MessageBox("文件大小不匹配!",
"错误",
MB_OK|MB_ICONINFORMATION);
File.Close();
delete lpstrPathName;
return;
}
File.Close();
}
m_lessList.AddString(*lpstrPathName);
m_lessList.SetCurSel(m_nLessImgCount);
m_aLessImgArray.Add(lpstrPathName);
m_nLessImgCount ++;
}
}
}
void MADDialog::OnLessDelete()
{
int nCurSel = m_lessList.GetCurSel();
if(nCurSel < 0)
return;
CString *pszTemp;
pszTemp = (CString *)(m_aLessImgArray[nCurSel]);
delete pszTemp;
m_aLessImgArray.RemoveAt(nCurSel);
m_lessList.DeleteString(nCurSel);
m_lessList.SetCurSel(0);
m_nLessImgCount --;
}
void MADDialog::OnLessReset()
{
CString *pszTemp;
for(int i=0;i<m_nLessImgCount;i++)
{
pszTemp = (CString *)(m_aLessImgArray[i]);
delete pszTemp;
}
m_aLessImgArray.RemoveAll();
m_nLessImgCount = 0;
m_lessList.ResetContent();
m_nImgHeight = 0;
m_nImgWidth = 0;
}
void MADDialog::OnOK()
{
if( m_nLessImgCount > m_nMoreImgCount ||
m_nLessImgCount <= 0 )
{
MessageBox("请按对话框中的提示输入参数",
"错误",
MB_OK|MB_ICONINFORMATION);
return;
}
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -