// B04View.cpp : implementation of the CB04View class
//
#include "stdafx.h"
#include "B04.h"
#include "math.h"
#include "B04Doc.h"
#include "B04View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CB04View
IMPLEMENT_DYNCREATE(CB04View, CView)
BEGIN_MESSAGE_MAP(CB04View, CView)
//{{AFX_MSG_MAP(CB04View)
ON_WM_CREATE()
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CB04View construction/destruction
CB04View::CB04View()
{
// TODO: add construction code here
}
CB04View::~CB04View()
{
}
BOOL CB04View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View drawing
void CB04View::OnDraw(CDC* pDC)
{
CB04Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//获取客户区
RECT Rect;
GetClientRect(&Rect);
//计算椭圆中心位置
int CenterX = Rect.right/2;
int CenterY = Rect.bottom/2;
//取当前时间
CTime Time = CTime::GetCurrentTime();
CString str;
int i,x,y;
CSize size;
//创建一支黄色的笔,用来画椭圆
CPen Pen(PS_SOLID,5,RGB(255,255,0));
//设置当前画笔,并记下以前的画笔
CPen *OldPen = pDC->SelectObject(&Pen);
//绘制钟面椭圆
pDC->Ellipse(5,5,Rect.right-5,Rect.bottom-5);
double Radians;
//设置字体颜色为红色
pDC->SetTextColor(RGB(255,0,0));
for(i = 1;i <= 12;i++){
//格式化钟点值
str.Format("%d",i);
size = pDC->GetTextExtent(str,str.GetLength());
Radians = (double)i*6.28/12.0;
//计算钟点放置的位置
x = CenterX - (size.cx/2) + (int)((double)(CenterX - 20)*
sin(Radians));
y = CenterY - (size.cy/2) - (int)((double)(CenterY - 20)*
cos(Radians));
//绘制钟点
pDC->TextOut(x,y,str);
}
//计算时钟指针的夹角
Radians = (double)Time.GetHour() + (double)Time.GetMinute()/60.0 +
(double)Time.GetSecond()/3600.0;
Radians *= 6.28/12.0;
//创建时钟指针画笔
CPen HourPen(PS_SOLID,5,RGB(0,255,0));
pDC->SelectObject(&HourPen);
//绘制时钟指针
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX + (int)((double)(CenterX/3)*sin(Radians)),
CenterY - (int)((double)(CenterY/3)*cos(Radians)));
Radians = (double)Time.GetMinute()+(double)Time.GetSecond()/60.0;
Radians *= 6.28/60.0;
//创建分钟指针画笔
CPen MinutePen(PS_SOLID,3,RGB(0,0,255));
pDC->SelectObject(&MinutePen);
//绘制分钟指针
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX + (int)((double)(CenterX*2)/3)*sin(Radians),
CenterY - (int)((double)(CenterY*2/3)*cos(Radians)));
Radians = (double)Time.GetSecond();
Radians *= 6.28/60.0;
//创建秒钟指针画笔
CPen SecondPen(PS_SOLID,1,RGB(0,255,255));
pDC->SelectObject(&SecondPen);
//绘制秒钟指针
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX + (int)((double)(CenterX*4)/5)*sin(Radians),
CenterY - (int)((double)(CenterY*4)/5*cos(Radians)));
pDC->SelectObject(OldPen);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View printing
BOOL CB04View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CB04View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CB04View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CB04View diagnostics
#ifdef _DEBUG
void CB04View::AssertValid() const
{
CView::AssertValid();
}
void CB04View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CB04Doc* CB04View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CB04Doc)));
return (CB04Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CB04View message handlers
int CB04View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL);
return 0;
}
void CB04View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateRect(NULL,true);
UpdateWindow();
CView::OnTimer(nIDEvent);
}
指针式时钟
5星 · 超过95%的资源 需积分: 10 179 浏览量
2008-04-12
18:33:16
上传
评论
收藏 1.52MB RAR 举报
Insky333
- 粉丝: 1
- 资源: 13
最新资源
- 基于Java的实验室仪器设备管理系统后端设计源码 - houduan
- Screenshot_2024-05-29-01-03-40-499_com.tencent.mm.jpg
- 素材(美女、自拍)-.zip
- 基于Vue和Javascript的自动化接口文档生成工具设计源码 - 自动化接口生成文档
- com.miHoYo.ys.bilibili.apk
- 基于51单片机+共阴极数码管设计00-99计数器Proteus仿真+软件程序C源代码.zip
- 基于STM32的单片机动态加载函数库设计源码 - dynamic_loader
- 基于51单片机设计可预置可逆4位计数器Proteus仿真+软件程序C源代码.zip
- xiaomi10青春版完好机备份基带qcn.qcn
- 基于51单片机的汉字点阵显示Proteus仿真+软件程序C源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