MainFrm.cpp
资源名称:一个学生管理系统.rar [点击查看]
上传用户:hzzhuce
上传日期:2013-04-01
资源大小:1289k
文件大小:6k
源码类别:
SQL Server
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "student.h"
- #include "MainFrm.h"
- #include "Splash.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_NCLBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- // CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- //if( !CFrameWnd::PreCreateWindow(cs) )
- // return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- // return TRUE;
- cs.lpszName="学生成绩管理系统 设计者:赵长胜";
- cs.x=220;
- cs.y=120;
- cs.cx=600;
- cs.cy=550;
- cs.style=WS_OVERLAPPEDWINDOW;
- return CFrameWnd::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- LRESULT CMainFrame::DefWindwoProc(UINT message,WPARAM wParam,LPARAM lParam)
- {
- LRESULT lrst=CFrameWnd::DefWindowProc(message,wParam,lParam);
- if(!::IsWindow(m_hWnd))
- return lrst;
- if(message==WM_NCPAINT||message==WM_NCACTIVATE||message==WM_NOTIFY)
- {
- CDC*pWinDC=GetWindowDC();
- if(pWinDC)
- DrawTitleBar(pWinDC);
- ReleaseDC(pWinDC);
- }
- return lrst;
- }
- void CMainFrame::DrawTitleBar(CDC*pDC)
- {
- if(!m_hWnd)return;
- CRect rtWnd,rtTitle,rtButtons;
- GetWindowRect(&rtWnd);
- rtTitle.left=GetSystemMetrics(SM_CXFRAME);
- rtTitle.top=GetSystemMetrics(SM_CYFRAME);
- rtTitle.right=rtWnd.right-rtWnd.left-GetSystemMetrics(SM_CXFRAME);
- rtTitle.bottom=rtTitle.top+GetSystemMetrics(SM_CYSIZE);
- DrawBmpTitleBar(pDC,rtTitle);
- HICON hIcon=(HICON)::GetClassLong(m_hWnd,GCL_HICON);
- m_rtIcon.left=rtTitle.right-GetSystemMetrics(SM_CYSMICON);
- m_rtIcon.top=rtTitle.top+1;
- m_rtIcon.right=m_rtIcon.left+GetSystemMetrics(SM_CXSMICON);
- m_rtIcon.bottom=m_rtIcon.top+GetSystemMetrics(SM_CYSMICON);
- DrawIconEx(pDC->m_hDC,m_rtIcon.left,m_rtIcon.top,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
- m_rtIcon.OffsetRect(rtWnd.TopLeft());
- int nButtHeight=GetSystemMetrics(SM_CYSMSIZE);
- rtButtons.left=rtTitle.left;
- rtButtons.top=rtTitle.top+(GetSystemMetrics(SM_CYSIZE)-nButtHeight)/2;
- rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
- rtButtons.bottom=rtButtons.top+nButtHeight;
- pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,DFCS_CAPTIONMIN);
- m_rtButtMin=rtButtons;
- m_rtButtMin.OffsetRect(rtWnd.TopLeft());
- rtButtons.left=rtButtons.right;
- rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
- pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,IsZoomed()?DFCS_CAPTIONRESTORE:DFCS_CAPTIONMAX);
- m_rtButtMax=rtButtons;
- m_rtButtMax.OffsetRect(rtWnd.TopLeft());
- rtButtons.left=rtButtons.right;
- rtButtons.right=rtButtons.left+GetSystemMetrics(SM_CXSMSIZE);
- pDC->DrawFrameControl(&rtButtons,DFC_CAPTION,DFCS_CAPTIONCLOSE);
- m_rtButtExit=rtButtons;
- m_rtButtExit.OffsetRect(rtWnd.TopLeft());
- int nOldMode=pDC->SetBkMode(TRANSPARENT);
- COLORREF clOldText=pDC->SetTextColor(RGB(0,0,0));
- pDC->SelectStockObject(ANSI_FIXED_FONT);
- rtTitle.right=GetSystemMetrics(SM_CYSMICON);
- pDC->DrawText((LPSTR)"自绘标题",-1,&rtTitle,DT_CENTER);
- pDC->SetBkMode(nOldMode);
- pDC->SetTextColor(clOldText);
- }
- void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
- {
- CFrameWnd::OnNcLButtonDown(nHitTest,point);
- if(m_rtButtExit.PtInRect(point))
- SendMessage(WM_CLOSE);
- else if(m_rtButtMin.PtInRect(point))
- SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,MAKELPARAM(point.x,point.y));
- else if(m_rtButtMax.PtInRect(point))
- {
- if(IsZoomed())
- SendMessage(WM_SYSCOMMAND,SC_RESTORE,MAKELPARAM(point.x,point.y));
- else
- SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,MAKELPARAM(point.x,point.y));
- }
- }
- void CMainFrame::DrawBmpTitleBar(CDC *pDC, CRect rcTitle)
- {
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP);
- CBrush brush;
- brush.CreatePatternBrush(&bmp);
- pDC->FillRect(rcTitle,&brush);
- }