📄 classbelldlg.cpp
字号:
// classbellDlg.cpp : implementation file
//
#include "stdafx.h"
#include "classbell.h"
#include "classbellDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClassbellDlg dialog
CClassbellDlg::CClassbellDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClassbellDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClassbellDlg)
m_clock = _T("");
m_minute = _T("");
m_TIP = _T("");
m_breaktip = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClassbellDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClassbellDlg)
DDX_Text(pDX, IDC_STATIME, m_clock);
DDX_Text(pDX, IDC_STATIME2, m_minute);
DDV_MaxChars(pDX, m_minute, 2);
DDX_Text(pDX, IDC_STATICTIP, m_TIP);
DDX_Text(pDX, IDC_STATIC_BREAK, m_breaktip);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClassbellDlg, CDialog)
//{{AFX_MSG_MAP(CClassbellDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_EN_CHANGE(IDC_STATIME2, OnChangeStatime2)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClassbellDlg message handlers
BOOL CClassbellDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_time =0;
this->SetTimer(1,60000,NULL);
m_begin = false;
CTime time = CTime::GetCurrentTime();
m_clock.Format("%d:%02d",time.GetHour(),time.GetMinute());
m_minute = "0";
m_TIP = "程序已停止...";
m_breaktip = "已上课:";
this->UpdateData(FALSE);
m_breaktime = 10;
return TRUE; // return TRUE unless you set the focus to a control
}
void CClassbellDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CClassbellDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CClassbellDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CClassbellDlg::OnTimer(UINT nIDEvent)
{
CTime time = CTime::GetCurrentTime();
m_clock.Format("%d:%02d",time.GetHour(),time.GetMinute());
if(m_begin)
{
m_time++;
if(m_time<45)
m_minute.Format("%d",m_time);
else
m_minute.Format("%d",m_time-45);
this->UpdateData(FALSE);
if(m_time == 45)
{
//AfxMessageBox("下课了!");
m_TIP = "下课了!放松一下吧!\n...不要让自己瞧不起自己!";
m_breaktip = "已下课:";
m_minute = "0";
this->UpdateData(FALSE);
for(int i=0;i<=10;i++)
{
::Beep(1810,60);
Sleep(3);
::Beep(1850,80);
::Beep(1850,300);
Sleep(200);
}
}
if(m_time == 45+m_breaktime)
{
// AfxMessageBox("上课了!");
m_TIP = "上课了,请安静...\n从现在作起......";
m_breaktip = "已上课:";
m_minute = "0";
OnButton5();
this->UpdateData(FALSE);
for(int i=0;i<=10;i++)
{
::Beep(1850,50);
Sleep(3);
::Beep(1880,80);
::Beep(1880,300);
Sleep(200);
}
m_time =0;
}
}
this->UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
void CClassbellDlg::OnButton1()
{
m_time =0;
m_begin = true;
m_TIP = "上课了,请安静...\n从现在作起......";
m_breaktip = "已上课:";
((CButton*)GetDlgItem(IDC_PAUSE))->SetWindowText("暂停(&P)");
m_minute = "0";
this->UpdateData(FALSE);
}
void CClassbellDlg::OnButton2()
{
m_time =0;
m_begin = false;
m_TIP = "程序已停止...";
((CButton*)GetDlgItem(IDC_PAUSE))->SetWindowText("暂停(&P)");
this->UpdateData(FALSE);
}
void CClassbellDlg::OnDestroy()
{
CDialog::OnDestroy();
this->KillTimer(1);
}
void CClassbellDlg::OnButton5()
{
if(m_breaktime == 10)
{
((CButton*)GetDlgItem(IDC_BUTTON5))->SetWindowText("二十分钟。");
m_breaktime = 20;
}
else
{
((CButton*)GetDlgItem(IDC_BUTTON5))->SetWindowText("十分钟。");
m_breaktime = 10;
}
}
void CClassbellDlg::OnChangeStatime2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
this->UpdateData(TRUE);
int minute = atoi(m_minute);
if(m_time<=45)
{
if(minute<45)
{
m_time = minute;
}
else
{
m_time =44;
m_minute = "44";
this->UpdateData(FALSE);
}
}
else
{
if(minute<=m_breaktime)
{
m_time = minute+45;
}
else
{
m_time =m_breaktime;
m_minute = m_breaktime;
this->UpdateData(FALSE);
}
}
}
void CClassbellDlg::OnPause()
{
if(m_begin)
{
m_begin = FALSE;
((CButton*)GetDlgItem(IDC_PAUSE))->SetWindowText("恢复(&P)");
m_TIP = "\n程序已暂停...";
this->UpdateData(FALSE);
}
else
{
m_begin = TRUE;
((CButton*)GetDlgItem(IDC_PAUSE))->SetWindowText("暂停(&P)");
m_TIP ="继续开始吧...";
this->UpdateData(FALSE);
}
}
BOOL CClassbellDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_NCLBUTTONDOWN)
{
if(pMsg->wParam == HTMINBUTTON)
{
// AfxMessageBox("small!");
// return 0;
}
if(pMsg->wParam == HTMAXBUTTON)
{
// AfxMessageBox("big!");
// return 0;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -