-
Notifications
You must be signed in to change notification settings - Fork 2
/
ImageApp.cpp
executable file
·215 lines (180 loc) · 4.95 KB
/
ImageApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// ImageApp.cpp: implementation of the CImageApp class.
// 鲍捷,1998.12.27
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ImageS.h"
#include "ImageApp.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CImageApp::CImageApp()
{
}
CImageApp::~CImageApp()
{
}
//1998.12.21 取本App所有文档的指针链表
CPtrArray * CImageApp::EnumAllDocuments( CDocument *pDocToExclude /*=NULL*/)
{
CPtrArray* pArray = NULL;
// POSITION pos = m_templateList.GetHeadPosition();
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
pArray = new CPtrArray;
BOOL bFound = FALSE;
while (pos != NULL)
{
// CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(pos);
POSITION posDoc = pTemplate->GetFirstDocPosition();
while(posDoc != NULL)
{
bFound = TRUE;
CDocument* pDoc = pTemplate->GetNextDoc(posDoc);
if( pDoc != pDocToExclude )
pArray->Add(pDoc);
}
}
if(bFound)
return(pArray);
else
return NULL;
}
/* 文件-打开消息响应
搜索已注册的文档模板,填充文件打开扩展名列表
用相应文档模板打开之
如无相应文档模板,用第一个注册的文档模板打开
可以重载之以实现自己的“打开”对话框
*/
void CImageApp::OnFileOpen()
{
//取已注册的文档扩展名
CString strType;
POSITION curTemplatePos = GetFirstDocTemplatePosition();
while(curTemplatePos != NULL)
{
CDocTemplate* curTemplate =
GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str, CDocTemplate::fileNewName);
strType+=str; //如 位图文件(*.bmp)
strType+="|*";
curTemplate->GetDocString(str, CDocTemplate::filterExt);
strType+=str;// 如 .BMP
strType+="|";
}
strType+="所有文件(*.*)|*.*||";
CFileDialog dlg(TRUE,
NULL,
"未命名",
OFN_ALLOWMULTISELECT|OFN_EXPLORER,
strType);
if(dlg.DoModal() != IDOK)
return;
CString strFileName=dlg.GetPathName();
LPTSTR lpStr=strFileName.GetBuffer(256);
strFileName.ReleaseBuffer();
//根据文件扩展名调用相应的文档模板
CString strExt=dlg.GetFileExt();
strExt.MakeUpper();
curTemplatePos = GetFirstDocTemplatePosition();
while(curTemplatePos != NULL)
{
CDocTemplate* curTemplate =
GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str, CDocTemplate::filterExt);
if( str == strExt || str == "."+strExt)
{
curTemplate->OpenDocumentFile(lpStr);
return;
}
}
//未注册的文件类型,以主文档模板打开(第一个注册的文档模板)
curTemplatePos = GetFirstDocTemplatePosition();
while(curTemplatePos != NULL)
{
CDocTemplate* curTemplate =
GetNextDocTemplate(curTemplatePos);
curTemplate->OpenDocumentFile(lpStr);
return;
}
AfxMessageBox("没有已注册的文档模板");
}
/*1998.12.28 鲍捷, 新的图象文档
参数 :strTemplate 文档模板的标志字符串
hDIB 图象的位图句柄
*/
CImageDoc * CImageApp::CreateDoc(CString strTemplate, HDIB hDIB)
{
CImageDoc *pNewDoc=NULL;
POSITION curTemplatePos = GetFirstDocTemplatePosition();
BOOL bSuccess=FALSE;
while(curTemplatePos != NULL)
{
CDocTemplate* curTemplate =
GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str, CDocTemplate::docName);
if(str == strTemplate)
{
pNewDoc=(CImageDoc *)(curTemplate->OpenDocumentFile(NULL));
//CImageDoc
bSuccess=TRUE;
break;
}
}
if(bSuccess)
{
pNewDoc->ReplaceHDIB(hDIB);
if(hDIB) pNewDoc->SetModifiedFlag(TRUE);
return pNewDoc;
}
else
{
AfxMessageBox("没有已注册的文档模板");
return NULL;
}
}
//1999-01-29 ,鲍捷,从一位图建立文档
CImageDoc * CImageApp::CreateDoc(CString strTemplate,HBITMAP hBitmap )
{
return CreateDoc(strTemplate,BitmapToDIB(hBitmap,NULL));
}
//1999-02-06,鲍捷,关闭当前打开的所有文档
void CImageApp::OnFileCloseAll()
{
CPtrArray* pDocArray = NULL;
pDocArray = EnumAllDocuments();
if(pDocArray == NULL) return;
int result=MessageBox(NULL,"自动保存所做的修改吗?","关闭所有文档",MB_YESNO);
if(result == IDYES)
OnFileSaveAll();
// HideApplication( );
CloseAllDocuments(FALSE);
}
void CImageApp::OnFileSaveAll()
{
// TODO: Add your command handler code here
CPtrArray* pDocArray;
pDocArray = EnumAllDocuments();
for(int i = 0; i < pDocArray->GetSize(); i++)
{
((CImageDoc*) pDocArray->GetAt(i))->OnFileSave();
}
}
BOOL CImageApp::InitInstance()
{
AfxEnableControlContainer();
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
{
return TRUE;
}
return CWinApp::InitInstance();
}