// 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