📄 clockview.cpp
字号:
// clockView.cpp : implementation of the CClockView class
//
#include "stdafx.h"
#include "clock.h"
#include "clockDoc.h"
#include "clockView.h"
#include "math.h"
#include "time_set.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI 3.1415926535897932384626433832795
/////////////////////////////////////////////////////////////////////////////
// CClockView
IMPLEMENT_DYNCREATE(CClockView, CView)
BEGIN_MESSAGE_MAP(CClockView, CView)
//{{AFX_MSG_MAP(CClockView)
ON_WM_TIMER()
ON_COMMAND(ID_start, Onstart)
ON_COMMAND(ID_pause, Onpause)
ON_COMMAND(ID_restart, Onrestart)
ON_COMMAND(aa, Onaa)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClockView construction/destruction
CClockView::CClockView()
{ p1=(200,200);
r=100;
r0=10;
theta0 = 0;
theta1=0;
theta2=0;
dt=1;
x0=200;
y0=-100;
x1=200;
y1=-100;
x2=200;
y2=-100;
n=60;
n0=12;
w0=2*PI/n;
w1=2*PI/(n*n);
w2=2*PI/(n*n*n0);
y=0;
m=0;
d=0;
h0=0;
m0=0;
d0=0;
f=false;
// TODO: add construction code here
}
CClockView::~CClockView()
{
}
BOOL CClockView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CClockView drawing
void CClockView::OnDraw(CDC* pDC)
{
CClockDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->SetViewportOrg(300, 300);
CPen pen(PS_SOLID, 1, RGB(255,0,0)),*p;
p=pDC->SelectObject(&pen);
pDC->Ellipse(p1.x-r-5, p1.y-r-5, p1.x+r+5, p1.y+r+5);
pDC->Ellipse(p1.x-r, p1.y-r, p1.x+r, p1.y+r);
pDC->SelectObject(p);
CBrush brush1(RGB(0,0,255)),*pOldbrush1;
pOldbrush1=pDC->SelectObject(&brush1);
pDC->Ellipse(p1.x-r-2, p1.y-r-2, p1.x+r+2, p1.y+r+2);
pDC->SelectObject(pOldbrush1);
CBrush brush2(RGB(0,0,0)),*pOldbrush;
pOldbrush=pDC->SelectObject(&brush2);
pDC->Ellipse(p1.x-r0, p1.y-r0, p1.x+r0, p1.y+r0);
pDC->SelectObject(pOldbrush);
pDC->TextOut(190,-95, "12");
pDC->TextOut(250,-85, "1");
pDC->TextOut(280,-50, "2");
pDC->TextOut(290,-10, "3");
pDC->TextOut(280,45, "4");
pDC->TextOut(250,75, "5");
pDC->TextOut(195,90, "6");
pDC->TextOut(150,75, "7");
pDC->TextOut(115,45, "8");
pDC->TextOut(105,-10, "9");
pDC->TextOut(120,-60, "10");
pDC->TextOut(150,-85, "11");
pDC->MoveTo(p1);
pDC->LineTo(x0,y0);
pDC->MoveTo(p1);
pDC->LineTo((3*x1+200)/4,3*y1/4);
pDC->MoveTo(p1);
pDC->LineTo((x2+200)/2,y2/2);
CString str;
pDC->TextOut(0,-200, str);
str.Format("现在的时间是:%d时%d分%d秒",y,m,d);
pDC->TextOut(-200,-100,str);
// TODO: add draw code for native data her
}
/////////////////////////////////////////////////////////////////////////////
// CClockView printing
BOOL CClockView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CClockView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CClockView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CClockView diagnostics
#ifdef _DEBUG
void CClockView::AssertValid() const
{
CView::AssertValid();
}
void CClockView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CClockDoc* CClockView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClockDoc)));
return (CClockDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CClockView message handlers
void CClockView::Onaa()
{
// TODO: Add your command handler code here
time_set t;
t.m_second=d0;
t.m_minit=m0;
t.m_hour=h0;
t.DoModal();
d=t.m_second;
m=t.m_minit;
y=t.m_hour;
d0=t.m_second;
m0=t.m_minit;
h0=t.m_hour;
theta0=t.m_second*2*PI/n;
theta1=(t.m_minit+t.m_second/n)*2*PI/n;
theta2=(t.m_hour+t.m_minit/n+t.m_second/n*n)*2*PI/n0;
Invalidate();
}
void CClockView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
calcute();
Invalidate();
CView::OnTimer(nIDEvent);
}
void CClockView::Onstart()
{ SetTimer(1, 1000, NULL);
// TODO: Add your command handler code here
}
void CClockView::Onpause()
{ KillTimer(1);
// TODO: Add your command handler code here
}
void CClockView::calcute()
{
theta0+=w0*dt;
theta1+=w1*dt;
theta2+=w2*dt;
d++;
if(d>60)
{ m++;
d-=60;
}
if(m>=60)
{y++;
m-=60;
}
x0=200+r*sin(theta0);
y0=-r*cos(theta0);
x1=200+r*sin(theta1);
y1=-r*cos(theta1);
x2=200+r*sin(theta2);
y2=-r*cos(theta2);
}
void CClockView::Onrestart()
{
// TODO: Add your command handler code here
theta0=0;
theta1=0;
theta2=0;
dt=1;
x0=200;
y0=-100;
x1=200;
y1=-100;
x2=200;
y2=-100;
n=60;
w0=2*PI/n;
w1=2*PI/(n*n);
w2=2*PI/(n*n*n0);
y=0;
m=0;
d=0;
KillTimer(1);
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -