www.pudn.com > JingXiang-Design-Jeff.rar > DesignDoc.cpp
// DesignDoc.cpp : implementation of the CDesignDoc class
//
#include "stdafx.h"
#include "Design.h"
#include "DesignDoc.h"
#include "MainFrm.h"
#include "DesignView.h"
#include "QuickSort.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc
IMPLEMENT_DYNCREATE(CDesignDoc, CDocument)
BEGIN_MESSAGE_MAP(CDesignDoc, CDocument)
//{{AFX_MSG_MAP(CDesignDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc construction/destruction
CDesignDoc::CDesignDoc()
{
// TODO: add one-time construction code here
}
CDesignDoc::~CDesignDoc()
{
}
BOOL CDesignDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc serialization
void CDesignDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc diagnostics
#ifdef _DEBUG
void CDesignDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDesignDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDesignDoc commands
BOOL CDesignDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CWaitCursor WaitCursor;//Show A Waiting Mouse Cursor
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*)pMFrame->GetActiveView();
if(BitMap.BMPSelectEnabled)// If Area Select Enable ,Disable It!
pMFrame->SendMessage(WM_COMMAND,ID_FUNC_SELECT_AREA,0);
if(!BitMap.GetBmpFile(lpszPathName)) return FALSE;
AfxGetApp()->m_pMainWnd->SetWindowText(((CDesignApp*)::AfxGetApp())->AppTitle+" "+BitMap.BMPFileName);
if(BitMap.GetBmpStatus())
{
CSize sizeTotal;
if(pDesignView->mNowRatio>0)
{
BitMap.mNowWidth*=pDesignView->mNowRatio;
BitMap.mNowHeight*=pDesignView->mNowRatio;
}
else
{
BitMap.mNowWidth/=-pDesignView->mNowRatio;
BitMap.mNowHeight/=-pDesignView->mNowRatio;
}
sizeTotal.cx = BitMap.mNowWidth;
sizeTotal.cy = BitMap.mNowHeight;
pDesignView->SetScrollSizes(MM_TEXT, sizeTotal);
pDesignView->pHiShow->m_Ratio=pDesignView->pHiShow->TotalLenth;
// Below ,Update 原图尺寸 For Para_Detect Dialog,Later this Will Be Get Auto Form Hardware Crystal analyse System
pDesignView->pPara_Detect->m_YuanTuChiCun_X=(float)BitMap.InfoHeader_Bak.biWidth;
pDesignView->pPara_Detect->m_YuanTuChiCun_Y=(float)BitMap.InfoHeader_Bak.biHeight;
}
return TRUE;
}
void CDesignDoc::OnFileOpen()
{
CFileDialog Dlg(1,NULL,NULL,OFN_HIDEREADONLY ,//| OFN_OVERWRITEPROMPT,
"BitMap File(*.bmp *.pcx *.tga *.tif)|*.bmp;*.pcx;*.tga;*.tif|All Files(*.*)|*.*||",NULL);
if(Dlg.DoModal()==IDCANCEL) return;
OnOpenDocument(Dlg.GetPathName());
::AfxGetApp()->GetMainWnd()->Invalidate(TRUE);
return;
}
void CDesignDoc::OnFileClose()
{
CWaitCursor WaitCursor;//Show A Waiting Mouse Cursor
BitMap.RectSelected=FALSE; //Disable The Selected Rect Data
if(!BitMap.GetBmpStatus()) return;
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*) (pMFrame->GetActiveView());
pMFrame=(CMainFrame *)(AfxGetApp()->m_pMainWnd);
if(pDesignView->MessageBox("真的要关闭当前图像吗?","关闭当前图像",MB_YESNO|MB_ICONWARNING)==IDNO) return;
if(pDesignView->IsHistogramShowed)// if Histogram View Showed,Close It!
pMFrame->SendMessage(WM_COMMAND,ID_VIEW_SHOW_HISTOGRAM,0);
if(BitMap.BMPSelectEnabled)// If Area Select Enable ,Disable It!
pMFrame->SendMessage(WM_COMMAND,ID_FUNC_SELECT_AREA,0);
BitMap.SetBmpStatus(FALSE);
BitMap.SetIsGray(FALSE);
CSize sizeTotal;
sizeTotal.cx = 100;
sizeTotal.cy = 100;
pDesignView->SetScrollSizes(MM_TEXT, sizeTotal);
AfxGetApp()->m_pMainWnd->SetWindowText(((CDesignApp*)::AfxGetApp())->AppTitle);
::AfxGetApp()->GetMainWnd()->Invalidate(TRUE);
pDesignView->pHiShow->Invalidate(TRUE);
return;
}
void CDesignDoc::OnUpdateFileClose(CCmdUI* pCmdUI)
{
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*)pMFrame->GetActiveView();
pCmdUI->Enable(BitMap.GetBmpStatus()&&!pDesignView->IsAreaLocked);
}
void CDesignDoc::OnFileSave()
{
// TODO: Add your command handler code here
}
void CDesignDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CDesignDoc::OnFileSaveAs()
{
// TODO: Add your command handler code here
}
void CDesignDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CDesignDoc::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*)pMFrame->GetActiveView();
pCmdUI->Enable(!pDesignView->IsAreaLocked);
}
void CDesignDoc::OnFileNew()
{
/*
BYTE Str[10]={106,39,3,2,66,54,4,3,42,1};
QuickSort TheSort;
TheSort.GetInput(Str,10);
for(int i=0;i<1000000;i++)
TheSort.GetTheMid();
CString StrTmp;
StrTmp.Format("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8],Str[9]);
AfxMessageBox(StrTmp);
*/
}