VC6++《可视化编程》钟表程序实验报告

时间:2024.4.30

程序设计课程设计 [年级] [班] [学号][姓名]

《可视化编程》课 程 设 计

题目: 1. 编写钟表程序

1

程序设计课程设计 [年级] [班] [学号][姓名]

题目1:编写钟表

[问题描述]

用vc++6.0编写钟表。

[基本要求]

1. 功能要求:编写一个钟表程序能显示出钟表的各种基本功能。

. [实验代码]

// Clock111Dlg.cpp : implementation file

//

#include "stdafx.h"

#include "Clock111.h"

#include "Clock111Dlg.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

2

程序设计课程设计 [年级] [班] [学号][姓名] // CAboutDlg dialog used for App About

class CAboutDlg : public CDialog

{

public:

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

// Implementation

protected:

//{{AFX_MSG(CAboutDlg)

3 //

程序设计课程设计 [年级] [班] [学号][姓名]

};

//}}AFX_MSG DECLARE_MESSAGE_MAP()

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg) // No message handlers CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT //}}AFX_MSG_MAP

END_MESSAGE_MAP()

4

程序设计课程设计 [年级] [班] [学号][姓名]

/////////////////////////////////////////////////////////////////////////////

// CClock111Dlg dialog

CClock111Dlg::CClock111Dlg(CWnd* pParent /*=NULL*/)

{

//{{AFX_DATA_INIT(CClock111Dlg) m_day = _T(""); m_month = _T(""); m_year = _T(""); // NOTE: the ClassWizard will add member initialization here : CDialog(CClock111Dlg::IDD, pParent) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon

in Win32

}

void CClock111Dlg::DoDataExchange(CDataExchange* pDX)

{

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CClock111Dlg) 5

程序设计课程设计 [年级] [班] [学号][姓名]

}

DDX_Text(pDX, IDC_DAY, m_day); DDX_Text(pDX, IDC_MONTH, m_month); DDX_Text(pDX, IDC_YEAR, m_year); // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CClock111Dlg, CDialog)

//{{AFX_MSG_MAP(CClock111Dlg) 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_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CClock111Dlg message handlers

6

程序设计课程设计 [年级] [班] [学号][姓名] BOOL CClock111Dlg::OnInitDialog()

{

// IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == // Add "About..." menu item to system menu. CDialog::OnInitDialog();

IDM_ABOUTBOX);

CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, ASSERT(IDM_ABOUTBOX < 0xF000);

IDM_ABOUTBOX, strAboutMenu);

} 7

程序设计课程设计 [年级] [班] [学号][姓名]

} // Set the icon for this dialog. The framework does this

automatically

// when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE); // TODO: Add extra initialization here //********************** //********************** SetTimer(1,900,NULL);//这个函数设置一个系统定时器。指定 // Set big icon // Set small icon

了一个定时值,每当发生超时,则系统就向设置定时器的应用程

序的消息队列发送一个WM_TIMER消息,或者将消息传递给应

用程序定义的TimerProc回调函数。

return TRUE; // return TRUE unless you set the focus to a

control

}

void CClock111Dlg::OnSysCommand(UINT nID, LPARAM

lParam)

8

程序设计课程设计 [年级] [班] [学号][姓名] {

}

// 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 CClock111Dlg::OnPaint()

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX) { } else { } CDialog::OnSysCommand(nID, lParam); CAboutDlg dlgAbout; dlgAbout.DoModal(); if (IsIconic()) { 9

程序设计课程设计 [年级] [班] [学号][姓名]

CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM)

dc.GetSafeHdc(), 0);

}

10 // Center icon in client rectangle int 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 icon dc.DrawIcon(x, y, m_hIcon); else { } CDialog::OnPaint();

程序设计课程设计 [年级] [班] [学号][姓名] // The system calls this to obtain the cursor to display while the user

drags

// the minimized window.

HCURSOR CClock111Dlg::OnQueryDragIcon()

{

return (HCURSOR) m_hIcon;

}

void CClock111Dlg::OnChangeYear()

{

// TODO: If this is a RICHEDIT control, the control will not

// send this notification unless you override

CDialog::OnInitDialog()

// function and call CRichEditCtrl().SetEventask.

// with the ENM_CHANGE flag ORed into the m

// TODO: Add your control notification handler code here

SYSTEMTIME sys;

GetLocalTime( &sys );

m_year.Format("%d 年", sys.wYear);

UpdateData(false);

}

