MainFrm.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:7k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "ControlWnd.h"
  6. #include "ProjectView.h"
  7. #include "MainFrm.h"
  8. #include "XProject.h"
  9. #include "YProject.h"
  10. #include "ZProject.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMainFrame
  18. extern bool gbIsGetData;
  19. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21. //{{AFX_MSG_MAP(CMainFrame)
  22. ON_WM_CREATE()
  23. ON_WM_SIZE()
  24. ON_WM_CLOSE()
  25. //}}AFX_MSG_MAP
  26. ON_MESSAGE(MESSAGE_STEPPRO,PrecessReadFile)
  27. END_MESSAGE_MAP()
  28. static UINT indicators[] =
  29. {
  30. ID_SEPARATOR,           // status line indicator
  31. ID_PROGRESSTEXT,
  32. ID_PROGRESSAREA,
  33. ID_INDICATOR_CAPS,
  34. ID_INDICATOR_NUM,
  35. ID_INDICATOR_SCRL,
  36. };
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame construction/destruction
  39. CMainFrame::CMainFrame()
  40. {
  41. m_pView = NULL;
  42. m_bCreat = FALSE;
  43. }
  44. CMainFrame::~CMainFrame()
  45. {
  46. }
  47. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  48. {
  49. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  50. return -1;
  51. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  52. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  53. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  54. {
  55. TRACE0("Failed to create toolbarn");
  56. return -1;      // fail to create
  57. }
  58. if (!m_wndStatusBar.Create(this) ||
  59. !m_wndStatusBar.SetIndicators(indicators,
  60. sizeof(indicators)/sizeof(UINT)))
  61. {
  62. TRACE0("Failed to create status barn");
  63. return -1;      // fail to create
  64. }
  65. // TODO: Delete these three lines if you don't want the toolbar to
  66. //  be dockable
  67. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  68. EnableDocking(CBRS_ALIGN_ANY);
  69. DockControlBar(&m_wndToolBar);
  70. this->CreateFont();
  71. this->GetWndPointer();
  72. return 0;
  73. }
  74. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  75. {
  76. if( !CFrameWnd::PreCreateWindow(cs) )
  77. return FALSE;
  78. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  79. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  80. return TRUE;
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CMainFrame diagnostics
  84. #ifdef _DEBUG
  85. void CMainFrame::AssertValid() const
  86. {
  87. CFrameWnd::AssertValid();
  88. }
  89. void CMainFrame::Dump(CDumpContext& dc) const
  90. {
  91. CFrameWnd::Dump(dc);
  92. }
  93. #endif //_DEBUG
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CMainFrame message handlers
  96. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  97. {
  98. int cx = GetSystemMetrics(SM_CXSCREEN);
  99. int cy = GetSystemMetrics(SM_CYSCREEN);
  100. //将主窗口分为一行两列
  101.     if(m_Sp1.CreateStatic(this,1,2)==NULL) 
  102. return FALSE;
  103. m_Sp1.SetColumnInfo(0,cx*2/3,100);
  104. //将左边的分为两行一列
  105. if(m_Sp3.CreateStatic(&m_Sp1,2,1,WS_CHILD|WS_VISIBLE, m_Sp1.IdFromRowCol(0, 0))==NULL) 
  106. return FALSE;
  107. m_Sp3.SetRowInfo(0,100,100);
  108. //最大的窗口
  109.     m_Sp3.CreateView(0,0,RUNTIME_CLASS(CTest1View),CSize(cx*3/4,cy-324), pContext); 
  110.    
  111. //将第二行分为一行三列
  112. if(m_Sp4.CreateStatic(&m_Sp3,1,3,WS_CHILD|WS_VISIBLE, m_Sp3.IdFromRowCol(1, 0))==NULL) 
  113. return FALSE;
  114. m_Sp4.SetRowInfo(0,224,200);
  115. m_Sp4.CreateView(0,0,RUNTIME_CLASS(CXProject),CSize(224,224),pContext);
  116.     m_Sp4.CreateView(0,1,RUNTIME_CLASS(CYProject),CSize(224,224),pContext); 
  117. m_Sp4.CreateView(0,2,RUNTIME_CLASS(CZProject),CSize(224,224),pContext); 
  118. //将右边的分为两行一列
  119. if(m_Sp2.CreateStatic(&m_Sp1,2,1,WS_CHILD|WS_VISIBLE, m_Sp1.IdFromRowCol(0, 1))==NULL) 
  120. return FALSE; 
  121.     m_Sp2.CreateView(0,0,RUNTIME_CLASS(CControlWnd),CSize(400,400),pContext);
  122.     m_Sp2.CreateView(1,0,RUNTIME_CLASS(CProjectView),CSize(cx/2,300),pContext); 
  123.     return TRUE;  
  124. }
  125. void CMainFrame::GetWndPointer()
  126. {
  127. CWnd *pWnd = NULL;
  128. pWnd = this->m_Sp3.GetPane(0,0);
  129. this->m_pView = DYNAMIC_DOWNCAST(CTest1View,pWnd);
  130. pWnd = this->m_Sp2.GetPane(0,0);
  131. this->m_pCtrlWnd = DYNAMIC_DOWNCAST(CControlWnd, pWnd);
  132. pWnd = this->m_Sp2.GetPane(1,0);
  133. this->m_pProView = DYNAMIC_DOWNCAST(CProjectView, pWnd);
  134. pWnd = this->m_Sp4.GetPane(0,0);
  135. this->m_pXPro = DYNAMIC_DOWNCAST(CXProject, pWnd);
  136. pWnd = this->m_Sp4.GetPane(0,1);
  137. this->m_pYPro = DYNAMIC_DOWNCAST(CYProject, pWnd);
  138. pWnd = this->m_Sp4.GetPane(0,2);
  139. this->m_pZPro = DYNAMIC_DOWNCAST(CZProject, pWnd);
  140. }
  141. void CMainFrame::CreateFont()
  142. {
  143. m_13Font.CreateFont(
  144. 13,                        // nHeight
  145. 0,                         // nWidth
  146. 0,                         // nEscapement
  147. 0,                         // nOrientation
  148. FW_NORMAL,                 // nWeight
  149. FALSE,                     // bItalic
  150. FALSE,                     // bUnderline
  151. 0,                         // cStrikeOut
  152. ANSI_CHARSET,              // nCharSet
  153. OUT_DEFAULT_PRECIS,        // nOutPrecision
  154. CLIP_DEFAULT_PRECIS,       // nClipPrecision
  155. DEFAULT_QUALITY,           // nQuality
  156. DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
  157. "宋体");                 // lpszFacename
  158. }
  159. void CMainFrame::CreateProcess()
  160. {
  161. RECT rect;
  162. m_wndStatusBar.GetItemRect(2,&rect);
  163. if(!m_bCreat)
  164. {
  165. m_Progress.Create(WS_VISIBLE|WS_CHILD|PBS_SMOOTH  ,rect,&m_wndStatusBar,10);
  166. m_Progress.SetRange(0,100);
  167. m_Progress.SetStep(1);
  168. m_bCreat=TRUE;
  169. }
  170. }
  171. void CMainFrame::PrecessReadFile(WPARAM wP, LPARAM lp)
  172. {
  173. if (!m_bCreat)
  174. this->CreateProcess();
  175. int n = wP;
  176. CString str;
  177. // Sleep(30);
  178. m_Progress.SetPos(n);
  179. str.Format("文件加载中,请稍候...  进度%d%%",n);
  180. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),str);//显示进度
  181. if (n==100)
  182. {
  183. m_Progress.SetPos(0);
  184. if (this->m_pView->m_bGetFileSuccess)
  185. {
  186. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),"文件读取完成->开始图形显示");//显示进度
  187. this->InvalidateAllWnd();
  188. }
  189. if (!this->m_pView->m_bGetFileSuccess)
  190. {
  191. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PROGRESSTEXT),"文件读取失败->请重新读取");//显示进度";
  192. MessageBox("文件读取失败,请重新加载或取系系统管理员!","警告",MB_ICONWARNING);
  193. }
  194. }
  195. }
  196. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  197. {
  198. CFrameWnd::OnSize(nType, cx, cy);
  199. if(m_bCreat)
  200. {
  201. RECT rect;
  202. m_wndStatusBar.GetItemRect(2,&rect);
  203. m_Progress.SetWindowPos(&wndTop,rect.left ,rect.top,
  204. rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW);
  205. }
  206. }
  207. void CMainFrame::InvalidateAllWnd()
  208. {
  209. this->m_pView->Invalidate();
  210. m_pProView->Invalidate();
  211. m_pXPro->Invalidate();
  212. m_pYPro->Invalidate();
  213. m_pZPro->Invalidate();
  214. }
  215. void CMainFrame::OnClose() 
  216. {
  217. if (::gbIsGetData)
  218. {
  219. MessageBox("正在读取数据,请稍候!","提示信息",MB_ICONINFORMATION);
  220. return;
  221. }
  222. // int nResult = MessageBox("确认退出系统?","提示信息",MB_ICONINFORMATION|MB_YESNO);
  223. // if (nResult == IDNO)
  224. // return;
  225. CFrameWnd::OnClose();
  226. }