画钟参考程序_第1页
画钟参考程序_第2页
画钟参考程序_第3页
画钟参考程序_第4页
画钟参考程序_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/ aaDlg.cpp : implementation file/#include "stdafx.h"#include "aa.h"#include "aaDlg.h"#include "math.h"#include "time.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifstruct saveUINT DrawType;int rectleft;int r

2、ectright;int recttop;int rectbottom;CPoint Origin;CPoint End;SavedGraph 10;static int width=0;static int height=0;/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual

3、 function overrides/AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAbou

4、tDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CAboutDlg)/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)/AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/ CAaDlg dialogCAaDlg:CAaDlg(CWnd* pParent /*=NULL*/): CDialog(CAaDlg:IDD, pParent)/AF

5、X_DATA_INIT(CAaDlg)/ NOTE: the ClassWizard will add member initialization here/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);void CAaDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP

6、(CAaDlg)/ NOTE: the ClassWizard will add DDX and DDV calls here/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAaDlg, CDialog)/AFX_MSG_MAP(CAaDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)ON_WM_TIMER()ON_BN_CLICKED(IDC_BUTTON3, OnS

7、ettingTime)ON_BN_CLICKED(IDC_BUTTON4, OnAdjustTime)ON_EN_CHANGE(IDC_EDIT3, OnChangeMinute)ON_EN_CHANGE(IDC_EDIT4, OnChangeSecond)ON_BN_CLICKED(IDC_BUTTON2, OnPause_Play)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CAaDlg message handlersBOOL CAaDlg:OnInitDialog()CDialog:OnInitDialog();/ Add "About." men

8、u 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

9、()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 dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small

10、 icon/ TODO: Add extra initialization hereModifyStyle( NULL, WS_THICKFRAME);return TRUE; / return TRUE unless you set the focus to a controlvoid CAaDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam

11、);/ 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 CAaDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM

12、_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint 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 icondc.Draw

13、Icon(x, y, m_hIcon);else/用外框进行试验/计算长宽的变化比例/ CRect Rect;/ float x,y;/ x=Rect.right/width;/ / / / SavedGraph0.rectleft*=1;/ SavedGraph0.recttop*=1;/ SavedGraph0.rectright*=1;/ SavedGraph0.rectbottom*=1;/ / /画方框/ CWnd *pWnd=this;/GetDlgItem(IDC_WORK);/图画区域/ pWnd->GetClientRect(&Rect);/ int nWidt

