Bmptestdoc.cpp
上传用户:cjd055
上传日期:2013-04-01
资源大小:608k
文件大小:3k
- // BmpTestDoc.cpp : implementation of the CBmpTestDoc class
- //
- #include "stdafx.h"
- #include "BmpTest.h"
- #include "BmpTestDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CBmpTestDoc
- IMPLEMENT_DYNCREATE(CBmpTestDoc, CDocument)
- BEGIN_MESSAGE_MAP(CBmpTestDoc, CDocument)
- //{{AFX_MSG_MAP(CBmpTestDoc)
- ON_COMMAND(ID_FILE_SAVE, OnFileSave)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- ON_COMMAND(ID_PICK, OnPick)
- ON_COMMAND(ID_FILE_OPENC, OnFileOpenc)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CBmpTestDoc construction/destruction
- CBmpTestDoc::CBmpTestDoc()
- {
- // TODO: add one-time construction code here
- }
- CBmpTestDoc::~CBmpTestDoc()
- {
- }
- BOOL CBmpTestDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CBmpTestDoc serialization
- void CBmpTestDoc::Serialize(CArchive& ar)
- {
- CString str;
- CFile * file;
- LPCTSTR fn;
- file=ar.GetFile();
- str=file->GetFileName();
- fn=str.GetBuffer(str.GetLength());
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- m_Dib.SaveBmp(fn);
- }
- else
- {
- // TODO: add loading code here
- m_Dib.LoadBmp(fn);
- }
- m_BM=true;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CBmpTestDoc diagnostics
- #ifdef _DEBUG
- void CBmpTestDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CBmpTestDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CBmpTestDoc commands
- void CBmpTestDoc::OnFileSave()
- {
- // TODO: Add your command handler code here
- CString str;
- LPCTSTR fn;
- str=GetPathName();
- fn=str.GetBuffer(100);
- m_Dib.SaveBmp(fn);
- }
- void CBmpTestDoc::OnFileSaveAs()
- {
- // TODO: Add your command handler code here
- CString str;
- LPCTSTR fn;
- CFileDialog fd(FALSE,
- NULL,
- NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "Windows Bmp files(*.bmp)|*.bmp|All files(*.*)|*.*||"
- );
- if(fd.DoModal()==IDOK)
- {
- str=fd.GetPathName();
- if(str.Find(".bmp")==-1)
- {
- str=str+".bmp";
- }
- fn=str.GetBuffer(100);
- m_Dib.SaveBmp(fn);
- SetPathName(fn);
- }
- }
- void CBmpTestDoc::OnPick()
- {
- // TODO: Add your command handler code here
- m_Dib.PickBitmapToFile("子画面.bmp",
- 20,
- 20,
- 231,
- 241
- );
- }
- void CBmpTestDoc::OnFileOpenc()
- {
- // TODO: Add your command handler code here
- static CFileFind fFind;
- CString strName;
- static BOOL ffind=fFind.FindFile("D:\郭大波\做测试的一些数据\*.bmp");
- CString str;
- if(ffind==TRUE)
- {
- ffind=fFind.FindNextFile();
- strName=fFind.GetFilePath();
- AfxGetApp()->OpenDocumentFile(strName);
- }
- }