MainFrm.cpp
上传用户:haifei
上传日期:2022-07-20
资源大小:77k
文件大小:4k
源码类别:

网络编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "AnalogMeterTest.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMainFrame
  13. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  14. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. ON_WM_CLOSE()
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. static UINT indicators[] =
  21. {
  22. ID_SEPARATOR,           // status line indicator
  23. ID_INDICATOR_CAPS,
  24. ID_INDICATOR_NUM,
  25. ID_INDICATOR_SCRL,
  26. };
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMainFrame construction/destruction
  29. CMainFrame::CMainFrame()
  30. {
  31. // TODO: add member initialization code here
  32. }
  33. CMainFrame::~CMainFrame()
  34. {
  35. }
  36. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  37. {
  38. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  39. return -1;
  40. if (!m_wndToolBar.Create(this) ||
  41. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  42. {
  43. TRACE0("Failed to create toolbarn");
  44. return -1;      // fail to create
  45. }
  46. if (!m_wndStatusBar.Create(this) ||
  47. !m_wndStatusBar.SetIndicators(indicators,
  48.   sizeof(indicators)/sizeof(UINT)))
  49. {
  50. TRACE0("Failed to create status barn");
  51. return -1;      // fail to create
  52. }
  53. // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  54. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  55. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  56. // TODO: Delete these three lines if you don't want the toolbar to
  57. //  be dockable
  58. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  59. EnableDocking(CBRS_ALIGN_ANY);
  60. DockControlBar(&m_wndToolBar);
  61. // Load stored Window position info
  62. WINDOWPLACEMENT wp;
  63. if (LoadWindowPlacement (&wp))
  64. {
  65. wp.showCmd = AfxGetApp ()->m_nCmdShow;
  66. SetWindowPlacement (&wp);
  67. }
  68. return 0;
  69. }
  70. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  71. {
  72. // TODO: Modify the Window class or styles here by modifying
  73. //  the CREATESTRUCT cs
  74. int maxx = GetSystemMetrics(SM_CXSCREEN);
  75. int maxy = GetSystemMetrics(SM_CYSCREEN);
  76. cs.style    = WS_OVERLAPPEDWINDOW ;
  77. cs.x        = maxx/10 ;
  78. cs.y        = maxy/10 ;
  79. cs.cx       = 4*maxx/5;
  80. cs.cy       = 4*maxy/5;
  81. cs.lpszName = "Performance Meter";
  82. return CFrameWnd::PreCreateWindow(cs);
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CMainFrame diagnostics
  86. #ifdef _DEBUG
  87. void CMainFrame::AssertValid() const
  88. {
  89. CFrameWnd::AssertValid();
  90. }
  91. void CMainFrame::Dump(CDumpContext& dc) const
  92. {
  93. CFrameWnd::Dump(dc);
  94. }
  95. #endif //_DEBUG
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CMainFrame message handlers
  98. void CMainFrame::OnClose() 
  99. {
  100. // Save window position info
  101. WINDOWPLACEMENT wp;
  102. if (GetWindowPlacement (&wp))
  103. {
  104. if (IsZoomed ())
  105. wp.flags |= WPF_RESTORETOMAXIMIZED;
  106. SaveWindowPlacement (&wp);
  107. }
  108. CFrameWnd::OnClose();
  109. }
  110. //
  111. // Get stored window postion
  112. //
  113. BOOL CMainFrame::LoadWindowPlacement(LPWINDOWPLACEMENT pwp)
  114. {
  115. CString strBuffer = AfxGetApp ()->GetProfileString (REG_SECTION, "WindowPos");
  116. if (strBuffer.IsEmpty ())
  117. return FALSE;
  118. int cRead = _stscanf (strBuffer, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i",
  119. &pwp->flags, &pwp->showCmd,
  120. &pwp->ptMinPosition.x, &pwp->ptMinPosition.y,
  121. &pwp->ptMaxPosition.x, &pwp->ptMaxPosition.y,
  122. &pwp->rcNormalPosition.left, &pwp->rcNormalPosition.top,
  123. &pwp->rcNormalPosition.right, &pwp->rcNormalPosition.bottom);
  124. if (cRead != 10)
  125. return FALSE;
  126. return TRUE;
  127. }
  128. //
  129. // Save window postion
  130. //
  131. void CMainFrame::SaveWindowPlacement(LPWINDOWPLACEMENT pwp)
  132. {
  133. // SaveWindowPlacement
  134. CString strBuffer;
  135. strBuffer.Format ("%i:%i:%i:%i:%i:%i:%i:%i:%i:%i",
  136. pwp->flags, pwp->showCmd,
  137. pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  138. pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  139. pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  140. pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  141. AfxGetApp ()->WriteProfileString (REG_SECTION, "WindowPos", strBuffer);
  142. }