ImageProcessingDoc.cpp
资源名称:图像识别.rar [点击查看]
上传用户:xjt2008yy
上传日期:2010-01-18
资源大小:272k
文件大小:4k
源码类别:
生物技术
开发平台:
Visual C++
- // ImageProcessingDoc.cpp : implementation of the CImageProcessingDoc class
- //
- #include "stdafx.h"
- #include "ImageProcessing.h"
- #include "ImageProcessingDoc.h"
- #include "GlobalApi.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CImageProcessingDoc
- IMPLEMENT_DYNCREATE(CImageProcessingDoc, CDocument)
- BEGIN_MESSAGE_MAP(CImageProcessingDoc, CDocument)
- //{{AFX_MSG_MAP(CImageProcessingDoc)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- ON_COMMAND(ID_FILE_RELOAD, OnFileReload)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CImageProcessingDoc construction/destruction
- CImageProcessingDoc::CImageProcessingDoc()
- {
- // TODO: add one-time construction code here
- InitDocVariable();
- }
- CImageProcessingDoc::~CImageProcessingDoc()
- {
- FreeDocVariable();
- }
- BOOL CImageProcessingDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageProcessingDoc serialization
- void CImageProcessingDoc::Serialize(CArchive& ar)
- {
- m_pDibInit->Serialize(ar);
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageProcessingDoc diagnostics
- #ifdef _DEBUG
- void CImageProcessingDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CImageProcessingDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CImageProcessingDoc commands
- int CImageProcessingDoc::InitDocVariable()
- {
- m_pDibInit = new CDib;
- // added by tanhc in 2002-7-30, used to test some function
- m_pDibTest = new CDib;
- m_nColorIndex = 0;
- //--------------------------------------------
- return 0;
- }
- int CImageProcessingDoc::FreeDocVariable()
- {
- delete m_pDibInit;
- m_pDibInit = NULL;
- // added by tanhc in 2002-7-30, used to test some function
- delete m_pDibTest ;
- m_pDibTest = NULL ;
- //--------------------------------------------
- return 0;
- }
- void CImageProcessingDoc::OnFileSaveAs()
- {
- // TODO: Add your command handler code here
- CString strSaveFileType = "位图文件 (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
- CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strSaveFileType);
- CFile fileOpen ;
- if( FileDlg.DoModal() == IDOK ) {
- if(!fileOpen.Open( FileDlg.GetPathName() , CFile::modeCreate|CFile::modeWrite )){
- AfxMessageBox("cannot create the file to save");
- return;
- }
- if( !m_pDibInit->Write( &fileOpen ) ){
- return;
- }
- fileOpen.Close();
- }
- }
- /*************************************************************************
- *
- * 函数名称:
- * OnFileReload()
- *
- * 输入参数:
- * 无
- *
- * 返回值:
- * 无
- *
- * 说明:
- * 该函数响应ID_FILE_RELOAD点击的消息,并重载DIB
- *
- *************************************************************************
- */
- void CImageProcessingDoc::OnFileReload()
- {
- // 判断当前图像是否已经被改动
- if (IsModified())
- {
- // 提示用户该操作将丢失所有当前的修改
- if (MessageBox(NULL, "重新打开图像将丢失所有改动!是否继续?", "系统提示", MB_ICONQUESTION | MB_YESNO) == IDNO)
- {
- // 用户取消操作,直接返回
- return;
- }
- }
- CFile file;
- CString strPathName;
- CFileException fe;
- strPathName = GetPathName();
- // 重新打开文件
- if( !file.Open(strPathName, CFile::modeRead | CFile::shareDenyWrite, &fe))
- {
- // 失败
- ReportSaveLoadException(strPathName, &fe, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
- // 返回
- return;
- }
- // 更改光标
- BeginWaitCursor();
- // 重新读取图象
- if(!m_pDibInit->Read(&file)){
- // 恢复光标形状
- EndWaitCursor();
- // 返回
- return;
- }
- // 初始化胀标记为FALSE
- SetModifiedFlag(FALSE);
- // 刷新
- UpdateAllViews(NULL);
- // 恢复光标形状
- EndWaitCursor();
- // 返回
- return;
- }