www.pudn.com > ImageSearch.rar > ImageSearchDoc.cpp


// ImageSearchDoc.cpp :  CImageSearchDoc 类的实现 
// 
 
#include "stdafx.h" 
#include "ImageSearch.h" 
 
#include "ImageSearchDoc.h" 
#include ".\imagesearchdoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif 
 
 
// CImageSearchDoc 
 
IMPLEMENT_DYNCREATE(CImageSearchDoc, CDocument) 
 
BEGIN_MESSAGE_MAP(CImageSearchDoc, CDocument) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	ON_UPDATE_COMMAND_UI(ID_QUERY, OnUpdateQuery) 
	ON_COMMAND(ID_QUERY, OnQuery) 
END_MESSAGE_MAP() 
 
 
// CImageSearchDoc 构造/析构 
 
CImageSearchDoc::CImageSearchDoc() 
{ 
	// TODO: 在此添加一次性构造代码 
	m_strQueryFile.Empty(); 
	m_iShowQueryResult=0; 
	fileopen=0; 
 
} 
 
CImageSearchDoc::~CImageSearchDoc() 
{ 
} 
 
BOOL CImageSearchDoc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
 
	// TODO: 在此添加重新初始化代码 
	// (SDI 文档将重用该文档) 
 
	return TRUE; 
} 
 
 
 
 
// CImageSearchDoc 序列化 
 
void CImageSearchDoc::Serialize(CArchive& ar) 
{ 
	if (ar.IsStoring()) 
	{ 
		// TODO: 在此添加存储代码 
	} 
	else 
	{ 
		// TODO: 在此添加加载代码 
	} 
} 
 
 
// CImageSearchDoc 诊断 
 
#ifdef _DEBUG 
void CImageSearchDoc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CImageSearchDoc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
 
// CImageSearchDoc 命令 
 
void CImageSearchDoc::OnFileOpen() 
{ 
	// TODO: 在此添加命令处理程序代码 
	CFileDialog dlgFile(true); 
 
	CString title,strFilter,strDefault; 
	VERIFY(title.LoadString(AFX_IDS_OPENFILE)); 
 
	//append the *.dat files filter 
	strFilter+=_T("24位位图文件(*.bmp)"); 
	strFilter+=(TCHAR)'\0';			    
	strFilter+=_T("*.bmp"); 
	strFilter+=(TCHAR)'\0';  
	dlgFile.m_ofn.nMaxCustFilter++; 
 
	dlgFile.m_ofn.lpstrFilter=strFilter;  
	dlgFile.m_ofn.lpstrTitle=_T("读取原始图像"); //title; 
	dlgFile.m_ofn.hwndOwner=AfxGetMainWnd()->GetSafeHwnd(); 
 
	BOOL bResult=dlgFile.DoModal(); 
    CWaitCursor waiter; 
	if(bResult==2 ) 
	{ 
		return; 
	} 
	else 
	{ 
	    if(bResult==1) 
	    { 
            // Save the name of selected file 
		    CString strPath=dlgFile.GetPathName(); 
			m_strQueryFile=strPath; 
 
			//open the selected bmp file 
			CFile fp; 
			fp.Open(m_strQueryFile,CFile::modeRead); 
			 
			//load the bmp file 
			m_dibQuery.Load(&fp); 
 
			//add by wanglei 
			fp.Close(); 
			fileopen=1; 
			UpdateAllViews(NULL); 
	    } 
	} 
} 
 
 
void CImageSearchDoc::OnUpdateQuery(CCmdUI *pCmdUI) 
{ 
	// TODO: 在此添加命令更新用户界面处理程序代码 
	if(fileopen==0) 
		pCmdUI->Enable(FALSE); 
	else 
		pCmdUI->Enable(TRUE); 
} 
 
void CImageSearchDoc::OnQuery() 
{ 
	// TODO: 在此添加命令处理程序代码 
	m_iShowQueryResult=1; 
	UpdateAllViews(NULL); 
}