📄 digclock.cpp
字号:
#include "stdafx.h"
#include "DigClock.h"
#include ".\digclock.h"
void DisplayDigit (HDC hdc, int iNumber)
{
static BOOL fSevenSegment [10][7] = {
1, 1, 1, 0, 1, 1, 1, // 0
0, 0, 1, 0, 0, 1, 0, // 1
1, 0, 1, 1, 1, 0, 1, // 2
1, 0, 1, 1, 0, 1, 1, // 3
0, 1, 1, 1, 0, 1, 0, // 4
1, 1, 0, 1, 0, 1, 1, // 5
1, 1, 0, 1, 1, 1, 1, // 6
1, 0, 1, 0, 0, 1, 0, // 7
1, 1, 1, 1, 1, 1, 1, // 8
1, 1, 1, 1, 0, 1, 1 } ; // 9
static POINT ptSegment [7][6] = {
7, 6, 11, 2, 31, 2, 35, 6, 31, 10, 11, 10,
6, 7, 10, 11, 10, 31, 6, 35, 2, 31, 2, 11,
36, 7, 40, 11, 40, 31, 36, 35, 32, 31, 32, 11,
7, 36, 11, 32, 31, 32, 35, 36, 31, 40, 11, 40,
6, 37, 10, 41, 10, 61, 6, 65, 2, 61, 2, 41,
36, 37, 40, 41, 40, 61, 36, 65, 32, 61, 32, 41,
7, 66, 11, 62, 31, 62, 35, 66, 31, 70, 11, 70 } ;
int iSeg ;
for (iSeg = 0 ; iSeg < 7 ; iSeg++)
if (fSevenSegment [iNumber][iSeg])
Polygon (hdc, ptSegment [iSeg], 6) ;
}
void DisplayTwoDigits(HDC hdc, int iNumber, BOOL fSuppress)
{
if (!fSuppress || (iNumber / 10 != 0))
DisplayDigit (hdc, iNumber / 10) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
DisplayDigit (hdc, iNumber % 10) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
}
void DisplayThreeDigits(HDC hdc, int iNumber, BOOL fSuppress)
{
if (!fSuppress || (iNumber / 10 != 0))
DisplayDigit (hdc, iNumber / 100) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
DisplayDigit (hdc, (iNumber % 100) / 10) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
DisplayDigit (hdc, (iNumber % 10)) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
}
void DisplayColon (HDC hdc)
{
POINT ptColon [2][4] = { 2, 21, 6, 17, 10, 21, 6, 25,
2, 51, 6, 47, 10, 51, 6, 55 } ;
Polygon (hdc, ptColon [0], 4) ;
Polygon (hdc, ptColon [1], 4) ;
OffsetWindowOrgEx (hdc, -12, 0, NULL) ;
}
void DisplayDot (HDC hdc)
{
POINT ptColon [1][4] = { 2, 61, 6, 57, 10, 61, 6, 65 } ;
Polygon (hdc, ptColon [0], 4) ;
OffsetWindowOrgEx (hdc, -12, 0, NULL) ;
}
void DisplayTime (HDC hdc, int hour, int min, int sec, int millsec)
{
//DisplayTwoDigits (hdc, hour, FALSE) ;
//DisplayColon (hdc) ;
DisplayTwoDigits (hdc, min, FALSE) ;
DisplayColon (hdc) ;
DisplayTwoDigits (hdc, sec, FALSE) ;
DisplayDot (hdc) ;
DisplayThreeDigits (hdc, millsec, FALSE) ;
}
LRESULT CDigClock::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (m_hWnd) {
CPaintDC dc(m_hWnd);
CBrush brushRed;
brushRed.CreateSolidBrush(RGB(0, 0, 0));
dc.SelectBrush(brushRed);
dc.SelectStockPen(NULL_PEN);
RECT rect;
GetClientRect(&rect);
dc.FillRect(&rect, (HBRUSH) (COLOR_WINDOW+1));
dc.SetMapMode(MM_ISOTROPIC);
dc.SetWindowExt(276, 72, NULL);
dc.SetViewportExt(rect.right, rect.bottom, NULL) ;
dc.SetWindowOrg(138, 36, NULL) ;
dc.SetViewportOrg(rect.right / 2, rect.bottom / 2, NULL) ;
DisplayTime (dc, m_nHour, m_nMin, m_nSec, m_nMillSec) ;
dc.SelectStockBrush(WHITE_BRUSH);
}
return 0;
}
void CDigClock::SetTime(int hour, int min, int sec, int millsec)
{
m_nHour=hour; m_nMin=min; m_nSec=sec; m_nMillSec = millsec;
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -