⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 一个学生考试成绩管理的半成品
💻 CPP
字号:
// MainFrm.cpp : CMainFrame 类的实现
//

#include "stdafx.h"
#include "ScoreGather.h"
#include "MyCloseSystem.h"
#include "GetLunarDate.h"

#include "MainFrm.h"
#include ".\mainfrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_CREATE()
	// 全局帮助命令
	ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
	ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
	ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
	ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
	ON_COMMAND(ID_CLOSE_SYSTEM, OnCloseSystem)
	ON_WM_TIMER()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // 状态行指示器
	IDS_LUNARDATE,
	IDS_DATE,
	IDS_WEEK,
	IDS_TIME,
	IDS_STRTIME,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};


// CMainFrame 构造/析构

CMainFrame::CMainFrame()
{
	week.Add("星期日");
	week.Add("星期一");
	week.Add("星期二");
	week.Add("星期三");
	week.Add("星期四");
	week.Add("星期五");
	week.Add("星期六");
}

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("未能创建工具栏\n");
		return -1;      // 未能创建
	}
	//m_wndToolBar.ShowText(IDR_MAINFRAME);
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("未能创建状态栏\n");
		return -1;      // 未能创建
	}
	SetTimer(1,1000,NULL);
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	cs.style &= ~(LONG) FWS_ADDTOTITLE;
	return CFrameWnd::PreCreateWindow(cs);
}


// CMainFrame 诊断

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG


// CMainFrame 消息处理程序


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	CRect rect;
	GetClientRect(& rect);
	if(!m_wndSplitter.CreateStatic(this,1,2))
		return FALSE;
	if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyLeftView),CSize(rect.Width()/4,rect.Height()),pContext))
		return FALSE;
	if(!m_wndSplitter1.CreateStatic(& m_wndSplitter,2,1,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(0,1)))
		return FALSE;
	if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CScoreGatherView),CSize(rect.Width()-rect.Width()/4,380),pContext))
		return FALSE;
	if(!m_wndSplitter1.CreateView(1,0,RUNTIME_CLASS(CMyDownView),CSize(rect.Width(),50),pContext))
		return FALSE;
	m_pMyLeftView = (CMyLeftView*)m_wndSplitter1.GetPane(0,0);
	m_pScoreGatherView = (CScoreGatherView*)m_wndSplitter.GetPane(0,0); 
	m_pMyDownView = (CMyDownView*)m_wndSplitter1.GetPane(1,0);
	return TRUE;
}

void CMainFrame::OnCloseSystem()
{
	/*
	typedef int (CALLBACK *SHUTDOWNDLG)(int);   //显示关机对话框函数的指针
	HINSTANCE hInst = LoadLibrary("shell32.dll");  //装入shell32.dll
	SHUTDOWNDLG ShutDownDialog;    //指向shell32.dll库中显示关机对话框函数的指针
	if(hInst != NULL)
	{
		//获得函数的地址并调用之
		ShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
		(*ShutDownDialog)(0);
	}
	*/
	CMyCloseSystem dlg;
	dlg.DoModal();
	if(dlg.m_exit)
		CFrameWnd::OnClose();
}

void CMainFrame::OnTimer(UINT nIDEvent)
{
	CTime t=CTime::GetCurrentTime(); //获得当前的系统时间
	CClientDC dc(this);
	CString lunardate=StatusGetLunarDate();
	CString date=t.Format("%Y/%m/%d"); //格式可以参考MSDN中的strftime函数
	CString weekstr=week[t.GetDayOfWeek()-1];
	CString time=t.Format("%H:%M:%S");
	CString str_time; 
	str_time.Format("系统运行%d小时%d分",::GetTickCount()/1000/60/60,::GetTickCount()/1000/60 % 60);
	CSize sz=dc.GetTextExtent(lunardate); 
	CSize sz1=dc.GetTextExtent(date); //设置一个CClientDC对象来获取str的长度
	CSize sz2=dc.GetTextExtent(weekstr);
	CSize sz3=dc.GetTextExtent(time);
	CSize sz4=dc.GetTextExtent(str_time);
	m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_STRETCH,NULL);
	m_wndStatusBar.SetPaneInfo(1,IDS_LUNARDATE,SBPS_NORMAL,sz.cx-20);
	m_wndStatusBar.SetPaneText(1,lunardate);
	m_wndStatusBar.SetPaneInfo(2,IDS_DATE,SBPS_NORMAL,sz1.cx-5);
	m_wndStatusBar.SetPaneText(2,date);
	m_wndStatusBar.SetPaneInfo(3,IDS_WEEK,SBPS_NORMAL,sz2.cx-5);
	m_wndStatusBar.SetPaneText(3,weekstr);
	m_wndStatusBar.SetPaneInfo(4,IDS_TIME,SBPS_NORMAL,sz3.cx-5);
	m_wndStatusBar.SetPaneText(4,time);
	m_wndStatusBar.SetPaneInfo(5,IDS_STRTIME,SBPS_NORMAL,sz4.cx-20);
	m_wndStatusBar.SetPaneText(5,str_time);
	CFrameWnd::OnTimer(nIDEvent);
}

void CMainFrame::OnDestroy()
{
	CFrameWnd::OnDestroy();
	week.RemoveAll();
	CFrameWnd::KillTimer(1);
}

CString CMainFrame::StatusGetLunarDate(void)
{
	CGetLunarDate m_oCalendar;
	WORD iYear , iMonth, iDay;
	WORD iHolDay = CGetLunarDate::GetLunarDate(m_oCalendar.GetYear(), m_oCalendar.GetMonth(),m_oCalendar.GetDay(), iYear, iMonth, iDay); 
	char text[18];
	CString str,str1;
	CGetLunarDate::FormatLunarYear(iYear, text);
	str1.Format("  %s",text);
	str+=str1;
	CGetLunarDate::FormatMonth(iMonth, text);
	str1.Format("%s",text);
	str+=str1;
	CGetLunarDate::FormatLunarDay(iDay, text);
	str1.Format(" %s",text);
	str+=str1;
    char *HolText[] ={"小寒", "大寒", "立春", "雨水","惊蛰", "春分", "清明", "谷雨","立夏", "小满", "芒种", "夏至","小暑", "大暑", "立秋", "处暑","白露", "秋分", "寒露", "霜降","立冬", "小雪", "大雪", "冬至"};
	if(iHolDay)
	{
	   strcpy(text,"  今日 ");
	   strcat(text, HolText[iHolDay-1]);
	   str1.Format("%s",text);
	   str+=str1;
	}
	return str;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -