📄 clockdlg.cpp
字号:
// clockDlg.cpp : implementation file
//Made By Alex Huang 川大软件学院02级3班
//这是一个二进制时钟,按回车则显示十进制,15秒后跳回二进制显示
//ESC键退出程序
//特别适合搞底层的同学,呵呵
#include "stdafx.h"
#include "clock.h"
#include "clockDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClockDlg dialog
CClockDlg::CClockDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClockDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClockDlg)
// NOTE: the ClassWizard will add member initialization here
//}}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_STATIC_DESIGN, m_mytext);
DDX_Control(pDX, IDC_STATIC_SHOW, m_show);
DDX_Control(pDX, IDC_EDIT1, m_clock);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClockDlg, CDialog)
//{{AFX_MSG_MAP(CClockDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClockDlg message handlers
BOOL CClockDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//初始化得到当前本地时间
tt=CTime::GetCurrentTime();
CString stime="";
stime=tt.Format("%H:%M:%S");
//显示本地时间
m_clock.SetWindowText(stime);
key=0;//开关设置为二进制显示模式
SetTimer(1,500,NULL);//每隔500毫秒刷新
return TRUE; // return TRUE unless you set the focus to a control
}
// 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;
}
//每次刷新所做的事情
void CClockDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
tt=CTime::GetCurrentTime();
// time_t osBinaryTime = tt.GetTime(); // time_t defined in <time.h>
CString stime;
char hh=tt.GetHour();
char mm=tt.GetMinute();
char ss=tt.GetSecond();
//如果十进制开关开启,将显示十进制时间,并开始倒计时
if(key>0)
{
stime=tt.Format("%H:%M:%S");
m_clock.SetWindowText(stime);
m_mytext.SetWindowText("Design By Alex Huang!");
key--;
}
//转化成二进制
for(int i=0;i<=4;i++)
{
shh[i]=hh%2+48;
hh/=2;
}
shh[5]='\0';
for(i=0;i<6;i++)
{
smm[i]=mm%2+48;
mm/=2;
}
smm[6]=0;
for(i=0;i<6;i++)
{
sss[i]=ss%2+48;
ss/=2;
}
sss[6]=0;
stime.Format("%s:%s:%s",sss,smm,shh);
stime.MakeReverse();
//如果十进制时间开关关了(key为0)则显示二进制时间
if(key==0)
{
m_clock.SetWindowText(stime);
m_mytext.SetWindowText("Hello World!");
}
char temp[20];
//显示二进制灯泡
for(i=0;i<stime.GetLength();i++)
{
switch(stime.GetAt(i))
{
case 48:
temp[i]=8;
break;
case 49:
temp[i]=7;
break;
case ':':
temp[i]=':';
break;
}
}
temp[19]=0;
stime.Format("%s",temp);
m_show.SetWindowText(stime);
CDialog::OnTimer(nIDEvent);
}
//按回车后十进制开关开启,十进制显示30/2秒
void CClockDlg::OnOK()
{
// TODO: Add extra validation here
key=30;
// CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -