studydlg.cpp
来自「这是一个学生信息管理系统」· C++ 代码 · 共 470 行 · 第 1/2 页
CPP
470 行
// StudyDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "SMS.h"
#include "StudyDlg.h"
// CStudyDlg 对话框
IMPLEMENT_DYNAMIC(CStudyDlg, CDialog)
CStudyDlg::CStudyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStudyDlg::IDD, pParent)
, m_pWordListSet(&theApp.m_db )
, m_pCourseSet(&theApp.m_db)
, m_pUserSet(&theApp.m_db )
{
//显示窗口颜色
m_backcolor=m_RGB_BkColor;
m_brush.CreateSolidBrush(m_backcolor);
}
CStudyDlg::~CStudyDlg()
{
}
void CStudyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STUDY_TAB, m_Study_TabCtrl);
}
BEGIN_MESSAGE_MAP(CStudyDlg, CDialog)
ON_NOTIFY(TCN_SELCHANGE, IDC_STUDY_TAB, &CStudyDlg::OnTcnSelchangeStudyTab)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_WM_CTLCOLOR()
ON_COMMAND(ID_STUDY_COURSE, &CStudyDlg::OnStudyCourse )
ON_COMMAND(ID_STUDY_PLAN, &CStudyDlg::OnStudyPlan )
ON_COMMAND(ID_STUDY_WORD, &CStudyDlg::OnStudyWord )
ON_COMMAND(ID_STUDY_LOGION, &CStudyDlg::OnStudyLogion )
ON_COMMAND(ID_STUDY_CLOSE, &CStudyDlg::OnStudyClose )
ON_UPDATE_COMMAND_UI(ID_STUDY_COURSE, &CStudyDlg::OnUpdateStudyCourse)
ON_UPDATE_COMMAND_UI(ID_STUDY_PLAN, &CStudyDlg::OnUpdateStudyPlan)
ON_UPDATE_COMMAND_UI(ID_STUDY_WORD, &CStudyDlg::OnUpdateStudyWord)
ON_UPDATE_COMMAND_UI(ID_STUDY_LOGION, &CStudyDlg::OnUpdateStudyLogion)
ON_WM_CONTEXTMENU()
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
// CStudyDlg 消息处理程序
BOOL CStudyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
//下面是学习主界面下的各个对话框的页面
SetTimer(STUDY_TIMER,10000,NULL);//英语单词的定时期,每隔10秒换一个单词
//先在初始化的时候显示,以免空白
//显示英语单词
CString StrWord;
if(m_pWordListSet.IsOpen())
m_pWordListSet.Close();
m_pWordListSet.Open();
int Count;
m_pWordListSet.m_strFilter .Empty ();
Count=m_pWordListSet.GetRecordCount();
if(Count==0)//如果没有单词,则显示默认的单词,要很经典才行
{
StrWord=L"Software Engineer\n(计算机)软件工程师\n常见职务";
SetDlgItemText(IDC_TODAY_WORD_STATIC,StrWord);
m_pWordListSet.Close ();
}
else//否则随机选择显示
{
Count=0;
m_pWordListSet.MoveFirst();
while(!m_pWordListSet.IsEOF())
{
m_pWordListSet.MoveNext();
Count++;//先计算总数
}
m_pWordListSet.MoveFirst();//再跳回到第一个
srand((unsigned)time(NULL)*rand());
srand((unsigned) time(NULL)*rand());
srand(rand());//再种多一个随机种子
int rth=rand()%Count;//随机找到那个
int i=0;
while(!m_pWordListSet.IsEOF())
{
if(i==rth)//随机取一个
{
StrWord=m_pWordListSet.m_wWord +L"\n"+m_pWordListSet.m_wMean +L"\n"+m_pWordListSet.m_wGroup ;
break;
}
i++;
m_pWordListSet.MoveNext();
}
m_pWordListSet.Close();
}
SetDlgItemText(IDC_TODAY_WORD_STATIC,StrWord);
///////课程表也必须在启动的时候显示作为一种不变的信息
CString StrCourse=L"";
CTime tTime=CTime::GetCurrentTime();
CString StrDayOfWeek;
CString TimeOfDay;
int Length;
int nDayOfWeek=tTime.GetDayOfWeek ();
if(m_pCourseSet.IsOpen ())
m_pCourseSet.Close ();
m_pCourseSet.Open ();
if(m_pCourseSet.GetRecordCount ()==0)//如果为空,则显示休息信息
{
StrCourse=L"暂时还没有课程表,您可以休息了!";
SetDlgItemText(IDC_TODAY_COURSE_STATIC,StrCourse);
m_pCourseSet.Close ();
}
else//否则根据星期显示
{
if(m_pUserSet.IsOpen ())
m_pUserSet.Close ();
m_pUserSet.Open ();
//用户表肯定不可能空!
m_pUserSet.MoveFirst ();
int nTerm=m_pUserSet.m_uTerm ;//取得用户所属的学期
m_pCourseSet.MoveFirst ();
while(!m_pCourseSet.IsEOF ())
{
if(nTerm!=m_pCourseSet.m_cTerm )//如果学期不同,则跳过
{
m_pCourseSet.MoveNext ();
continue;
}
TimeOfDay=StrDayOfWeek=(CString)m_pCourseSet.m_cTime;
Length=StrDayOfWeek.GetLength ();
StrDayOfWeek.Delete (2,Length-2);//只取周次
TimeOfDay.Delete (0,3);//只取节次
switch(nDayOfWeek)
{
case 1://周日
if(StrDayOfWeek==L"周日")
StrCourse+=m_pCourseSet.m_cName +L" "+TimeOfDay +L" "+m_pCourseSet.m_cPlace+L" ";//把最重要的信息列出来
break;
case 2://周一
if(StrDayOfWeek==L"周一")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
case 3://周二
if(StrDayOfWeek==L"周二")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
case 4://周三
if(StrDayOfWeek==L"周三")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
case 5://周四
if(StrDayOfWeek==L"周四")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
case 6://周五
if(StrDayOfWeek==L"周五")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
case 7://周六
if(StrDayOfWeek==L"周六")
StrCourse+=L"课程:"+m_pCourseSet.m_cName +L" 时间:"+TimeOfDay +L" 地点:"+m_pCourseSet.m_cPlace+L"\n";//把最重要的信息列出来
break;
}
m_pCourseSet.MoveNext ();
}
m_pCourseSet.Close ();
SetDlgItemText(IDC_TODAY_COURSE_STATIC,StrCourse);
}
TCITEM item;
item.mask =TCIF_TEXT;
CRect r;
m_Study_TabCtrl.GetClientRect (&r);
item.pszText =_T("课程表");
m_Study_TabCtrl.InsertItem (0,&item);
item.pszText =_T("学习计划");
m_Study_TabCtrl.InsertItem (1,&item);
item.pszText =_T("英语单词");
m_Study_TabCtrl.InsertItem (2,&item);
item.pszText =_T("名人名言");
m_Study_TabCtrl.InsertItem (3,&item);
//下面是控制显示位置
m_StudyTimetableDlg.Create (IDD_STUDY_TIMETABLE_DLG, &m_Study_TabCtrl);
m_StudyPlanDlg.Create (IDD_STUDY_PLAN_DLG, &m_Study_TabCtrl);
m_StudyWordDlg.Create (IDD_STUDY_WORD_DLG, &m_Study_TabCtrl);
m_StudyLogionDlg.Create (IDD_STUDY_LOGION_DLG, &m_Study_TabCtrl);
m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CStudyDlg::OnTcnSelchangeStudyTab(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CRect r;
m_Study_TabCtrl.GetClientRect (&r);
switch(m_Study_TabCtrl.GetCurSel ())
{
case 0:
m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
break;
case 1:
m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
break;
case 2:
m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
break;
case 3:
m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?