anywhereDoc.cpp
资源名称:anywhere.zip [点击查看]
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:5k
源码类别:
远程控制编程
开发平台:
Visual C++
- // anywhereDoc.cpp : implementation of the CAnywhereDoc class
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "anywhereDoc.h"
- #include "msgman.h"
- #include "mainfrm.h"
- #include "frameprop.h"
- #include <limits.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAnywhereDoc
- IMPLEMENT_DYNCREATE(CAnywhereDoc, CDocument)
- BEGIN_MESSAGE_MAP(CAnywhereDoc, CDocument)
- //{{AFX_MSG_MAP(CAnywhereDoc)
- ON_COMMAND(ID_FRAMEPROP, OnFrameprop)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAnywhereDoc construction/destruction
- CAnywhereDoc::CAnywhereDoc()
- {
- // TODO: add one-time construction code here
- m_hDIB = NULL;
- m_palDIB = NULL;
- m_sizeDoc = CSize(1,1); // dummy value to make CScrollView happy
- }
- CAnywhereDoc::~CAnywhereDoc()
- {
- }
- BOOL CAnywhereDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- //m_FontAril.CreateFont(20,0,0,0,400,FALSE,FALSE,0,
- // ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
- // DEFAULT_PITCH|FF_SWISS,"Arial");
- //m_Fontst.CreateFont(15,0,0,0,700,0,0,0,ANSI_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS
- //,DRAFT_QUALITY,VARIABLE_PITCH,_T("宋体"));
- //m_pmsgman=new CMsgman(this);
- for (int i=0;i<9;i++)
- m_sys[i]="";
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnywhereDoc serialization
- void CAnywhereDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnywhereDoc diagnostics
- #ifdef _DEBUG
- void CAnywhereDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CAnywhereDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CAnywhereDoc commands
- void CAnywhereDoc::OnFrameprop()
- {
- // CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
- CFrameworkProperties dialog(((CMainFrame*)AfxGetMainWnd())->m_Framework);
- dialog.DoModal();
- }
- BOOL CAnywhereDoc::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
- {
- /* CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
- if (pFrame && pFrame->m_Framework.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo))
- return TRUE;
- */
- return CDocument::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
- }
- BOOL CAnywhereDoc::ReadBmp(LPCTSTR lpszPathName)
- {
- CFile file;
- CFileException fe;
- if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite, &fe))
- {
- ReportSaveLoadException(lpszPathName, &fe,
- FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
- return FALSE;
- }
- //DeleteContents();
- BeginWaitCursor();
- // replace calls to Serialize with ReadDIBFile function
- TRY
- {
- m_hDIB = ::ReadDIBFile(file);
- }
- CATCH (CFileException, eLoad)
- {
- file.Abort(); // will not throw an exception
- EndWaitCursor();
- ReportSaveLoadException(lpszPathName, eLoad,
- FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
- m_hDIB = NULL;
- return FALSE;
- }
- END_CATCH
- InitDIBData();
- EndWaitCursor();
- if (m_hDIB == NULL)
- {
- // may not be DIB format
- CString strMsg;
- strMsg.LoadString(IDS_CANNOT_LOAD_DIB);
- MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
- return FALSE;
- }
- SetPathName(lpszPathName);
- SetModifiedFlag(FALSE); // start off with unmodified
- return TRUE;
- }
- void CAnywhereDoc::InitDIBData()
- {
- if (m_palDIB != NULL)
- {
- delete m_palDIB;
- m_palDIB = NULL;
- }
- if (m_hDIB == NULL)
- {
- return;
- }
- // Set up document size
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_hDIB);
- if (::DIBWidth(lpDIB) > INT_MAX ||::DIBHeight(lpDIB) > INT_MAX)
- {
- ::GlobalUnlock((HGLOBAL) m_hDIB);
- ::GlobalFree((HGLOBAL) m_hDIB);
- m_hDIB = NULL;
- CString strMsg;
- strMsg.LoadString(IDS_DIB_TOO_BIG);
- MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
- return;
- }
- m_sizeDoc = CSize((int) ::DIBWidth(lpDIB), (int) ::DIBHeight(lpDIB));
- ::GlobalUnlock((HGLOBAL) m_hDIB);
- // Create copy of palette
- m_palDIB = new CPalette;
- if (m_palDIB == NULL)
- {
- // we must be really low on memory
- ::GlobalFree((HGLOBAL) m_hDIB);
- m_hDIB = NULL;
- return;
- }
- if (::CreateDIBPalette(m_hDIB, m_palDIB) == NULL)
- {
- // DIB may not have a palette
- delete m_palDIB;
- m_palDIB = NULL;
- return;
- }
- }