11 the

程序设计课程设计 [年级] [班] [学号][姓名]

void CClock111Dlg::OnChangeMonth()

{

// TODO: If this is a RICHEDIT control, the control will not

// send this notification unless you override

CDialog::OnInitDialog()

// function and call CRichEditCtrl().SetEventMask()

// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here

SYSTEMTIME sys;

GetLocalTime( &sys );

m_month.Format("%d 月", sys.wMonth);

UpdateData(false);

}

void CClock111Dlg::OnChangeDay()

{

// TODO: If this is a RICHEDIT control, the control will not

// send this notification unless you override

CDialog::OnInitDialog()

// function and call CRichEditCtrl().SetEventMask()

12 the the

程序设计课程设计 [年级] [班] [学号][姓名]

} // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here SYSTEMTIME sys; GetLocalTime( &sys ); m_day.Format("%d 日", sys.wDay); UpdateData(false);

#include <windows.h>

#include <math.h>

void CClock111Dlg::OnTimer(UINT nIDEvent)

{

// TODO: Add your message handler code here and/or call

default

RedrawWindow();

CTime time; time = CTime::GetCurrentTime(); CDC * pDC = GetDC();

13

程序设计课程设计 [年级] [班] [学号][姓名]

CPen * oldpen, pen1,pen2,pen3,pen4,pen5,pen6; CPen 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 = 170; //改变指针圆心位置 14

程序设计课程设计 [年级] [班] [学号][姓名] int oy = 178; //改变指针圆心位置

int m;

OnChangeYear(); //--------------year

OnChangeMonth(); //--------------month OnChangeDay(); //--------------day //second oldpen = 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); 15

程序设计课程设计 [年级] [班] [学号][姓名]

pDC->MoveTo(x,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(x,y);//指针的箭头设定 pDC->LineTo((int)x1,(int)y1);//指针的箭头设定

//minute oldpen = pDC->SelectObject(&pen4); // about tail r = 35; x = sin(Rad+pi) * r + ox; y = -cos(Rad+pi) * r + oy; pDC->MoveTo(ox,oy); // pDC->LineTo((int)x,(int)y);

oldpen = pDC->SelectObject(&pen2);

r = 71; m = time.GetMinute(); Rad = pi * m / 30.0; x = sin(Rad) * r + ox; y = -cos(Rad) * r + oy; 16

程序设计课程设计 [年级] [班] [学号][姓名]

pDC->MoveTo(ox, oy); pDC->LineTo((int)x,(int)y); r11 = 8; x1 = x - sin( (Rad + 2.0/5.0) ) * r11 ; y1 = y + cos( (Rad + 2.0/5.0) ) * r11 ; oldpen = pDC->SelectObject(&pen22); pDC->MoveTo(x,y); pDC->LineTo((int)x1,(int)y1); x1 = x - sin( (Rad - 2.0/5.0) ) * r11 ; y1 = y + cos( (Rad - 2.0/5.0) ) * r11 ; pDC->MoveTo(x,y); pDC->LineTo((int)x1,(int)y1); oldpen = pDC->SelectObject(&pen5);/////////////// about tail r = 20; x = sin(Rad+pi) * r + ox; y = -cos(Rad+pi) * r + oy; pDC->MoveTo(ox, oy); pDC->LineTo((int)x,(int)y); 17

程序设计课程设计 [年级] [班] [学号][姓名]

//hour oldpen = pDC->SelectObject(&pen3); r = 60; m = time.GetHour(); Rad = pi * m / 6.0; x = sin(Rad) * r + ox; y = -cos(Rad) * r + oy; pDC->MoveTo(ox, oy); pDC->LineTo((int)x,(int)y); r11 = 12; x1 = x - sin( (Rad + 3.0/7.0) ) * r11 ; y1 = y + cos( (Rad + 3.0/7.0) ) * r11 ; oldpen = pDC->SelectObject(&pen33); pDC->MoveTo(x,y); pDC->LineTo((int)x1,(int)y1); x1 = x - sin( (Rad - 3.0/7.0) ) * r11 ; y1 = y + cos( (Rad - 3.0/7.0) ) * r11 ; pDC->MoveTo(x,y); pDC->LineTo((int)x1,(int)y1); oldpen = pDC->SelectObject(&pen6);/////////////// about tail 18

程序设计课程设计 [年级] [班] [学号][姓名]

} r = 12; x = sin(Rad+pi) * r + ox; y = -cos(Rad+pi) * r + oy; pDC->MoveTo(ox, oy); pDC->LineTo((int)x,(int)y); CDialog::OnTimer(nIDEvent);

实验结果:

VC6可视化编程钟表程序实验报告

[课程设计小结]

完成实验的心得与体会:通过本次的实验更加了解了完成一个完

整的程序需要哪些方面的知识,学会了编写一个钟表所用到的知识~~

虽然中间也遇到了很多困难,但通过询问与虚心的学习还是学到了不

少知识!最终也完成了实验。受益匪浅!

19

更多相关推荐:
C++程序设计实验报告

C++程序设计实验报告学号:姓名:班级:指导老师:实验一、字符和格式的输出实验一,实验目的1、重点把握各种内部数据类型、数值和逻辑运算,各种表达式、函数声明、定义和调用。2、掌握过程控制编程方法,正确编制多重循…

程序设计实验报告模板

C语言程序设计实验报告1实验目的(1)掌握函数的定义方法、调用方法、参数说明以及返回值;(2)掌握实参与形参的对应关系,以及参数之间的值传递的方式;(3)掌握函数的嵌套调用及递归调用的设计方法;(4)在编程过程…

算法与编程实验报告

算法与编程实验报告班级10083412姓名储飞学号10081235指导老师朱芳第一题一题目一题目统计字母的使用频率二目的与要求1目的通过编写程序统计字母的使用频率培养学生综合利用C语言进行程序设计的能力熟悉字符...

C语言程序设计实验报告8

C语言程序设计实验报告八专业计算机科学与技术班级卓越工程师班日期20xx年12月16日实验组别第一组成绩第八次实验指针实验指导教师李开学生姓名邱金源学号U20xx14493实验名称指针实验一实验目的12345熟...

Windows编程实验报告

Windows编程实验报告1GDI图形程序设计姓名专业学号框架窗口程序和20xx3241Windows编程实验报告1Windows编程实验一GDI图形程序设计框架窗口程序和一实验目的1熟悉在VisualC60I...

算法与编程实验报告

算法与编程实验实验报告第一题一、题目:统计字母的使用频率二、目的与要求1.目的:通过编写程序统计字母的使用频率,培养学生综合利用C语言进行程序设计的能力,熟悉字符串的操作方法,加强函数的运用,提高软件系统分析能…

网络编程实验报告

网络编程实验报告指导老师姓名学号班级实验题目网络文件传输实验目的了解网络文件传输的方法了解FTP协议基础学习使用WinSock实现网络文件的传输了解点对点P2P网络文件传输的方法学习使用WinSock实现P2P...

网络编程实验报告

实验一TCPSocketAPI程序设计一预备知识1网络编程基本概念网络上的计算机间的通讯实质上是网络中不同主机上的程序之间的通讯在互联网中使用IP地址来标识不同的主机在网络协议中使用端口号来标识主机上不同进程即...

网络编程实验报告

程序实践报告一程序实践概述1题目名称Linux程序设计基础2时间进度20xx年6月19日到20xx年7月5日3开发环境Ubunto1004二问题分析1功能说明编程实现快速排序算法实现文本文件拷贝函数copyfs...

socket编程实验报告

姓名学院实验时间计算机网络实验题目Socket编程实验1基于UDP的Socket编程实验2基于TCP的Socket编程学号年级目录一实验内容3实验1基于UDP的Socket编程3实验2基于TCP的Socket编...

WinSocket编程实验报告

实验六WinSock编程实验报告1实验目的和要求1学习网络中进程之间通信的原理和实现方法2掌握在VB或VC等集成开发环境中编写网络程序的方法3编写一个简单的聊天程序最低要求实现两人一组的两台计算机之间的收发文本...

程序设计 实验报告3

《C语言程序设计》实验报告实验名称:结构体程序设计系别:计算机系专业:计算机科学与技术班级:姓名:学号:实验日期:20##年12月23日教师审批签字:实验11结构体程序设计⒈实验目的⑴掌握结构体类型变量的定义和…

编程实验报告(38篇)