14、h=Rect.right;/图画区域宽度/ int nHeight=Rect.bottom;/图画区域高度/ / /设置填充色/ CClientDC dc(pWnd);/ CBrush brush;/ brush.CreateSolidBrush(RGB(255,255,255);/填充色/ HBRUSH hNewBrush=(HBRUSH)brush.m_hObject;/ HBRUSH hOldBrush=(HBRUSH)dc.SelectObject(hNewBrush);/ /以下画方框/ /设置方框画笔色 蓝色/ CPen BluePen;/ BluePen.CreatePen( P

15、S_SOLID,5/*线宽*/, RGB(0, 0, 255)/*画笔色*/);/ CPen * pOldPen1=dc.SelectObject(&BluePen);/ /开始画方框/ Rect.left=SavedGraph0.rectleft;/ Rect.top=SavedGraph0.recttop;/ Rect.right=SavedGraph0.rectright;/ Rect.bottom=SavedGraph0.rectbottom;/ dc.Rectangle(Rect);/ /恢复环境/ dc.SelectObject(hOldBrush);/ dc.Select

16、Object(pOldPen1); / /画方框结束CDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CAaDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;static int m_second=-96;static int m_minute=-90;static double m_hour=-90;static double mm_hour=-90;s

17、tatic int i=1;static int num1=0,num2=0,num3=0;static int flag=0;static int flag1=0;static int count=0;void CAaDlg:OnButton1() /第一个按钮 画钟/ TODO: Add your control notification handler code hereif(count%2=0|count=0)CWnd *pWnd=this;/GetDlgItem(IDC_WORK);/图画区域CRect Rect;pWnd->GetClientRect(&Rect);i

18、nt nWidth=Rect.right;/图画区域宽度int nHeight=Rect.bottom;/图画区域高度width=nWidth;height=nHeight;/设置填充色CClientDC dc(pWnd);CBrush brush;brush.CreateSolidBrush(RGB(255,255,255);/填充色HBRUSH hNewBrush=(HBRUSH)brush.m_hObject;HBRUSH hOldBrush=(HBRUSH)dc.SelectObject(hNewBrush);/以下画方框/设置方框画笔色 蓝色CPen BluePen;BluePen.

19、CreatePen( PS_SOLID,5/*线宽*/, RGB(0, 0, 255)/*画笔色*/);CPen * pOldPen1=dc.SelectObject(&BluePen);/开始画方框Rect.left=90;Rect.top=10;Rect.right=290;Rect.bottom=210;dc.Rectangle(Rect);/保存方框到结构体中/*SavedGraph0.DrawType="Rectangle"*/SavedGraph0.rectleft=Rect.left;SavedGraph0.recttop=Rect.top;Saved

20、Graph0.rectright=Rect.right;SavedGraph0.rectbottom=Rect.bottom;/恢复环境dc.SelectObject(hOldBrush);dc.SelectObject(pOldPen1); /设置黑色画笔色CPen *BlackPen1 = new CPen( PS_SOLID,1/*线宽*/, RGB(0, 0, 0)/*画笔色*/);CPen *pOldPen=dc.SelectObject(BlackPen1);/以下画圆HBRUSH hOldBrush1 = (HBRUSH)dc.SelectObject(hNewBrush);Re

21、ct.left=100;Rect.top=20;Rect.right=280;Rect.bottom=200;/圆区域dc.Ellipse(Rect);/画圆dc.SelectObject(hOldBrush1);/恢复环境dc.SelectObject(hOldBrush1);dc.SelectObject(pOldPen); delete BlackPen1;/画中间的圆CBrush brush1;brush1.CreateSolidBrush(RGB(250,0,0);HBRUSH hNewBrush11=(HBRUSH)brush1.m_hObject;HBRUSH hOldBrush

22、11=(HBRUSH)dc.SelectObject(hNewBrush11);/HBRUSH hOldBrush11 = (HBRUSH)dc.SelectObject(hNewBrush11);Rect.left=185;Rect.top=105;Rect.right=195;Rect.bottom=115;/圆区域CPen *RedPen=new CPen(PS_SOLID,1/*线宽*/, RGB(250, 0, 0)/*画笔色*/);CPen *pOldPen4=dc.SelectObject(RedPen);dc.Ellipse(Rect);/画圆/恢复环境dc.SelectObj

23、ect(hOldBrush11);dc.SelectObject(pOldPen4); delete RedPen;/以下开始画刻度线,先画4条在x轴和y轴的/先对4条xy轴的刻度线设置颜色CPen BlackPen2;BlackPen2.CreatePen(PS_SOLID,4,RGB(0,0,0);CPen *pOldPen2=dc.SelectObject(&BlackPen2);/开始画刻度CPoint point1=dc.MoveTo(190,20); /起点1dc.LineTo(190,35);/终点1CPoint point2=dc.MoveTo(190,200); /起

24、点2dc.LineTo(190,185);/终点2CPoint point3=dc.MoveTo(280,110); /起点3dc.LineTo(265,110);/终点3CPoint point4=dc.MoveTo(100,110); /起点4dc.LineTo(115,110);/终点4/恢复环境dc.SelectObject(pOldPen2); /写刻度上的字CFont font;LOGFONT lf;memset(&lf, 0, sizeof(LOGFONT);lf.lfHeight = 15; /字高strcpy(lf.lfFaceName, "Times Ne

25、w Roman"); /字体VERIFY(font.CreateFontIndirect(&lf);HGDIOBJ oldfont=dc.SelectObject(font.m_hObject);dc.SetTextColor(RGB(0,0,0);/设置文字颜色dc.SetBkMode(TRANSPARENT);/文字背景透明dc.TextOut(185,37,"12");dc.TextOut(187,168,"6");dc.TextOut(120,103,"9");dc.TextOut(252,103,"

26、;3");dc.SelectObject(oldfont);/画剩余的刻度,绿色的刻度/设置画笔的颜色CPen GreenPen;GreenPen.CreatePen(PS_SOLID,4,RGB(0,128,0);CPen *pOldPen3=dc.SelectObject(&GreenPen);/开始画剩余的刻度int mm,nn;mm=int(90.0*sqrt(3.0)/2);nn=int(70.0*sqrt(3.0)/2);CPoint point5=dc.MoveTo(190+45,110-mm); /起点5dc.LineTo(190+35,110-nn);/终点

27、5CPoint point6=dc.MoveTo(190+mm,110-45); /起点6dc.LineTo(190+nn,110-35);/终点6CPoint point7=dc.MoveTo(190+mm,110+45); /起点7dc.LineTo(190+nn,110+35);/终点7CPoint point8=dc.MoveTo(190+45,110+mm); /起点8dc.LineTo(190+35,110+nn);/终点8CPoint point9=dc.MoveTo(190-45,110-mm); /起点9dc.LineTo(190-35,110-nn);/终点9CPoint

28、point10=dc.MoveTo(190-mm,110-45); /起点10dc.LineTo(190-nn,110-35);/终点10CPoint point11=dc.MoveTo(190-mm,110+45); /起点11dc.LineTo(190-nn,110+35);/终点11CPoint point12=dc.MoveTo(190-45,110+mm); /起点12dc.LineTo(190-35,110+nn);/终点12/恢复环境dc.SelectObject(pOldPen3); /输出当前时间if(flag=0)PutOutCurrentTime();SetTimer(1

29、,1000,0);/设定1秒钟时间/画秒针int x,y;double pi=3.1415926;m_second+=6;x=int(190+60*cos(m_second*pi/180);y=int(110+60*sin(m_second*pi/180);if(m_second=360) m_second=0;CPen *OrangePen1=new CPen(PS_SOLID,1/*线宽*/, RGB(250, 200, 0)/*画笔色*/);CPen *pOldPen5=dc.SelectObject(OrangePen1);CPoint point13=dc.MoveTo(190,11

30、0); /中心点 dc.LineTo(x,y);/终点/恢复环境dc.SelectObject(pOldPen5); delete OrangePen1;/画分针int x2,y2;if(m_second=270)m_minute+=6;i+;x2=int(190+48*cos(m_minute*pi/180);y2=int(110+48*sin(m_minute*pi/180);if (m_minute=360)m_minute=0;CPen *BlackPen=new CPen(PS_SOLID,3/*线宽*/, RGB(100, 250, 100)/*画笔色*/);CPen *pOldP

31、en6=dc.SelectObject(BlackPen);CPoint point14=dc.MoveTo(190,110); /中心点dc.LineTo(x2,y2);/终点dc.SelectObject(pOldPen6); delete BlackPen;/画时针int x3,y3;if(i%6=0)m_hour+=0.05;x3=int(190+40*cos(m_hour*pi/180);y3=int(110+40*sin(m_hour*pi/180);if(i=61)i=1;mm_hour+=30;if(m_hour=360)m_hour=0;mm_hour=0;CPen *Bla

32、ckPen3=new CPen(PS_SOLID,4/*线宽*/, RGB(0, 0, 200)/*画笔色*/);CPen *pOldPen7=dc.SelectObject(BlackPen3);CPoint point15=dc.MoveTo(190,110); /中心点dc.LineTo(x3,y3);/终点dc.SelectObject(pOldPen7); delete BlackPen3;void CAaDlg:OnChangeEdit2() / TODO: If this is a RICHEDIT control, the control will not/ send this

33、 notification unless you override the CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code here/*flag=1;*/void CAaDlg:OnTimer(UINT nIDEvent) / TODO: Add your message handler code here

34、and/or call defaultif(nIDEvent=1)OnButton1();/ if(nIDEvent=2)/ PutOutCurrentTime();void CAaDlg:OnSettingTime() /设置时间按钮/ TODO: Add your control notification handler code hereflag1=0;char ch15,ch25,ch35;GetDlgItem(IDC_EDIT2)->GetWindowText(ch1,5);GetDlgItem(IDC_EDIT3)->GetWindowText(ch2,5);GetDl

35、gItem(IDC_EDIT4)->GetWindowText(ch3,5);num1=atoi(ch1);num2=atoi(ch2);num3=atoi(ch3);m_second=-90+(num3-1)*6;/设置秒针初始时间位置m_minute=-90+num2*6;/设置分针初始时间位置m_hour=-90+num1*30+num2*30/60;/设置时针初始时间位置mm_hour=-90+num1*30+num2*30/60;if(num1>24|num2>61|num3>61)MessageBox("请输入正确的时间");elseco

36、unt+; void CAaDlg:OnAdjustTime() /当前时间按钮/ TODO: Add your control notification handler code here int hour,minute,second; flag1=1; CTime t=CTime:GetCurrentTime(); hour=t.GetHour(); minute=t.GetMinute(); second=t.GetSecond(); if(second!=0)m_second=-90+(second-1)*6; if(minute!=0)m_minute=-90+minute*6; i

37、f(hour!=0) m_hour=-90+hour*30+minute*30/60; mm_hour=-90+hour*30+minute*30/60; /* count+;*/ OnButton1(); void CAaDlg:PutOutCurrentTime()/把表的时间输出int minute,second;int hour=0;second=(m_second+96)/6;minute=(m_minute+90)/6;if(second<=59)SetDlgItemInt(IDC_EDIT4,second);elseSetDlgItemInt(IDC_EDIT4,secon

38、d-60);if(minute<=59)if(second<=59)SetDlgItemInt(IDC_EDIT3,minute);if(second=60)SetDlgItemInt(IDC_EDIT3,+minute); if(minute=60)SetDlgItemInt(IDC_EDIT3,minute-60);hour=(mm_hour+90)/30;if(flag1=0)/当前时间按钮没有启动,用的是设置时间按钮if(minute<=59)SetDlgItemInt(IDC_EDIT2,hour);elseif(hour!=23)SetDlgItemInt(IDC

39、_EDIT2,+hour);elsehour=0;SetDlgItemInt(IDC_EDIT2,hour);if(flag1=1)/当前时间按钮启动if(minute<=59)SetDlgItemInt(IDC_EDIT2,hour);elseif(hour!=23)SetDlgItemInt(IDC_EDIT2,+hour);elsehour=0;SetDlgItemInt(IDC_EDIT2,hour);/ void CAaDlg:DrawLaughter()/ / / CWnd *pWnd=this;/GetDlgItem(IDC_WORK);/图画区域/ / CRect Rect;/ / pWnd->G

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论