画钟参考程序.docx
- 文档编号:27631984
- 上传时间:2023-07-03
- 格式:DOCX
- 页数:23
- 大小:42.79KB
画钟参考程序.docx
《画钟参考程序.docx》由会员分享,可在线阅读,更多相关《画钟参考程序.docx(23页珍藏版)》请在冰豆网上搜索。
画钟参考程序
//aaDlg.cpp:
implementationfile
//
#include"stdafx.h"
#include"aa.h"
#include"aaDlg.h"
#include"math.h"
#include"time.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
structsave
{
UINTDrawType;
intrectleft;
intrectright;
intrecttop;
intrectbottom;
CPointOrigin;
CPointEnd;
}SavedGraph[10];
staticintwidth=0;
staticintheight=0;
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialog(CAboutDlg:
:
IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
voidCAboutDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CAaDlgdialog
CAaDlg:
:
CAaDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CAaDlg:
:
IDD,pParent)
{
//{{AFX_DATA_INIT(CAaDlg)
//NOTE:
theClassWizardwilladdmemberinitializationhere
//}}AFX_DATA_INIT
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
voidCAaDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAaDlg)
//NOTE:
theClassWizardwilladdDDXandDDVcallshere
//}}AFX_DATA_MAP
}
BEGIN_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,OnSettingTime)
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_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CAaDlgmessagehandlers
BOOLCAaDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
//Add"About..."menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);//Setbigicon
SetIcon(m_hIcon,FALSE);//Setsmallicon
//TODO:
Addextrainitializationhere
ModifyStyle(NULL,WS_THICKFRAME);
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
}
voidCAaDlg:
:
OnSysCommand(UINTnID,LPARAMlParam)
{
if((nID&0xFFF0)==IDM_ABOUTBOX)
{
CAboutDlgdlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog:
:
OnSysCommand(nID,lParam);
}
}
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
voidCAaDlg:
:
OnPaint()
{
if(IsIconic())
{
CPaintDCdc(this);//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon);
}
else
{
//用外框进行试验
//计算长宽的变化比例
//CRectRect;
//floatx,y;
//x=Rect.right/width;
//
//
//
//SavedGraph[0].rectleft*=1;
//SavedGraph[0].recttop*=1;
//SavedGraph[0].rectright*=1;
//SavedGraph[0].rectbottom*=1;
//
////画方框
//CWnd*pWnd=this;//GetDlgItem(IDC_WORK);//图画区域
//pWnd->GetClientRect(&Rect);
//intnWidth=Rect.right;//图画区域宽度
//intnHeight=Rect.bottom;//图画区域高度
//
////设置填充色
//CClientDCdc(pWnd);
//CBrushbrush;
//brush.CreateSolidBrush(RGB(255,255,255));//填充色
//HBRUSHhNewBrush=(HBRUSH)brush.m_hObject;
//HBRUSHhOldBrush=(HBRUSH)dc.SelectObject(hNewBrush);
////以下画方框
////设置方框画笔色蓝色
//CPenBluePen;
//BluePen.CreatePen(PS_SOLID,5/*线宽*/,RGB(0,0,255)/*画笔色*/);
//CPen*pOldPen1=dc.SelectObject(&BluePen);
////开始画方框
//Rect.left=SavedGraph[0].rectleft;
//Rect.top=SavedGraph[0].recttop;
//Rect.right=SavedGraph[0].rectright;
//Rect.bottom=SavedGraph[0].rectbottom;
//dc.Rectangle(Rect);
////恢复环境
//dc.SelectObject(hOldBrush);
//dc.SelectObject(pOldPen1);
////画方框结束
CDialog:
:
OnPaint();
}
}
//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags
//theminimizedwindow.
HCURSORCAaDlg:
:
OnQueryDragIcon()
{
return(HCURSOR)m_hIcon;
}
staticintm_second=-96;
staticintm_minute=-90;
staticdoublem_hour=-90;
staticdoublemm_hour=-90;
staticinti=1;
staticintnum1=0,num2=0,num3=0;
staticintflag=0;
staticintflag1=0;
staticintcount=0;
voidCAaDlg:
:
OnButton1()//第一个按钮画钟
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(count%2==0||count==0)
{
CWnd*pWnd=this;//GetDlgItem(IDC_WORK);//图画区域
CRectRect;
pWnd->GetClientRect(&Rect);
intnWidth=Rect.right;//图画区域宽度
intnHeight=Rect.bottom;//图画区域高度
width=nWidth;
height=nHeight;
//设置填充色
CClientDCdc(pWnd);
CBrushbrush;
brush.CreateSolidBrush(RGB(255,255,255));//填充色
HBRUSHhNewBrush=(HBRUSH)brush.m_hObject;
HBRUSHhOldBrush=(HBRUSH)dc.SelectObject(hNewBrush);
//以下画方框
//设置方框画笔色蓝色
CPenBluePen;
BluePen.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);
//保存方框到结构体中
/*SavedGraph[0].DrawType="Rectangle";*/
SavedGraph[0].rectleft=Rect.left;
SavedGraph[0].recttop=Rect.top;
SavedGraph[0].rectright=Rect.right;
SavedGraph[0].rectbottom=Rect.bottom;
//恢复环境
dc.SelectObject(hOldBrush);
dc.SelectObject(pOldPen1);
//设置黑色画笔色
CPen*BlackPen1=newCPen(PS_SOLID,1/*线宽*/,RGB(0,0,0)/*画笔色*/);
CPen*pOldPen=dc.SelectObject(BlackPen1);
//以下画圆
HBRUSHhOldBrush1=(HBRUSH)dc.SelectObject(hNewBrush);
Rect.left=100;Rect.top=20;Rect.right=280;Rect.bottom=200;//圆区域
dc.Ellipse(Rect);//画圆
dc.SelectObject(hOldBrush1);
//恢复环境
dc.SelectObject(hOldBrush1);
dc.SelectObject(pOldPen);
deleteBlackPen1;
//画中间的圆
CBrushbrush1;
brush1.CreateSolidBrush(RGB(250,0,0));
HBRUSHhNewBrush11=(HBRUSH)brush1.m_hObject;
HBRUSHhOldBrush11=(HBRUSH)dc.SelectObject(hNewBrush11);
//HBRUSHhOldBrush11=(HBRUSH)dc.SelectObject(hNewBrush11);
Rect.left=185;Rect.top=105;Rect.right=195;Rect.bottom=115;//圆区域
CPen*RedPen=newCPen(PS_SOLID,1/*线宽*/,RGB(250,0,0)/*画笔色*/);
CPen*pOldPen4=dc.SelectObject(RedPen);
dc.Ellipse(Rect);//画圆
//恢复环境
dc.SelectObject(hOldBrush11);
dc.SelectObject(pOldPen4);
deleteRedPen;
//以下开始画刻度线,先画4条在x轴和y轴的
//先对4条xy轴的刻度线设置颜色
CPenBlackPen2;
BlackPen2.CreatePen(PS_SOLID,4,RGB(0,0,0));
CPen*pOldPen2=dc.SelectObject(&BlackPen2);
//开始画刻度
CPointpoint1=dc.MoveTo(190,20);//起点1
dc.LineTo(190,35);//终点1
CPointpoint2=dc.MoveTo(190,200);//起点2
dc.LineTo(190,185);//终点2
CPointpoint3=dc.MoveTo(280,110);//起点3
dc.LineTo(265,110);//终点3
CPointpoint4=dc.MoveTo(100,110);//起点4
dc.LineTo(115,110);//终点4
//恢复环境
dc.SelectObject(pOldPen2);
//写刻度上的字
CFontfont;
LOGFONTlf;
memset(&lf,0,sizeof(LOGFONT));
lf.lfHeight=15;//字高
strcpy(lf.lfFaceName,"TimesNewRoman");//字体
VERIFY(font.CreateFontIndirect(&lf));
HGDIOBJoldfont=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,"3");
dc.SelectObject(oldfont);
//画剩余的刻度,绿色的刻度
//设置画笔的颜色
CPenGreenPen;
GreenPen.CreatePen(PS_SOLID,4,RGB(0,128,0));
CPen*pOldPen3=dc.SelectObject(&GreenPen);
//开始画剩余的刻度
intmm,nn;
mm=int(90.0*sqrt(3.0)/2);
nn=int(70.0*sqrt(3.0)/2);
CPointpoint5=dc.MoveTo(190+45,110-mm);//起点5
dc.LineTo(190+35,110-nn);//终点5
CPointpoint6=dc.MoveTo(190+mm,110-45);//起点6
dc.LineTo(190+nn,110-35);//终点6
CPointpoint7=dc.MoveTo(190+mm,110+45);//起点7
dc.LineTo(190+nn,110+35);//终点7
CPointpoint8=dc.MoveTo(190+45,110+mm);//起点8
dc.LineTo(190+35,110+nn);//终点8
CPointpoint9=dc.MoveTo(190-45,110-mm);//起点9
dc.LineTo(190-35,110-nn);//终点9
CPointpoint10=dc.MoveTo(190-mm,110-45);//起点10
dc.LineTo(190-nn,110-35);//终点10
CPointpoint11=dc.MoveTo(190-mm,110+45);//起点11
dc.LineTo(190-nn,110+35);//终点11
CPointpoint12=dc.MoveTo(190-45,110+mm);//起点12
dc.LineTo(190-35,110+nn);//终点12
//恢复环境
dc.SelectObject(pOldPen3);
//输出当前时间
if(flag==0)
PutOutCurrentTime();
SetTimer(1,1000,0);//设定1秒钟时间
//画秒针
intx,y;
doublepi=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=newCPen(PS_SOLID,1/
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 参考 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)