📄 clockdlg.cpp
字号:
// clockDlg.cpp : implementation file
//
#include "stdafx.h"
#include "clock.h"
#include "clockDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CClockDlg dialog
CClockDlg::CClockDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClockDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClockDlg)
m_hours = _T("");
m_minutes = _T("");
m_seconds = _T("");
m_DAY = _T("");
m_MONTH = _T("");
m_YEAR = _T("");
m_CENTRY = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClockDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClockDlg)
DDX_Control(pDX, IDC_LINK2, m_LINK2);
DDX_Control(pDX, IDC_LINK3, m_LINK3);
DDX_Control(pDX, IDC_LINK1, m_LINK1);
DDX_Text(pDX, IDC_HOUR, m_hours);
DDX_Text(pDX, IDC_MINUTE, m_minutes);
DDX_Text(pDX, IDC_SECOND, m_seconds);
DDX_Text(pDX, IDC_day, m_DAY);
DDX_Text(pDX, IDC_month, m_MONTH);
DDX_Text(pDX, IDC_year, m_YEAR);
DDX_Text(pDX, IDC_CENTRY, m_CENTRY);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClockDlg, CDialog)
//{{AFX_MSG_MAP(CClockDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClockDlg message handlers
BOOL CClockDlg::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
/////////////////////////////////
//添加代码功能:安装定时器
//作者:王哲(王传章)
//单位:石油大学 数学系
//浮萍工作室
//////////////////////////////////
int iInstallresult;
iInstallresult=SetTimer(1,1000,NULL);
if(iInstallresult==0)
{
MessageBox("fail to install the timer!");
}
else
CurrentTime();//调用后面的函数
return TRUE; // return TRUE unless you set the focus to a control
}
void CClockDlg::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 CClockDlg::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 CClockDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
////////////////////////////////
//函数名:CurrentTime()
//功能:获取系统的当前时间
//作者:王哲(王传章)
//单位:浮萍工作室
//////////////////////////////////
void CClockDlg::CurrentTime()
{
time_t t1;//声明
char s1[ 256 ];
t1 = time ( ( time_t* ) NULL );// 获取系统时间
strftime ( s1, sizeof (s1), "%Y", localtime ( &t1) );
m_YEAR =s1;
strftime ( s1, sizeof (s1), "%m", localtime ( &t1) );
m_MONTH = s1;
strftime ( s1, sizeof (s1), "%d", localtime ( &t1) );
m_DAY = s1;
strftime ( s1, sizeof (s1), "%H", localtime ( &t1) );
m_hours = s1;
strftime ( s1, sizeof (s1), "%M", localtime ( &t1) );
m_minutes = s1;
strftime ( s1, sizeof (s1), "%S", localtime ( &t1) );
m_seconds = s1;
// 将各变量值赋给对话框相应ID号 对应的项
UpdateData(false);//或用下面三句也行
//( GetDlgItem ( IDC_HOUR ) ) -> SetWindowText ( m_hours );
//( GetDlgItem ( IDC_MINUTE ) ) -> SetWindowText ( m_minutes );
//( GetDlgItem ( IDC_SECOND ) ) -> SetWindowText ( m_seconds );
}
////////////////////////////////
//函数名:OnTimer()
//功能:定时器
//作者:王哲(王传章)
//单位:浮萍工作室
//////////////////////////////////
void CClockDlg::OnTimer(UINT nIDEvent)
{
CurrentTime();//调用此函数
CDialog::OnTimer(nIDEvent);
}
////////////////////////////////
//函数名:OnClose()
//功能:关闭窗口的模糊消失效果
//作者:王哲(王传章)
//单位:浮萍工作室
//////////////////////////////////
void CClockDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -