MainFrm.cpp
上传用户:lin85885
上传日期:2013-04-27
资源大小:796k
文件大小:5k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "Simplifier.h"
  5. #include "MainFrm.h"
  6. #define IDC_PROGRESS 105
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. ON_WM_CREATE()
  18. ON_WM_SETFOCUS()
  19. ON_WM_SIZE()
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. static UINT indicators[] =
  23. {
  24. ID_SEPARATOR,           // status line indicator
  25. ID_INDICATOR_CAPS,
  26. ID_INDICATOR_NUM,
  27. };
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CMainFrame construction/destruction
  30. CMainFrame::CMainFrame()
  31. {
  32. // TODO: add member initialization code here
  33. }
  34. CMainFrame::~CMainFrame()
  35. {
  36. }
  37. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  38. {
  39. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  40. return -1;
  41. // create a view to occupy the client area of the frame
  42. if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
  43. CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
  44. {
  45. TRACE0("Failed to create view windown");
  46. return -1;
  47. }
  48. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  49. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  50. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  51. {
  52. TRACE0("Failed to create toolbarn");
  53. return -1;      // fail to create
  54. }
  55. if (!m_wndStatusBar.Create(this)||
  56. !m_wndStatusBar.SetIndicators(indicators,
  57. sizeof(indicators)/sizeof(UINT)))
  58. {
  59. TRACE0("Failed to create status barn");
  60. return -1;      // fail to create
  61. }
  62. if (!m_wndInteractLeft.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  63. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  64. !m_wndInteractLeft.LoadToolBar(IDR_INTERACT_LEFT))
  65. {
  66. TRACE0("Failed to create toolbarn");
  67. return -1;      // fail to create
  68. }
  69. if (!m_wndInteractRight.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  70. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  71. !m_wndInteractRight.LoadToolBar(IDR_INTERACT_RIGHT))
  72. {
  73. TRACE0("Failed to create toolbarn");
  74. return -1;      // fail to create
  75. }
  76. m_wndStatusBar.SetPaneText(1,"原始模型:0");
  77. m_wndStatusBar.SetPaneText(2,"简化模型:0");
  78. // TODO: Delete these three lines if you don't want the toolbar to
  79. //  be dockable
  80. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  81. m_wndInteractLeft.EnableDocking(CBRS_ALIGN_ANY);
  82. m_wndInteractRight.EnableDocking(CBRS_ALIGN_ANY);
  83. EnableDocking(CBRS_ALIGN_ANY);
  84. DockControlBar(&m_wndToolBar);
  85. DockControlBar(&m_wndInteractLeft, AFX_IDW_DOCKBAR_LEFT);
  86. DockControlBar(&m_wndInteractRight, AFX_IDW_DOCKBAR_RIGHT);
  87. if (!m_Progress.Create( WS_CHILD | WS_VISIBLE , CRect(280,2,450,18), &m_wndStatusBar, IDC_PROGRESS ))
  88. {
  89. TRACE0("Failed to create progress control n");
  90. return -1;      // fail to create
  91. }
  92. m_Progress.SetRange(0,100);
  93. m_Progress.SetPos(0);
  94. return 0;
  95. }
  96. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  97. {
  98. cs.cx = 472;
  99. cs.cy = 460;
  100. if( !CFrameWnd::PreCreateWindow(cs) )
  101. return FALSE;
  102. // TODO: Modify the Window class or styles here by modifying
  103. //  the CREATESTRUCT cs
  104. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  105. cs.lpszClass = AfxRegisterWndClass(0);
  106. return TRUE;
  107. }
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMainFrame diagnostics
  110. #ifdef _DEBUG
  111. void CMainFrame::AssertValid() const
  112. {
  113. CFrameWnd::AssertValid();
  114. }
  115. void CMainFrame::Dump(CDumpContext& dc) const
  116. {
  117. CFrameWnd::Dump(dc);
  118. }
  119. #endif //_DEBUG
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CMainFrame message handlers
  122. void CMainFrame::OnSetFocus(CWnd* pOldWnd)
  123. {
  124. // forward focus to the view window
  125. m_wndView.SetFocus();
  126. }
  127. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  128. {
  129. // let the view have first crack at the command
  130. if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  131. return TRUE;
  132. // otherwise, do default handling
  133. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  134. }
  135. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  136. {
  137. CFrameWnd::OnSize(nType, cx, cy);
  138. UINT statusPaneID, nStyle;
  139. int cxWidth;
  140. RECT rect;
  141. GetClientRect( &rect );
  142. m_wndStatusBar.GetPaneInfo( 0, statusPaneID, nStyle, cxWidth);
  143. m_wndStatusBar.SetPaneInfo( 0, statusPaneID, SBPS_NOBORDERS, (rect.right-rect.left)/5);
  144. m_wndStatusBar.SetPaneInfo( 1, statusPaneID, SBPS_NORMAL, (rect.right-rect.left)/5);
  145. m_wndStatusBar.SetPaneInfo( 2, statusPaneID, SBPS_NORMAL, (rect.right-rect.left)/5);
  146. m_Progress.MoveWindow((rect.right-rect.left)*3/5+25,2,(rect.right-rect.left)*2/5-25,17);
  147. }