📄 iprocessndoc.cpp
字号:
// IProcessNDoc.cpp : CIProcessNDoc 类的实现
//
#include "stdafx.h"
#include "IProcessN.h"
#include "IProcessNDoc.h"
#include ".\iprocessndoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CImage SaveCanvus,WorkCanvus,img2,img3,img4,img5,img6,img7,img8,WindowCanvus;
CImage* pImg[10];
CString m_FileName;
// CIProcessNDoc
IMPLEMENT_DYNCREATE(CIProcessNDoc, CDocument)
BEGIN_MESSAGE_MAP(CIProcessNDoc, CDocument)
ON_COMMAND(ID_OPEN_IMAGE, OnOpenImage)
ON_COMMAND(ID_SAVE_IMAGE, OnSaveImage)
ON_UPDATE_COMMAND_UI(ID_SAVE_IMAGE, OnUpdateSaveImage)
ON_COMMAND(ID_COLOR_IMAGE_REFRESH, OnColorImageRefresh)
END_MESSAGE_MAP()
// CIProcessNDoc 构造/析构
CIProcessNDoc::CIProcessNDoc()
{
// TODO: 在此添加一次性构造代码
pImg[0]=&SaveCanvus;
pImg[1]=&WorkCanvus;
pImg[2]=&img2;
pImg[3]=&img3;
pImg[4]=&img4;
pImg[5]=&img5;
pImg[6]=&img6;
pImg[7]=&img7;
pImg[8]=&img8;
pImg[9]=&WindowCanvus;
}
CIProcessNDoc::~CIProcessNDoc()
{
for (int i=0;i<10;i++)
pImg[i]->Destroy();
}
BOOL CIProcessNDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: 在此添加重新初始化代码
// (SDI 文档将重用该文档)
return TRUE;
}
// CIProcessNDoc 序列化
void CIProcessNDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: 在此添加存储代码
}
else
{
// TODO: 在此添加加载代码
}
}
// CIProcessNDoc 诊断
#ifdef _DEBUG
void CIProcessNDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CIProcessNDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CIProcessNDoc 命令
void CIProcessNDoc::OnUpdateSaveImage(CCmdUI *pCmdUI)
{
// TODO: 在此添加命令更新用户界面处理程序代码
pCmdUI->Enable(!pImg[0]->IsNull());
}
void CIProcessNDoc::OnOpenImage()
{
// TODO: 在此添加命令处理程序代码
CString strFilter;
CSimpleArray<GUID> aguidFileTypes;
HRESULT hResult;
hResult = pImg[0]->GetExporterFilterString(strFilter,aguidFileTypes);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("GetExporterFilter failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter);
dlg.m_ofn.nFilterIndex = m_nFilterLoad;
hResult = (int)dlg.DoModal();
if(hResult != IDOK) {
CString fmt;
fmt.Format("GetExporterFilter failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
m_nFilterLoad = dlg.m_ofn.nFilterIndex;
m_FileName = dlg.GetFileName();
pImg[0]->Destroy();
hResult = pImg[0]->Load(m_FileName);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("Load image failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
if (ImageType(pImg[0])<2)
LowTypeToIndex(pImg[1],pImg[0]);
else
ImageCopy(pImg[1],pImg[0]);
SetPathName(m_FileName,1);
UpdateAllViews(NULL);
}
BOOL CIProcessNDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
HRESULT hResult;
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: 在此添加您专用的创建代码
m_FileName = lpszPathName;
pImg[0]->Destroy();
hResult = pImg[0]->Load(m_FileName);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("Load image failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return FALSE;
}
if (ImageType(pImg[0])<2)
LowTypeToIndex(pImg[1],pImg[0]);
else
ImageCopy(pImg[1],pImg[0]);
SetPathName(m_FileName,1);
UpdateAllViews(NULL);
return TRUE;
}
void CIProcessNDoc::OnSaveImage()
{
// TODO: 在此添加命令处理程序代码
CString strFilter;
CSimpleArray<GUID> aguidFileTypes;
CString strFileName;
CString strExtension;
HRESULT hResult;
hResult = pImg[1]->GetExporterFilterString(strFilter,aguidFileTypes);
if (FAILED(hResult)) return;
CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT | OFN_EXPLORER,strFilter);
dlg.m_ofn.nFilterIndex = m_nFilterLoad;
hResult = (int)dlg.DoModal();
if (hResult != IDOK) return;
strFileName = dlg.m_ofn.lpstrFile;
if (dlg.m_ofn.nFileExtension == 0)
{
switch (dlg.m_ofn.nFilterIndex)
{
case 1:
strExtension = "bmp";
break;
case 2:
strExtension = "jpg";
break;
case 3:
strExtension = "gif";
break;
case 4:
strExtension = "tif";
break;
case 5:
strExtension = "png";
break;
default:
break;
}
strFileName = strFileName + '.' + strExtension;
}
if (ImageType(pImg[1])==0)
IndexToLowType(pImg[1],pImg[1]);
hResult = WorkCanvus.Save(strFileName);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("Save image failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
}
void CIProcessNDoc::OnColorImageRefresh()
{
HRESULT hResult;
pImg[0]->Destroy();
hResult = pImg[0]->Load(m_FileName);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("Load image failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
ImageCopy(pImg[1],pImg[0]);
SetPathName(m_FileName,1);
UpdateAllViews(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -