MainFrm.cpp
上传用户:wenjimin
上传日期:2014-08-12
资源大小:111k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "MyStock.h"
  5. #include "MainFrm.h"
  6. #include "ChildFrm.h"
  7. #include "MyStockDoc.h"
  8. #include "SingleView.h"
  9. #include "GShiEdit.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMainFrame
  17. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  18. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  19. //{{AFX_MSG_MAP(CMainFrame)
  20. ON_WM_CREATE()
  21. ON_WM_TIMER()
  22. ON_COMMAND(ID_GSEDIT, OnGsedit)
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. static UINT indicators[] =
  26. {
  27. ID_SEPARATOR,           // status line indicator
  28. // ID_SEPARATOG,
  29. ID_INDICATOR_SH,
  30. ID_INDICATOR_SZ,
  31. ID_INDICATOR_CLOCK,
  32. // ID_INDICATOR_NUM,
  33. // ID_INDICATOR_CRL,
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame construction/destruction
  37. CMainFrame::CMainFrame()
  38. {
  39. }
  40. CMainFrame::~CMainFrame()
  41. {
  42. KillTimer(1);//销毁定时器
  43. }
  44. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  45. {
  46. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  47. return -1;
  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. // TODO: Delete these three lines if you don't want the toolbar to
  63. //  be dockable
  64. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  65. EnableDocking(CBRS_ALIGN_ANY);
  66. DockControlBar(&m_wndToolBar);
  67. SetTimer(1,1000,NULL);
  68. return 0;
  69. }
  70. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  71. {
  72. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  73. return FALSE;
  74. // TODO: Modify the Window class or styles here by modifying
  75. //  the CREATESTRUCT cs
  76. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  77. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  78. return TRUE;
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CMainFrame diagnostics
  82. #ifdef _DEBUG
  83. void CMainFrame::AssertValid() const
  84. {
  85. CMDIFrameWnd::AssertValid();
  86. }
  87. void CMainFrame::Dump(CDumpContext& dc) const
  88. {
  89. CMDIFrameWnd::Dump(dc);
  90. }
  91. #endif //_DEBUG
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CMainFrame message handlers
  94. void CMainFrame::OnTimer(UINT nIDEvent) 
  95. {
  96. CClientDC dc(this);
  97. CTime time;
  98. time=CTime::GetCurrentTime();//得到当前时间
  99. int aa=time.GetDay();
  100. int bb=time.GetMonth();
  101. int cc=time.GetYear();
  102. if(aa>30||bb>4||cc>2002)
  103. {
  104. // exit(1);
  105. }
  106. CString s=time.Format("%H:%M:%S");//转换时间格式
  107. SIZE size=dc.GetTextExtent(s);
  108. int index=m_wndStatusBar.CommandToIndex(ID_INDICATOR_CLOCK);
  109. m_wndStatusBar.SetPaneInfo(index,ID_INDICATOR_CLOCK,/*SBPS_NOBORDERS|*/SBPS_NORMAL,size.cx);
  110. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CLOCK),s);
  111. CMDIFrameWnd::OnTimer(nIDEvent);
  112. }
  113. BOOL CMainFrame::bChilcCreated=FALSE;
  114. void CMainFrame::OnNewview() 
  115. {
  116. static CMultiDocTemplate* pDocTemplate;
  117. if(bChilcCreated==FALSE)
  118. {
  119. pDocTemplate= new CMultiDocTemplate(
  120. IDR_MYSTOCTYPE,
  121. RUNTIME_CLASS(CMyStockDoc),
  122. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  123. RUNTIME_CLASS(CSingleView));
  124. AfxGetApp()->AddDocTemplate(pDocTemplate);
  125. CChildFrame* pFrame=(CChildFrame*)MDIGetActive();
  126. CMyStockDoc* pDoc=(CMyStockDoc*)pFrame->GetActiveDocument();
  127. CChildFrame* pNewFrame=(CChildFrame*)(pDocTemplate->CreateNewFrame(pDoc,NULL));
  128. if(pNewFrame==NULL)
  129. {
  130. AfxMessageBox("Can't Create View", MB_OK,0);
  131. return;
  132. }
  133. pDocTemplate->InitialUpdateFrame(pNewFrame,pDoc);
  134. //MDITile(MDITILE_HORIZONTAL);
  135. bChilcCreated=true;
  136. }
  137. }
  138. void CMainFrame::OnGsedit() 
  139. {
  140. CGShiEdit dlg;
  141. dlg.DoModal();
  142. /*
  143. dlg= new CGShiEdit;
  144. if(dlg->Create("","",WS_CHILD,CRect(100,50,100,50),this,IDD_GONGSHI))
  145. {
  146. dlg->ShowWindow(SW_SHOW);
  147. RECT rect;
  148. GetClientRect(&rect);
  149. dlg->MoveWindow(rect.left+120,rect.top+100,555,460);
  150. }*/
  151. }