MainFrm.cpp
上传用户:hzzhuce
上传日期:2013-04-01
资源大小:1289k
文件大小:6k
源码类别:

SQL Server

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "student.h"
  5. #include "MainFrm.h"
  6. #include "Splash.h"
  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_DYNCREATE(CMainFrame, CFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. ON_WM_CREATE()
  18. ON_WM_NCLBUTTONDOWN()
  19. //}}AFX_MSG_MAP
  20. END_MESSAGE_MAP()
  21. static UINT indicators[] =
  22. {
  23. ID_SEPARATOR,           // status line indicator
  24. ID_INDICATOR_CAPS,
  25. ID_INDICATOR_NUM,
  26. ID_INDICATOR_SCRL,
  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. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  42. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  43. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  44. {
  45. TRACE0("Failed to create toolbarn");
  46. return -1;      // fail to create
  47. }
  48. if (!m_wndStatusBar.Create(this) ||
  49. !m_wndStatusBar.SetIndicators(indicators,
  50.   sizeof(indicators)/sizeof(UINT)))
  51. {
  52. TRACE0("Failed to create status barn");
  53. return -1;      // fail to create
  54. }
  55. // TODO: Delete these three lines if you don't want the toolbar to
  56. //  be dockable
  57. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  58. EnableDocking(CBRS_ALIGN_ANY);
  59. DockControlBar(&m_wndToolBar);
  60. // CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
  61. return 0;
  62. }
  63. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  64. {
  65. //if( !CFrameWnd::PreCreateWindow(cs) )
  66. // return FALSE;
  67. // TODO: Modify the Window class or styles here by modifying
  68. //  the CREATESTRUCT cs
  69. // return TRUE;
  70.     cs.lpszName="学生成绩管理系统                                设计者:赵长胜";
  71. cs.x=220;
  72. cs.y=120;
  73. cs.cx=600;
  74. cs.cy=550;
  75. cs.style=WS_OVERLAPPEDWINDOW;
  76. return CFrameWnd::PreCreateWindow(cs);
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CMainFrame diagnostics
  80. #ifdef _DEBUG
  81. void CMainFrame::AssertValid() const
  82. {
  83. CFrameWnd::AssertValid();
  84. }
  85. void CMainFrame::Dump(CDumpContext& dc) const
  86. {
  87. CFrameWnd::Dump(dc);
  88. }
  89. #endif //_DEBUG
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CMainFrame message handlers
  92. LRESULT CMainFrame::DefWindwoProc(UINT message,WPARAM wParam,LPARAM lParam)
  93. {
  94.         LRESULT lrst=CFrameWnd::DefWindowProc(message,wParam,lParam);
  95.         if(!::IsWindow(m_hWnd))
  96. return lrst;
  97. if(message==WM_NCPAINT||message==WM_NCACTIVATE||message==WM_NOTIFY)
  98. {
  99. CDC*pWinDC=GetWindowDC();
  100. if(pWinDC)
  101. DrawTitleBar(pWinDC);
  102. ReleaseDC(pWinDC);
  103. }
  104. return lrst;
  105. }
  106. void CMainFrame::DrawTitleBar(CDC*pDC)
  107. {
  108. if(!m_hWnd)return;
  109. CRect rtWnd,rtTitle,rtButtons;
  110. GetWindowRect(&rtWnd);
  111. rtTitle.left=GetSystemMetrics(SM_CXFRAME);
  112.     rtTitle.top=GetSystemMetrics(SM_CYFRAME);
  113. rtTitle.right=rtWnd.right-rtWnd.left-GetSystemMetrics(SM_CXFRAME);
  114. rtTitle.bottom=rtTitle.top+GetSystemMetrics(SM_CYSIZE);
  115. DrawBmpTitleBar(pDC,rtTitle);
  116. HICON hIcon=(HICON)::GetClassLong(m_hWnd,GCL_HICON);
  117. m_rtIcon.left=rtTitle.right-GetSystemMetrics(SM_CYSMICON);
  118. m_rtIcon.top=rtTitle.top+1;
  119. m_rtIcon.right=m_rtIcon.left+GetSystemMetrics(SM_CXSMICON);
  120. m_rtIcon.bottom=m_rtIcon.top+GetSystemMetrics(SM_CYSMICON);
  121. DrawIconEx(pDC->m_hDC,m_rtIcon.left,m_rtIcon.top,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
  122. m_rtIcon.OffsetRect(rtWnd.TopLeft());
  123. int nButtHeight=GetSystemMetrics(SM_CYSMSIZE);
  124. rtButtons.left=rtTitle.left;
  125. rtButtons.top=rtTitle.top+(GetSystemMetrics(SM_CYSIZE)-nButtHeight)/2;
  126. rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
  127. rtButtons.bottom=rtButtons.top+nButtHeight;
  128. pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,DFCS_CAPTIONMIN);
  129. m_rtButtMin=rtButtons;
  130. m_rtButtMin.OffsetRect(rtWnd.TopLeft());
  131. rtButtons.left=rtButtons.right;
  132. rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
  133.     pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,IsZoomed()?DFCS_CAPTIONRESTORE:DFCS_CAPTIONMAX);
  134. m_rtButtMax=rtButtons;
  135. m_rtButtMax.OffsetRect(rtWnd.TopLeft());
  136. rtButtons.left=rtButtons.right;
  137. rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
  138. pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,DFCS_CAPTIONCLOSE);
  139. m_rtButtExit=rtButtons;
  140. m_rtButtExit.OffsetRect(rtWnd.TopLeft());
  141. int nOldMode=pDC->SetBkMode(TRANSPARENT);
  142. COLORREF clOldText=pDC->SetTextColor(RGB(0,0,0));
  143. pDC->SelectStockObject(ANSI_FIXED_FONT);
  144. rtTitle.right=GetSystemMetrics(SM_CYSMICON);
  145. pDC->DrawText((LPSTR)"自绘标题",-1,&rtTitle,DT_CENTER);
  146. pDC->SetBkMode(nOldMode);
  147. pDC->SetTextColor(clOldText);
  148. }
  149. void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
  150. {
  151. CFrameWnd::OnNcLButtonDown(nHitTest,point);
  152. if(m_rtButtExit.PtInRect(point))
  153. SendMessage(WM_CLOSE);
  154. else if(m_rtButtMin.PtInRect(point))
  155. SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,MAKELPARAM(point.x,point.y));
  156. else if(m_rtButtMax.PtInRect(point))
  157. {
  158. if(IsZoomed())
  159. SendMessage(WM_SYSCOMMAND,SC_RESTORE,MAKELPARAM(point.x,point.y));
  160. else
  161. SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,MAKELPARAM(point.x,point.y));
  162. }
  163. }
  164. void CMainFrame::DrawBmpTitleBar(CDC *pDC, CRect rcTitle)
  165. {
  166. CBitmap bmp;
  167. bmp.LoadBitmap(IDB_BITMAP);
  168. CBrush brush;
  169. brush.CreatePatternBrush(&bmp);
  170. pDC->FillRect(rcTitle,&brush);
  171. }