可视化编程时钟编写的实验报告.doc_第1页
可视化编程时钟编写的实验报告.doc_第2页
可视化编程时钟编写的实验报告.doc_第3页
可视化编程时钟编写的实验报告.doc_第4页
可视化编程时钟编写的实验报告.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

可视化编程课 程 设 计姓 名_熊健_ 班 次_11_计算机科学与技术 _ 学 号_20111104593_指导教师_朝力萌_成 绩_计算机与信息工程学院2013 年 5 月 27 题目2:编写钟表1.问题描述:编写钟表2.基本要求 :通过编写程序钟表,使程序能够完美的展示出钟表,并且能正确显示时间和日期。3.算法分析:通过设置时间函数来确定时钟的正确运行,再利用UpdateData(false)和UpdateData(true)来编写年月日时分秒以及星期函数,以至于正确的展示出时钟所能拥有的一切功能。 4.源程序:/ ColockDlg.h : header file/#if !defined(AFX_COLOCKDLG_H_AB11AAFB_7269_4E1D_B7CD_BB986486830E_INCLUDED_)#define AFX_COLOCKDLG_H_AB11AAFB_7269_4E1D_B7CD_BB986486830E_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000/ CColockDlg dialogclass CColockDlg : public CDialog/ Constructionpublic:CColockDlg(CWnd* pParent = NULL);/ standard constructor/ Dialog Data/AFX_DATA(CColockDlg)enum IDD = IDD_COLOCK_DIALOG ;CStringm_Day;CStringm_Month;CStringm_Year;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CColockDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:HICON m_hIcon;/ Generated message map functions/AFX_MSG(CColockDlg)virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();afx_msg void OnChangeYear();afx_msg void OnChangeMonth();afx_msg void OnChangeDay();afx_msg void OnTimer(UINT nIDEvent);/AFX_MSGDECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_COLOCKDLG_H_AB11AAFB_7269_4E1D_B7CD_BB986486830E_INCLUDED_)/ ColockDlg.cpp : implementation file/#include stdafx.h#include Colock.h#include ColockDlg.h#include windows.h#include math.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual 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 CAboutDlg: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()/ CColockDlg dialogCColockDlg:CColockDlg(CWnd* pParent /*=NULL*/): CDialog(CColockDlg:IDD, pParent)/AFX_DATA_INIT(CColockDlg)m_Day = _T();m_Month = _T();m_Year = _T();/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CColockDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CColockDlg)DDX_Text(pDX, IDC_DAY, m_Day);DDX_Text(pDX, IDC_MONTH, m_Month);DDX_Text(pDX, IDC_YEAR, m_Year);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CColockDlg, CDialog)/AFX_MSG_MAP(CColockDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_EN_CHANGE(IDC_YEAR, OnChangeYear)ON_EN_CHANGE(IDC_MONTH, OnChangeMonth)ON_EN_CHANGE(IDC_DAY, OnChangeDay)ON_WM_TIMER()/AFX_MSG_MAPEND_MESSAGE_MAP()/ CColockDlg message handlersBOOL CColockDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra initialization hereSetTimer(1,1000,NULL);/这个函数设置一个系统定时器。return TRUE; / return TRUE unless you set the focus to a controlvoid CColockDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ 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 CColockDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_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.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CColockDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CColockDlg:OnChangeYear() / TODO: If this is a RICHEDIT control, the control will not/ send this 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 hereSYSTEMTIME sys;GetLocalTime(&sys); m_Year.Format( %d 年,sys.wYear);UpdateData(false);void CColockDlg:OnChangeMonth() / TODO: If this is a RICHEDIT control, the control will not/ send this 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 hereSYSTEMTIME sys;GetLocalTime(&sys); m_Month.Format( %d 月,sys.wMonth);UpdateData(false);void CColockDlg:OnChangeDay() / TODO: If this is a RICHEDIT control, the control will not/ send this 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 hereSYSTEMTIME sys;GetLocalTime( &sys ); m_Day.Format( %d 日, sys.wDay);UpdateData(false);void CColockDlg:OnTimer(UINT nIDEvent) / TODO: Add your message handler code here and/or call default RedrawWindow();CTime time;time=CTime:GetCurrentTime();CDC *pDC=GetDC(); CPen *oldpen,pen1,pen2,pen3,pen4,pen5,pen6,pen11,pen22,pen33;pen1.CreatePen(PS_SOLID,2,RGB(200,0,0);pen4.CreatePen(PS_SOLID,2,RGB(200,0,0);pen11.CreatePen(PS_SOLID,2,RGB(200,0,0);pen2.CreatePen(PS_SOLID,4,RGB(100,100,200);pen22.CreatePen(PS_SOLID,2,RGB(100,100,200);pen5.CreatePen(PS_SOLID,5,RGB(100,100,200);pen3.CreatePen(PS_SOLID,6,RGB(0,0,0);pen33.CreatePen(PS_SOLID,3,RGB(0,0,0);pen6.CreatePen(PS_SOLID,8,RGB(0,0,0); double pi=3.141592653;double Rad;double r;double x;double y;int ox=210; /改变指针圆心位置 int oy=230; /改变指针圆心位置 int m; OnChangeYear(); /-yearOnChangeMonth(); /-monthOnChangeDay(); /-day/secondoldpen=pDC-SelectObject(&pen1);r=83;m=time.GetSecond();Rad=pi*m/30.0;x=sin(Rad)*r+ox;y=-cos(Rad)*r+oy; pDC-MoveTo(ox,oy);pDC-LineTo(int)x,(int)y);int r11=11;int x1=(int)(x-sin(Rad+1.0/5.0)*r11);int y1=(int)(y+cos(Rad+1.0/5.0)*r11);oldpen=pDC-SelectObject(&pen1);pDC-MoveTo(int)x,(int)y); /指针的箭头设定pDC-LineTo(int)x1,(int)y1); /指针的箭头设定x1=(int)(x-sin(Rad-1.0/5.0)*r11);y1=(int)(y+cos(Rad-1.0/5.0)*r11);pDC-MoveTo(int)x,(int)y);/指针的箭头设定pDC-LineTo(int)x1,(int)y1);/指针的箭头设定 oldpen=pDC-SelectObject(&pen4); r=35;x=sin(Rad+pi)*r+ox;y=-cos(Rad+pi)*r+oy;pDC-MoveTo(ox,oy); pDC-LineTo(int)x,(int)y);/minute oldpen =pDC-SelectObject(&pen2);r=71;m=time.GetMinute();Rad=pi*m/30.0;x=sin(Rad)*r+ox;y=-cos(Rad)*r+oy; pDC-MoveTo(ox,oy);pDC-LineTo(int)x,(int)y);r11=8;x1=(int)(x-sin(Rad+2.0/5.0)*r11);y1=(int)(y+cos(Rad+2.0/5.0)*r11);oldpen=pDC-SelectObject(&pen22);pDC-MoveTo(int)x,

温馨提示

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

评论

0/150

提交评论