MainFrm.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:7k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "Test1.h"
- #include "ControlWnd.h"
- #include "ProjectView.h"
- #include "MainFrm.h"
- #include "XProject.h"
- #include "YProject.h"
- #include "ZProject.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- extern bool gbIsGetData;
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- ON_MESSAGE(MESSAGE_STEPPRO,PrecessReadFile)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_PROGRESSTEXT,
- ID_PROGRESSAREA,
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- m_pView = NULL;
- m_bCreat = FALSE;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::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; // fail to create
- }
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
-
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
-
- this->CreateFont();
- this->GetWndPointer();
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
-
- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
-
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
-
- int cx = GetSystemMetrics(SM_CXSCREEN);
- int cy = GetSystemMetrics(SM_CYSCREEN);
- //将主窗口分为一行两列
- if(m_Sp1.CreateStatic(this,1,2)==NULL)
- return FALSE;
- m_Sp1.SetColumnInfo(0,cx*2/3,100);
- //将左边的分为两行一列
- if(m_Sp3.CreateStatic(&m_Sp1,2,1,WS_CHILD|WS_VISIBLE, m_Sp1.IdFromRowCol(0, 0))==NULL)
- return FALSE;
- m_Sp3.SetRowInfo(0,100,100);
- //最大的窗口
- m_Sp3.CreateView(0,0,RUNTIME_CLASS(CTest1View),CSize(cx*3/4,cy-324), pContext);
-
- //将第二行分为一行三列
- if(m_Sp4.CreateStatic(&m_Sp3,1,3,WS_CHILD|WS_VISIBLE, m_Sp3.IdFromRowCol(1, 0))==NULL)
- return FALSE;
- m_Sp4.SetRowInfo(0,224,200);
- m_Sp4.CreateView(0,0,RUNTIME_CLASS(CXProject),CSize(224,224),pContext);
- m_Sp4.CreateView(0,1,RUNTIME_CLASS(CYProject),CSize(224,224),pContext);
- m_Sp4.CreateView(0,2,RUNTIME_CLASS(CZProject),CSize(224,224),pContext);
- //将右边的分为两行一列
- if(m_Sp2.CreateStatic(&m_Sp1,2,1,WS_CHILD|WS_VISIBLE, m_Sp1.IdFromRowCol(0, 1))==NULL)
- return FALSE;
- m_Sp2.CreateView(0,0,RUNTIME_CLASS(CControlWnd),CSize(400,400),pContext);
- m_Sp2.CreateView(1,0,RUNTIME_CLASS(CProjectView),CSize(cx/2,300),pContext);
- return TRUE;
- }
- void CMainFrame::GetWndPointer()
- {
- CWnd *pWnd = NULL;
- pWnd = this->m_Sp3.GetPane(0,0);
- this->m_pView = DYNAMIC_DOWNCAST(CTest1View,pWnd);
- pWnd = this->m_Sp2.GetPane(0,0);
- this->m_pCtrlWnd = DYNAMIC_DOWNCAST(CControlWnd, pWnd);
- pWnd = this->m_Sp2.GetPane(1,0);
- this->m_pProView = DYNAMIC_DOWNCAST(CProjectView, pWnd);
- pWnd = this->m_Sp4.GetPane(0,0);
- this->m_pXPro = DYNAMIC_DOWNCAST(CXProject, pWnd);
- pWnd = this->m_Sp4.GetPane(0,1);
- this->m_pYPro = DYNAMIC_DOWNCAST(CYProject, pWnd);
- pWnd = this->m_Sp4.GetPane(0,2);
- this->m_pZPro = DYNAMIC_DOWNCAST(CZProject, pWnd);
- }
- void CMainFrame::CreateFont()
- {
- m_13Font.CreateFont(
- 13, // nHeight
- 0, // nWidth
- 0, // nEscapement
- 0, // nOrientation
- FW_NORMAL, // nWeight
- FALSE, // bItalic
- FALSE, // bUnderline
- 0, // cStrikeOut
- ANSI_CHARSET, // nCharSet
- OUT_DEFAULT_PRECIS, // nOutPrecision
- CLIP_DEFAULT_PRECIS, // nClipPrecision
- DEFAULT_QUALITY, // nQuality
- DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
- "宋体"); // lpszFacename
- }
- void CMainFrame::CreateProcess()
- {
- RECT rect;
- m_wndStatusBar.GetItemRect(2,&rect);
- if(!m_bCreat)
- {
- m_Progress.Create(WS_VISIBLE|WS_CHILD|PBS_SMOOTH ,rect,&m_wndStatusBar,10);
- m_Progress.SetRange(0,100);
- m_Progress.SetStep(1);
- m_bCreat=TRUE;
- }
- }
- void CMainFrame::PrecessReadFile(WPARAM wP, LPARAM lp)
- {
- if (!m_bCreat)
- this->CreateProcess();
- int n = wP;
- CString str;
- // Sleep(30);
- m_Progress.SetPos(n);
- str.Format("文件加载中,请稍候... 进度%d%%",n);
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),str);//显示进度
- if (n==100)
- {
- m_Progress.SetPos(0);
- if (this->m_pView->m_bGetFileSuccess)
- {
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),"文件读取完成->开始图形显示");//显示进度
- this->InvalidateAllWnd();
- }
- if (!this->m_pView->m_bGetFileSuccess)
- {
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),"文件读取失败->请重新读取");//显示进度";
- MessageBox("文件读取失败,请重新加载或取系系统管理员!","警告",MB_ICONWARNING);
- }
- }
- }
- void CMainFrame::OnSize(UINT nType, int cx, int cy)
- {
- CFrameWnd::OnSize(nType, cx, cy);
-
- if(m_bCreat)
- {
- RECT rect;
- m_wndStatusBar.GetItemRect(2,&rect);
- m_Progress.SetWindowPos(&wndTop,rect.left ,rect.top,
- rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW);
- }
- }
- void CMainFrame::InvalidateAllWnd()
- {
- this->m_pView->Invalidate();
- m_pProView->Invalidate();
- m_pXPro->Invalidate();
- m_pYPro->Invalidate();
- m_pZPro->Invalidate();
- }
- void CMainFrame::OnClose()
- {
- if (::gbIsGetData)
- {
- MessageBox("正在读取数据,请稍候!","提示信息",MB_ICONINFORMATION);
- return;
- }
- // int nResult = MessageBox("确认退出系统?","提示信息",MB_ICONINFORMATION|MB_YESNO);
- // if (nResult == IDNO)
- // return;
- CFrameWnd::OnClose();
- }