FilesMFC lab1 Doc cpp implementation of the CFilesMFClab1Doc class inc

  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
// FilesMFC(lab1)Doc.cpp : implementation of the CFilesMFClab1Doc class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "FilesMFC(lab1).h"
#endif
#include "FilesMFC(lab1)Doc.h"
#include <propkey.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define BUF 256
// CFilesMFClab1Doc
CFile In,Out;
IMPLEMENT_DYNCREATE(CFilesMFClab1Doc, CDocument)
BEGIN_MESSAGE_MAP(CFilesMFClab1Doc, CDocument)
ON_COMMAND(ID_PUSHIT_GO,&CFilesMFClab1Doc::DoIt)
END_MESSAGE_MAP()
// CFilesMFClab1Doc construction/destruction
CFilesMFClab1Doc::CFilesMFClab1Doc()
{
// TODO: add one-time construction code here
}
CFilesMFClab1Doc::~CFilesMFClab1Doc()
{
}
BOOL CFilesMFClab1Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
void CFilesMFClab1Doc::DoIt()
{
CFileException fileExc;
CFileDialog dlg(TRUE);
TCHAR Buf1[BUF]={0}, Buf2[BUF]={0}, *b1=Buf1, *b2=Buf2;
dlg.DoModal();
if(!In.Open(dlg.GetFileName(),CFile::modeRead))
{
exit(0);
}
CFileDialog dlg1(FALSE);
dlg1.DoModal();
if(!Out.Open(dlg1.GetFileName(),CFile::modeCreate|CFile::modeReadWrite))
{
exit(0);
}
In.SeekToBegin();
LONG s=In.GetLength();
while(s>0)
{
In.Read(b1,1);
if (*b1==' ')
{
*b2=*b1;
*b2++;
*b2=*b1++;
*b2++;
}
else
{
*b2=*b1++;
*b2++;
}
s-=1;
}
Out.Write(Buf2,sizeof(Buf2));
*b1=0;
*b2=0;
In.Close();
Out.Close();
}
// CFilesMFClab1Doc serialization
void CFilesMFClab1Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
#ifdef SHARED_HANDLERS
// Support for thumbnails
void CFilesMFClab1Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
// Modify this code to draw the document's data
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
CString strText = _T("TODO: implement thumbnail drawing here");
LOGFONT lf;
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
pDefaultGUIFont->GetLogFont(&lf);
lf.lfHeight = 36;
CFont fontDraw;
fontDraw.CreateFontIndirect(&lf);
CFont* pOldFont = dc.SelectObject(&fontDraw);
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
dc.SelectObject(pOldFont);
}
// Support for Search Handlers
void CFilesMFClab1Doc::InitializeSearchContent()
{
CString strSearchContent;
// Set search contents from document's data.
// The content parts should be separated by ";"
// For example: strSearchContent = _T("point;rectangle;circle;ole object;");
SetSearchContent(strSearchContent);
}
void CFilesMFClab1Doc::SetSearchContent(const CString& value)
{
if (value.IsEmpty())
{
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
}
else
{
CMFCFilterChunkValueImpl *pChunk = NULL;
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
if (pChunk != NULL)
{
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
SetChunkValue(pChunk);
}
}
}
#endif // SHARED_HANDLERS
// CFilesMFClab1Doc diagnostics
#ifdef _DEBUG
void CFilesMFClab1Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CFilesMFClab1Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CFilesMFClab1Doc commands