MainFrm.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:26k
- // MainFrm.cpp : implementation of the CMainFrame class
- #include "stdafx.h"
- #include "MainFrm.h"
- #include "MiniCADDoc.h"
- #include "MiniCADView.h"
- #include "MyNewDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- ON_COMMAND_EX(ID_VIEW_MYOPTIONBAR, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYOPTIONBAR, OnUpdateControlBarMenu)
- ON_COMMAND_EX(ID_VIEW_MYWORKBAR, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYWORKBAR, OnUpdateControlBarMenu)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_VIEW_MYDRAWTOOLBAR, OnViewMydrawtoolbar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYDRAWTOOLBAR, OnUpdateViewMydrawtoolbar)
- ON_COMMAND(ID_FILE_NEWF, OnFileNewF)
- ON_COMMAND(ID_FILE_OPENF, OnFileOpenF)
- ON_COMMAND(ID_FILE_NEWP, OnFileNewP)
- ON_COMMAND(ID_FILE_OPENP, OnFileOpenP)
- ON_COMMAND(ID_FILE_NEWFTOP, OnFileNewFToP)
- ON_UPDATE_COMMAND_UI(ID_FILE_NEWFTOP, OnUpdateFileNewFToP)
- ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
- ON_NOTIFY(NM_CLICK, IDC_TREE, OnClickTree)
- ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnDblclkTree)
- ON_NOTIFY(NM_RCLICK, IDC_TREE, OnRclickTree)
- ON_COMMAND(ID_VIEW_FULL, OnViewFull)
- ON_UPDATE_COMMAND_UI(ID_VIEW_FULL, OnUpdateViewFull)
- ON_WM_GETMINMAXINFO()
- ON_COMMAND(ID_FILE_OPENFTOP, OnFileOpenFToP)
- ON_UPDATE_COMMAND_UI(ID_FILE_OPENFTOP, OnUpdateFileOpenFToP)
- ON_COMMAND(ID_FILE_SAVEP, OnFileSaveP)
- ON_WM_CLOSE()
- ON_COMMAND(ID_FILE_CLOSEP, OnFileCloseP)
- ON_COMMAND(ID_FILE_CLOSEF, OnFileCloseF)
- ON_COMMAND(ID_FILE_SAVEF, OnFileSaveF)
- ON_COMMAND(ID_FILE_SAVEF_AS, OnFileSaveFAs)
- ON_COMMAND(ID_FILE_SAVEALL, OnFileSaveall)
- //}}AFX_MSG_MAP
- ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_FILELIST, ID_FILE_FILELIST + RECENTFILELIST_NUM - 1, OnUpdateFileFilelist)
- ON_COMMAND_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + 3, OnFileProjectlist)
- ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + RECENTFILELIST_NUM - 1, OnUpdateFileProjectlist)
- // Global help commands
- ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
- ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
- ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
- ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_SEPARATOR,
- ID_SEPARATOR,
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- m_pWndFullScreen = NULL;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- m_wndToolBar.SetWindowText (_T("标准工具条"));
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1;
- }
- m_wndStatusBar.SetPaneInfo(1, 0, SBPS_NORMAL, 100);
- m_wndStatusBar.SetPaneInfo(2, 0, SBPS_NORMAL, 100);
- if (!m_MyWorkBar.Create(_T("工作区"), this, CSize(170, 50), TRUE, ID_VIEW_MYWORKBAR))
- {
- TRACE0("Failed to create myworkbarn");
- return -1;
- }
- m_MyWorkBar.SetBarStyle(m_MyWorkBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY |
- CBRS_SIZE_DYNAMIC);
- m_MyWorkBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_MyWorkBar, AFX_IDW_DOCKBAR_LEFT);
-
- //创建位于左侧的绘图工具条
- if (!m_MyDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_MyDrawToolBar.LoadToolBar(IDR_MYDRAWTOOLBAR))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- //设置绘图工具条标题
- m_MyDrawToolBar.SetWindowText (_T("绘图工具条"));
- //允许工具条浮动
- m_MyDrawToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_MyDrawToolBar);
- //创建位于左侧的修改工具条
- if (!m_MyModifyToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_MyModifyToolBar.LoadToolBar(IDR_MYMODIFYTOOLBAR))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- //设置修改工具条标题
- m_MyModifyToolBar.SetWindowText (_T("修改工具条"));
- //允许工具条浮动
- m_MyModifyToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_MyModifyToolBar);
- if (!m_MyOptionBar.Create(this, IDD_MYOPTIONBAR, ID_VIEW_MYOPTIONBAR))
{
TRACE0("Failed to create dialog bar m_MyOptionBarn");
return -1;
}
m_MyOptionBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_MyOptionBar);
- //初始化选项条
- m_MyOptionBar.Initialize();
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
- cs.style &= ~FWS_ADDTOTITLE;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnViewMydrawtoolbar(UINT nID)
- {
- BOOL bVisible=m_MyDrawToolBar.GetStyle() & WS_VISIBLE ;
- //显示或隐藏绘图工具条
- ShowControlBar(&m_MyDrawToolBar, !bVisible, FALSE);
- RecalcLayout();
- return ;
- }
- void CMainFrame::OnUpdateViewMydrawtoolbar(CCmdUI* pCmdUI)
- {
- //设置绘图工具条显示、隐藏标志
- pCmdUI->SetCheck((m_MyDrawToolBar.GetStyle() & WS_VISIBLE) != 0);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileNewF()
- {
- CMyNewSheet m_NewSheet(_T("新建"), this, 0);
- m_NewSheet.DoModal();
- }
- void CMainFrame::OnFileOpenF()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- {
- //pApp->CADInfo.KindofNew = NEW_NONE;
- //pApp->CADInfo.IsEmpty = FALSE;
- }
- }
- void CMainFrame::OnFileSaveF()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- return;
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- pDoc->SaveDocument();
- }
- void CMainFrame::OnFileSaveFAs()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- return;
- CString Filter="图纸文件(*.xsy)|*.xsy|所有文件(*.*)|*.*||";
- CString PathName;
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- CFileDialog SaveFileDlg(FALSE, 0, pDoc->FileInfo.FileName,
- OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES, (LPCTSTR)Filter);
- SaveFileDlg.m_ofn.lpstrTitle=_T("另存为");
- if(SaveFileDlg.DoModal() != IDOK)
- return;
- //更改文档的文件名及路径
- PathName = SaveFileDlg.GetPathName(); //取得文件名(包含路径)
- pDoc->FileInfo.FileName = SaveFileDlg.GetFileName(); //取得文件名
- pDoc->FileInfo.FilePath = PathName.Left(PathName.GetLength()
- - pDoc->FileInfo.FileName.GetLength() - 1);
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex].FileName = pDoc->FileInfo.FileName;
- pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex].FilePath = pDoc->FileInfo.FilePath;
- }
- pDoc->SaveDocument();
- }
- //保存全部文档
- void CMainFrame::OnFileSaveall()
- {
- // TODO: Add your command handler code here
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- //获取文档模板
-
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- ASSERT(pDocTemplate != NULL);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- while(DocPosition != NULL)
- {
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- pDoc->SaveDocument();
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileNewP()
- {
- // TODO: Add your command handler code here
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
-
- //显示“新建”属性框
- CMyNewProjectDlg m_NewProjectDlg;
- if(m_NewProjectDlg.NewProject(&pApp->ProjectInfo) == FALSE)
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- pTree->InsertItem((LPCTSTR)pApp->ProjectInfo.Name, 0, 0, TVI_ROOT, TVI_SORT);
- pTree->ShowWindow(TRUE);
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- //刚刚创建新项目,自动显示“增加图纸”对话框
- OnFileNewFToP();
- }
- void CMainFrame::OnFileOpenP()
- {
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
- CString Filter="项目文件(*.prj)|*.prj|所有文件(*.*)|*.*||";
- CString PathName;
- //实例化一个CFileDialog类
- CFileDialog OpenProjectDlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES,(LPCTSTR)Filter);
- OpenProjectDlg.m_ofn.lpstrTitle=_T("打开项目文件");
- if(OpenProjectDlg.DoModal() != IDOK)
- return;
- PathName = OpenProjectDlg.GetPathName(); //取得文件名(包含路径)
-
- if(!OpenProject(PathName))
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- pApp->ProjectInfo.FileName = OpenProjectDlg.GetFileName(); //取得文件名
- pApp->ProjectInfo.FilePath = PathName.Left(PathName.GetLength()
- - pApp->ProjectInfo.FileName.GetLength() - 1);
- pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- }
- void CMainFrame::OnFileNewFToP()
- {
- if(pApp->CADInfo.KindofNew != NEW_PROJECT)
- return;
- CMyAddFileDlg MyAddFileDlg;
- //如果增加图纸成功
- //通过CMiniCADApp的成员变量NewFileInfo来传递新建文档参数
- if(MyAddFileDlg.AddFile(&pApp->NewFileInfo))
- {
- pApp->OnFileNew();//该函数会调用CDocument::OnNewDocument()
-
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
-
- pApp->ProjectInfo.FileNum++;
- pDoc->DocumentIndex = pApp->ProjectInfo.FileNum - 1;
- pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex] = pDoc->FileInfo;
- CMiniCADView* pView = (CMiniCADView*)pChildWnd->GetActiveView();
- pView->Invalidate(FALSE);
-
- HTREEITEM RootItem;
- HTREEITEM ChildItem;
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- RootItem = pTree->GetRootItem();
- ChildItem = pTree->InsertItem((LPCTSTR)pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex].Name,
- 1, 1, RootItem);
- pTree->SetItemData(ChildItem, (DWORD)(pDoc->DocumentIndex));
- pTree->Expand(RootItem, TVE_EXPAND);
- }
- }
- void CMainFrame::OnUpdateFileNewFToP(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- //使能“增加图纸-新建”菜单命令
- if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMainFrame::OnFileOpenFToP()
- {
- // TODO: Add your command handler code here
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- pApp->OnFileOpen();
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
-
- pApp->ProjectInfo.FileNum++;
- pDoc->DocumentIndex = pApp->ProjectInfo.FileNum -1;
- pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex] = pDoc->FileInfo;
- HTREEITEM RootItem;
- HTREEITEM ChildItem;
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- RootItem = pTree->GetRootItem();
- ChildItem = pTree->InsertItem((LPCTSTR)pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex].Name,
- 1, 1, RootItem);
- pTree->SetItemData(ChildItem, (DWORD)(pDoc->DocumentIndex));
- pTree->Expand(RootItem, TVE_EXPAND);
- }
- }
- void CMainFrame::OnUpdateFileOpenFToP(CCmdUI* pCmdUI)
- {
- if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMainFrame::OnFileSaveP()
- {
- int num;
- CFile fp;
- CString PathName;
- PathName = pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName;
- //打开一个文件,如果该文件不存在就创建一个,如果已存在就将文件长度变为0
- fp.Open(PathName, CFile::modeCreate | CFile::modeWrite);
- if(fp == 0)
- {
- MessageBox("打开项目文件错误",
- "错误", MB_OK | MB_ICONERROR);
- return;
- }
-
- CArchive ar(&fp, CArchive::store);
- ar << pApp->ProjectInfo.Name << pApp->ProjectInfo.FileNum;
- for(num = 0; num < pApp->ProjectInfo.FileNum; num++)
- pApp->ProjectInfo.FileInfo[num].Serialize(ar);
- //必须先关闭ar,再关闭fp
- ar.Close();
- fp.Close();
- }
- void CMainFrame::OnFileCloseP()
- {
- if(MessageBox("关闭前是否保存全部文件?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveall();//保存全部图纸
-
- if(MessageBox("关闭前是否保存项目?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveP();//保存当前项目
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- pApp->CADInfo.IsEmpty = TRUE;
- pApp->CADInfo.KindofNew = NEW_NONE;
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- pTree->DeleteAllItems();
- pTree->ShowWindow(FALSE);
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- for(;;)
- {
- if(DocPosition == NULL)
- return;
- //获取文档
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- ASSERT(pDoc != NULL);
- pDoc->OnCloseDocument();
- }
- }
- ////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileCloseF()
- {
-
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CTabCtrl* m_Tab =(CTabCtrl*)m_MyWorkBar.GetDlgItem(IDC_TAB);
- switch(m_Tab->GetCurSel())
- {
- case 0:
- {
- //隐藏列表框
- CListCtrl* pList = (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
- pList->ShowWindow(FALSE);
- //当有项目存在时才显示树形框
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- pTree->ShowWindow(TRUE);
- }
- }
- break;
- case 1:
- {
- //显示列表框
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- pTree->ShowWindow(FALSE);
-
- CListCtrl* pList =
- (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
- pList->ShowWindow(TRUE);
- }
- break;
- }
- *pResult = 0;
- }
- void CMainFrame::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- }
- void CMainFrame::OnDblclkTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CString PathName;
- int index;
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- CMiniCADView* pView;
- CChildFrame* pChildFrame;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- POSITION ViewPosition;
-
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- HTREEITEM ChildItem = pTree->GetSelectedItem();
- if(ChildItem == pTree->GetRootItem())
- return;
- index = (int)pTree->GetItemData(ChildItem);
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- for(;;)
- {
- if(DocPosition == NULL)
- {
- //如果DocPosition == NULL,说明文档没有打开
- //注意如果文件不存在,在CScrollView创建时会出错,现在
- //还不知道预先处理错误的方法
- PathName = pApp->ProjectInfo.FileInfo[index].FilePath + "\" + pApp->ProjectInfo.FileInfo[index].FileName;
- //给要激活的文档序号赋值
- ASSERT(AfxGetApp()->OpenDocumentFile(PathName) != NULL);
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- pDoc->DocumentIndex = index;
-
- *pResult = 0;
- return;
- }
- //获取文档
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- if(pDoc->DocumentIndex == index)
- break;
- }
- //获取文档的视图
- ViewPosition = pDoc->GetFirstViewPosition();
- pView = (CMiniCADView*)pDoc->GetNextView(ViewPosition);
- //激活子窗口
- pChildFrame = (CChildFrame*)pView->GetParentFrame();
- pChildFrame->MDIActivate( );
-
- *pResult = 0;
- }
- void CMainFrame::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- *pResult = 0;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnViewFull()
- {
- if (m_pWndFullScreen != NULL)
- {
- LockWindowUpdate();
- m_pWndFullScreen->LockWindowUpdate();
- m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, TRUE, FALSE);
- ShowControlBar(&m_wndToolBar, TRUE, FALSE);
- ShowControlBar(&m_wndStatusBar, TRUE, FALSE);
- ShowControlBar(&m_MyOptionBar, TRUE, FALSE);
- ShowControlBar(&m_MyDrawToolBar, TRUE, FALSE);
- ShowControlBar(&m_MyModifyToolBar, TRUE, FALSE);
- ShowControlBar(&m_MyWorkBar, TRUE, FALSE);
-
- //恢复原来状态
- SetWindowPlacement(&m_MainOldPlace);
- m_pWndFullScreen->SetWindowPlacement(&m_ChildOldPlace);
- UnlockWindowUpdate();
- m_pWndFullScreen->UnlockWindowUpdate();
- m_pWndFullScreen = NULL;
- }
- else
- {
- m_pWndFullScreen = (CChildFrame*)MDIGetActive();
- if(m_pWndFullScreen == NULL)
- return;
-
- LockWindowUpdate();
- m_pWndFullScreen->LockWindowUpdate();
- //隐藏各种工具条,注意应先使用LockWindowUpdate()禁止更新屏幕
- //这样可以加快全屏显示的速度
- m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, FALSE, FALSE);
- ShowControlBar(&m_wndToolBar, FALSE, FALSE);
- ShowControlBar(&m_wndStatusBar,FALSE, FALSE);
- ShowControlBar(&m_MyOptionBar, FALSE, FALSE);
- ShowControlBar(&m_MyDrawToolBar, FALSE, FALSE);
- ShowControlBar(&m_MyModifyToolBar, FALSE, FALSE);
- ShowControlBar(&m_MyWorkBar, FALSE, FALSE);
-
- m_pWndFullScreen->GetWindowPlacement(&m_ChildOldPlace);
- GetWindowPlacement(&m_MainOldPlace);
-
- CRect rectDesktop, rectDesired;
- //获取全屏显示所需的客户区
- if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktop, 0))
- ::GetWindowRect(::GetDesktopWindow(), &rectDesktop);
- else
- {
- rectDesktop.right = ::GetSystemMetrics(SM_CXSCREEN);
- rectDesktop.bottom = ::GetSystemMetrics(SM_CYSCREEN);
- rectDesktop.right -= rectDesktop.left;
- rectDesktop.bottom -= rectDesktop.top;
- rectDesktop.left = rectDesktop.left;
- rectDesktop.top = rectDesktop.top;
- }
- rectDesired = rectDesktop;
- //根据客户区获取框架的尺寸
- ::AdjustWindowRect(&rectDesktop, GetStyle(), TRUE);
-
- rectDesktop.bottom += ::GetSystemMetrics(SM_CYBORDER); // See "Ask Dr. GUI #10"
- m_FullScreenPlace = rectDesktop;
-
- WINDOWPLACEMENT wpNew = m_MainOldPlace;
- wpNew.showCmd = SW_SHOWNORMAL;
- wpNew.rcNormalPosition = rectDesktop;
- //设置主框架新的状态和位置
- SetWindowPlacement(&wpNew);
-
- wpNew.rcNormalPosition = rectDesired;
- ::AdjustWindowRect(&(wpNew.rcNormalPosition), m_pWndFullScreen->GetStyle(), FALSE);
- //设置子框架新的状态和位置
- m_pWndFullScreen->SetWindowPlacement(&wpNew);
- UnlockWindowUpdate();
- m_pWndFullScreen->UnlockWindowUpdate();
- }
- }
- void CMainFrame::OnUpdateViewFull(CCmdUI* pCmdUI)
- {
- if(MDIGetActive() == NULL)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- else
- {
- pCmdUI->Enable(TRUE);
- pCmdUI->SetCheck(m_pWndFullScreen != NULL);
- }
- }
- void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- {
- // TODO: Add your message handler code here and/or call default
- if (m_pWndFullScreen != NULL)
- {
- //全屏显示时重新设置主框架最大化时的尺寸
- lpMMI->ptMaxSize.y = m_FullScreenPlace.Height();
- lpMMI->ptMaxTrackSize.y = m_FullScreenPlace.Height();
- lpMMI->ptMaxSize.x = m_FullScreenPlace.Width();
- lpMMI->ptMaxTrackSize.x = m_FullScreenPlace.Width();
- }
- else
- CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
- }
- BOOL CMainFrame::GetFullScreenSize(CWnd* pWnd, POINT& pt)
- {
- if (m_pWndFullScreen != NULL && pWnd->m_hWnd == m_pWndFullScreen->m_hWnd)
- {
- pt.x = m_FullScreenPlace.Width();
- pt.y = m_FullScreenPlace.Height();
- }
- return (m_pWndFullScreen != NULL);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- //实现“最近项目”的菜单功能
- void CMainFrame::OnFileProjectlist(UINT nID)
- {
- UINT index;
- CString PathName;
- index = nID - ID_FILE_PROJECTLIST;
- PathName = (*(pApp->pRecentProjectList))[index];
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- //如果PathName是当前打开的项目,则返回
- if(PathName == pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName)
- return;
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
- if(!OpenProject(PathName))
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- //获取项目文件名
- pApp->ProjectInfo.FileName = PathName.Right(PathName.GetLength() - PathName.ReverseFind('\')
- - 1);
- //获取项目文件路径
- pApp->ProjectInfo.FilePath = PathName.Left(PathName.ReverseFind('\'));
- pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- }
- void CMainFrame::OnUpdateFileProjectlist(CCmdUI* pCmdUI)
- {
- if(pCmdUI->m_nID == ID_FILE_PROJECTLIST)
- {
- pApp->pRecentProjectList->CRecentFileListEx::UpdateMenu(pCmdUI);
- }
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnFileFilelist(UINT nID)
- {
- }
- void CMainFrame::OnUpdateFileFilelist(CCmdUI* pCmdUI)
- {
- if(pCmdUI->m_nID == ID_FILE_FILELIST)
- {
- //注意此时应该用基类CRecentFileList的UpdateMenu(CCmdUI* pCmdUI)
- //这是由CMenu的特点决定的,“最近文件”菜单项是第二个Popup菜单项,
- //其子菜单的pCmdUI->mIndex为0,pCmdUI->pMenu指向子菜单
- pApp->pRecentFileList->UpdateMenu(pCmdUI);
- }
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnClose()
- {
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- //如果按下“确定”(按下“取消”返回值为2)
- if(MessageBox("退出前是否保存全部文件?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveall();
-
- if(MessageBox("退出前是否保存项目?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveP();
- }
- CMDIFrameWnd::OnClose();
- }
- BOOL CMainFrame::OpenProject(CString PathName)
- {
- HTREEITEM RootItem;
- HTREEITEM ChildItem;
- int filenum;
- int index;
- CFile fp;
- fp.Open(PathName, CFile::modeCreate | CFile::modeNoTruncate
- | CFile::modeRead);
- if(fp == 0)
- {
- MessageBox("打开项目文件错误",
- "错误", MB_OK | MB_ICONERROR);
- return FALSE;
- }
-
- CArchive ar(&fp, CArchive::load);
- ar >> pApp->ProjectInfo.Name >> filenum;
- for(index = 0; index < filenum; index++)
- pApp->ProjectInfo.FileInfo[index].Serialize(ar);
- //显示树形控件,插入根项
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- pTree->InsertItem((LPCTSTR)pApp->ProjectInfo.Name, 0, 0, TVI_ROOT, TVI_SORT);
- pTree->ShowWindow(TRUE);
- //项目文档数置0,如果打开文档成功,项目文档数中增加1
- pApp->ProjectInfo.FileNum = 0;
- for(index = 0; index < filenum; index++)
- {
- //注意如果文件不存在,在CScrollView创建时会出错,现在
- //还不知道预先处理错误的方法
- PathName = pApp->ProjectInfo.FileInfo[index].FilePath + "\" + pApp->ProjectInfo.FileInfo[index].FileName;
- ASSERT(pApp->OpenDocumentFile(PathName) != NULL);
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- pApp->ProjectInfo.FileNum++;
- pDoc->DocumentIndex = pApp->ProjectInfo.FileNum - 1;
- pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex] = pDoc->FileInfo;
- CTreeCtrl* pTree = (CTreeCtrl*)m_MyWorkBar.GetDlgItem(IDC_TREE);
- RootItem = pTree->GetRootItem();
- ChildItem = pTree->InsertItem((LPCTSTR)pApp->ProjectInfo.FileInfo[pDoc->DocumentIndex].Name,
- 1, 1, RootItem);
- pTree->SetItemData(ChildItem, (DWORD)(pDoc->DocumentIndex));
- pTree->Expand(RootItem, TVE_EXPAND);
- }
- //关闭文件
- fp.Close();
- return TRUE;
- }