當前位置:首頁 » 編程語言 » c語言設計時鍾

c語言設計時鍾

發布時間: 2024-12-26 14:15:54

『壹』 c語言編圖形時鍾

給你2個選吧,都是原創:
第1個:
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init()
{int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++)
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s;
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7);
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
{while(t[0].ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch();
closegraph();
}

第2個:
#include<graphics.h>
#include<math.h>
#include<dos.h>

#define PI 3.1415926
#define x0 320 /*定義鍾表中心坐標*/
#define y0 240

void DrawClock(int x,int y,int color) /*畫表盤*/
{ int r=150; /*表盤的半徑*/
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}

void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}

void main()
{int gdriver=DETECT,gmode;
struct time curtime;
float th_hour,th_min,th_sec;
initgraph(&gdriver,&gmode,"");

setbkcolor(0);

while(! kbhit())
{
DrawClock(x0,y0,14);
gettime(&curtime); /*得到當前系統時間*/

gotoxy(35,20); /*定位輸出位置*/
if((float)curtime.ti_hour<=12) /*午前的處理*/
{printf("AM ");
if((float)curtime.ti_hour<10) printf("0"); /*十點之前在小時數前加零*/
printf("%.0f:",(float)curtime.ti_hour);
}
else /*午後的處理*/
{printf("PM ");
if((float)curtime.ti_hour-12<10) printf("0");
printf("%.0f:",(float)curtime.ti_hour-12);
}

if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);

/*以下三行計算表針轉動角度,以豎直向上為起點,順時針為正*/

th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,70,2); /*畫時針*/
DrawHand(x0,y0,th_min,110,3); /*分針*/
DrawHand(x0,y0,th_sec,140,12); /*秒針*/

sleep(1); /*延時一秒後刷新*/
cleardevice();
}

closegraph();
}

『貳』 跪求單片機c51一個多功能時鍾設計。要鬧鍾。調整時間、秒錶、就行了。急求。。。C語言編寫

//給你發一個數碼管輸出的可調節時鍾的程序,<DS1302.H>在最後
#include <at89x52.h>
#include <DS1302.h>
//定義共陽極字型碼0123456789-
unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
unsigned char time[]={0,0,0,0,0,0,0,0};//用來儲存時間
unsigned char date[]={0,0,0,0,0,0,0,0};//用來儲存日期
SYSTEMTIME time1; //在ds1302.h文件中已經定義了一個名字為SYSTEMTIME的結構體,在這里我們定義一個變數名
//為time的SYSTEMTIME結構體
void delay(unsigned char i) //延時子程序
{
unsigned char j;
while((i--)!=0)
{
for(j=123;j>0;j--);
}
}
unsigned char button_time(n,x,y) //時鍾調整子程序
unsigned char n,x,y;
{
if(P1_7==0)
{
delay(50);
if(P1_7==0)
{
n++;
if(n==x)
n=0;
while(P1_7==0);
}
}

if(P1_5==0)
{
delay(50);
if(P1_5==0)
{
if(n==0)
n=y;
else
n--;
while(P1_5==0);
}
}
return n;
}

unsigned char button_date(n,x,y) //日期調整子程序
unsigned char n,x,y;
{
if(P1_7==0)
{
delay(50);
if(P1_7==0)
{
n++;
if(n==x)
n=1;
while(P1_7==0);
}
}

if(P1_5==0)
{
delay(50);
if(P1_5==0)
{
if(n==1)
n=y;
else
n--;
while(P1_5==0);
}
}
return n;
}

void display(second10,second1,minute10,minute1,hour10,hour1) //顯示子程序
unsigned char second10,second1,minute10,minute1,hour10,hour1;
{
P2=0xfe;
P0=dispcode[second10];//顯示秒的十位
delay(1);

P2=0xfd;
P0=dispcode[second1]; //顯示秒的個位
delay(1);

P2=0xfb;
P0=dispcode[10]; //顯示"-"
delay(1);

P2=0xf7;
P0=dispcode[minute10];//顯示分的十位
delay(1);

P2=0xef;
P0=dispcode[minute1]; //顯示分的個位
delay(1);

P2=0xdf;
P0=dispcode[10]; //顯示"-"
delay(1);

P2=0xbf;
P0=dispcode[hour10]; //顯示時的十位
delay(1);

P2=0x7f;
P0=dispcode[hour1]; //顯示時的個位
delay(1);
}

void main()
{
unsigned char flag;
Initial_DS1302(); //初始化DS1302這個時鍾晶元,
while(1)
{
DS1302_GetTime(&time1); //讀取時間參數
time[5]=(time1.Second)%10; //把秒的個位數據存入time[5]
time[4]=(time1.Second)/10; //把秒的十位數據存入time[4]
time[3]=(time1.Minute)%10; //把分的個位數據存入time[3]
time[2]=(time1.Minute)/10; //把分的十位數據存入time[2]
time[1]=(time1.Hour)%10; //把時的個位數據存入time[1]
time[0]=(time1.Hour)/10; //把時的十位數據存入time[0]
date[5]=(time1.Day)%10;
date[4]=(time1.Day)/10;
date[3]=(time1.Month)%10;
date[2]=(time1.Month)/10;
date[1]=(time1.Year)%10;
date[0]=(time1.Year)/10;

if(P1_4==0) //如果按下Time Start鍵一下,時鍾開始正常顯示時間,再按一下,顯示日期
{
delay(50);
if(P1_4==0)
{
flag++;
if(flag>1)
{
flag=0;
}
}
while(P1_4==0);
}
if(P1_6==0) //如果按下Time Set鍵一下,開始顯示日期,再按一下進入日期跟時鍾的調節模式
{
delay(50);
if(P1_6==0)
{
flag++;
if(flag>7)
{
flag=0;
}
}
while(P1_6==0);
}

switch(flag)
{
case 0:display(time[0],time[1],time[2],time[3],time[4],time[5]); //調用子函數display,把存入數組time的數據給顯示出來
break;

case 1:display(date[0],date[1],date[2],date[3],date[4],date[5]); //調用子函數display,把存入數組date的數據給顯示出來
break;

case 2:time1.Year=button_date(time1.Year,100,99); //調整年
DS1302_SetTime(0x8c,time1.Year);
display(date[0],date[1],10,10,10,10);
break;

case 3:time1.Month=button_date(time1.Month,13,12); //調整月
DS1302_SetTime(0x88,time1.Month);
display(10,10,date[2],date[3],10,10);
break;

case 4:time1.Day=button_date(time1.Day,32,31); //調整日
DS1302_SetTime(0x86,time1.Day);
display(10,10,10,10,date[4],date[5]);
break;

case 5:time1.Hour=button_time(time1.Hour,24,23); //調整時
DS1302_SetTime(0x84,time1.Hour);
display(time[0],time[1],10,10,10,10);
break;

case 6:time1.Minute=button_time(time1.Minute,60,59); //調整分
DS1302_SetTime(0x82,time1.Minute);
display(10,10,time[2],time[3],10,10);
break;

case 7:time1.Second=button_time(time1.Second,60,59); //調整秒
DS1302_SetTime(0x80,time1.Second);
display(10,10,10,10,time[4],time[5]);
break;
}
}
}
//DS1302.H

#ifndef _REAL_TIMER_DS1302_2003_7_21_
#define _REAL_TIMER_DS1302_2003_7_21_
#include <at89x52.h>
sbit DS1302_CLK = P1^0; //實時時鍾時鍾線引腳
sbit DS1302_IO = P1^1; //實時時鍾數據線引腳
sbit DS1302_RST = P1^2; //實時時鍾復位線引腳
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;

typedef struct __SYSTEMTIME__
{
unsigned char Second;
unsigned char Minute;
unsigned char Hour;
unsigned char Week;
unsigned char Day;
unsigned char Month;
unsigned char Year;
unsigned char DateString[9];
unsigned char TimeString[9];
}SYSTEMTIME; //定義的時間類型

#define AM(X) X
#define PM(X) (X+12) // 轉成24小時制
#define DS1302_SECOND 0x80 //秒寄存器
#define DS1302_MINUTE 0x82 //分寄存器
#define DS1302_HOUR 0x84
#define DS1302_WEEK 0x8A
#define DS1302_DAY 0x86
#define DS1302_MONTH 0x88
#define DS1302_YEAR 0x8C
#define DS1302_RAM(X) (0xC0+(X)*2) //用於計算 DS1302_RAM 地址的宏

void DS1302InputByte(unsigned char d) //實時時鍾寫入一位元組(內部函數)
{
unsigned char i;
ACC = d;
for(i=8; i>0; i--)
{
DS1302_IO = ACC0; //相當於匯編中的 RRC
DS1302_CLK = 1;
DS1302_CLK = 0; //發一個高跳變到低的脈沖
ACC = ACC >> 1;
}
}

unsigned char DS1302OutputByte(void) //實時時鍾讀取一位元組(內部函數)
{
unsigned char i;
for(i=8; i>0; i--)
{
ACC = ACC >>1; //相當於匯編中的 RRC
ACC7 = DS1302_IO;
DS1302_CLK = 1;
DS1302_CLK = 0; //發一個高跳變到低的脈沖
}
return(ACC);
}

void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要寫的數據
{
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // 地址,命令
DS1302InputByte(ucDa); // 寫1Byte數據
DS1302_CLK = 1;
DS1302_RST = 0; //RST 0->1->0,CLK 0->1
}

unsigned char Read1302(unsigned char ucAddr) //讀取DS1302某地址的數據
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1; //enable
DS1302InputByte(ucAddr|0x01); // 地址,命令
ucData = DS1302OutputByte(); // 讀1Byte數據
DS1302_CLK = 1; //RST 0->1->0,CLK 0->1
DS1302_RST = 0;
return(ucData);
}

void DS1302_SetProtect(bit flag) //是否防寫
{
if(flag)
Write1302(0x8E,0x10); //WP=1,不能寫入
else
Write1302(0x8E,0x00);//WP=0,可以寫入
}

void DS1302_SetTime(unsigned char Address, unsigned char Value) // 設置時間函數
{
DS1302_SetProtect(0);
Write1302(Address, ((Value/10)<<4 | (Value%10))); //高4位為十位,低4位為個位
}

void DS1302_GetTime(SYSTEMTIME *Time)
{
unsigned char ReadValue;
ReadValue = Read1302(DS1302_SECOND);
Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//轉換成10進制的秒
ReadValue = Read1302(DS1302_MINUTE);
Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
ReadValue = Read1302(DS1302_HOUR);
Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
ReadValue = Read1302(DS1302_DAY);
Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
ReadValue = Read1302(DS1302_WEEK);
Time->Week = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
ReadValue = Read1302(DS1302_MONTH);
Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
ReadValue = Read1302(DS1302_YEAR);
Time->Year = ((ReadValue&0xf0)>>4)*10 + (ReadValue&0x0F);
}
/*
void DateToStr(SYSTEMTIME *Time)
{
Time->DateString[0] = Time->Year/10 + '0'; //數字類型轉化為字元類型
Time->DateString[1] = Time->Year%10 + '0';
Time->DateString[2] = '-';
Time->DateString[3] = Time->Month/10 + '0';
Time->DateString[4] = Time->Month%10 + '0';
Time->DateString[5] = '-';
Time->DateString[6] = Time->Day/10 + '0';
Time->DateString[7] = Time->Day%10 + '0';
Time->DateString[8] = '\0';
}

void TimeToStr(SYSTEMTIME *Time)
{
Time->TimeString[0] = Time->Hour/10 + '0'; //數字類型轉化為字元類型
Time->TimeString[1] = Time->Hour%10 + '0';
Time->TimeString[2] = ':';
Time->TimeString[3] = Time->Minute/10 + '0';
Time->TimeString[4] = Time->Minute%10 + '0';
Time->TimeString[5] = ':';
Time->TimeString[6] = Time->Second/10 + '0';
Time->TimeString[7] = Time->Second%10 + '0';
Time->DateString[8] = '\0';
}
*/
void Initial_DS1302(void)
{
unsigned char Second=Read1302(DS1302_SECOND);
if(Second&0x80) //如果第七為1(表明沒有啟動), 則啟動時鍾
DS1302_SetTime(DS1302_SECOND,0);
}

/********************************************************************************
void BurstWrite1302(unsigned char *pWClock) //往DS1302寫入時鍾數據(多位元組方式)
{
unsigned char i;
Write1302(0x8e,0x00); // 控制命令,WP=0,寫操作?
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(0xbe); // 0xbe:時鍾多位元組寫命令
for (i = 8; i>0; i--) //8Byte = 7Byte 時鍾數據 + 1Byte 控制
{
DS1302InputByte(*pWClock); // 寫1Byte數據
pWClock++;
}
DS1302_CLK = 1;
DS1302_RST = 0;
}

void BurstRead1302(unsigned char *pRClock) //讀取DS1302時鍾數據(時鍾多位元組方式)
{
unsigned char i;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(0xbf); // 0xbf:時鍾多位元組讀命令
for (i=8; i>0; i--)
{
*pRClock = DS1302OutputByte(); // 讀1Byte數據
pRClock++;
}
DS1302_CLK = 1;
DS1302_RST = 0;
}

void DS1302_TimeStop(bit flag) // 是否將時鍾停止
{
unsigned char Data;
Data=Read1302(DS1302_SECOND);
DS1302_SetProtect(0);
if(flag)
Write1302(DS1302_SECOND, Data|0x80);//停止
else
Write1302(DS1302_SECOND, Data&0x7F);不停止
}
********************************************************************************/
#endif

『叄』 數字時鍾C語言設計.用的是51單片機。 00 秒 00 分 00 小時 還有小數點。 麻煩把程序代碼告訴我把

我這寫了一個!使用數碼管顯示的!可以用鍵盤校對時間!你參考下。還寫了一個液晶顯示的!你要的話也可以發給你!
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit K1=P3^0;
sbit K2=P3^1;
sbit K3=P3^2;
uchar table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
uchar table1[]={0x5b,0x66,0x6d,0x6f,0x6d,0x6f};
uchar table2[]={0,1,0,0,0,0};
int shi=1,fen=0,miao=0;
uchar a,i,j,temp=-2,temp1;
void sfm(uchar dz,uchar shu);//將計的數的十位和個位分開
void display();//將時間顯示出來
void display1(uchar dz);//只顯示要校對的數
void init();//初始化
void jiaoshi();//定義一個校時函數
void delay(uchar z)//定義一個延時函數
{
uchar x,y;
for(x=0;x<50;x++)
for(y=0;y<z;y++);
}
void main()
{
init();
while(1)
{
jiaoshi();
}
}
void init()
{
EA=1;
ET0=1;
ET1=1;
TR1=1;
TR0=0;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
K1=K2=1;
temp1=0;
while(TR1)
{
for(i=0;i<6;i++)
{
delay(3);
P1=i;
P2=table1[i];
delay(3);
}
}
}
void sfm(uchar dz,uchar shu)
{
if(shu==60&dz!=0) shu=0;
table2[dz]=shu/10;
table2[dz+1]=shu%10;

}
void display()
{
uchar j;
for(j=0;j<6;j++)
{
delay(3);
P1=j;
P2=table[table2[j]];
delay(3);
}
}
void display1(uchar dz)
{
uchar j;
for(j=0;j<2;j++)
{
delay(3);
P1=dz+j;
P2=table[table2[dz+j]];
delay(3);
}
}
void jiaoshi()
{
uchar a;
if(K1==0)
{
delay(5);
if(K1==0)
{
TR0=0;
a++;
temp+=2;
if(a==4|temp==6)
{
a=0;
temp=-2;
TR0=1;
}
}
}
while(!K1)
{
delay(5);
display1(temp);
}
while(!K1);
display1(temp);
if(K2==0)
{
delay(5);
if(K2==0)
{
if(a==1)
{
temp=0;
if(shi==24)
shi=0;
shi++;
sfm(0,shi);
}
if(a==2)
{
temp=2;
if(fen==59)
fen=-1;
fen++;
sfm(2,fen);
}
if(a==3)
{
temp=4;
if(miao==59)
miao=-1;
miao++;
sfm(4,miao);
}
}
}
while(!K2)
{
delay(5);
display1(temp);
}
while(!K2);
if(K3==0)
{
delay(5);
if(K3==0)
{
if(a==1)
{
shi--;
if(shi==0)
shi=24;
sfm(0,shi);
}
if(a==2)
{
fen--;
if(fen==-1)
fen=59;
sfm(2,fen);
}
if(a==3)
{
miao--;
if(miao==-1)
miao=59;
sfm(4,miao);
}
}
}
while(!K3)
{
delay(5);
display1(temp);
}
while(!K3);
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
if(a==16)
{
a=0;
miao++;
sfm(4,miao);
if(miao==60)
{
miao=0;
display();
fen++;
sfm(2,fen);
if(fen==60)
{
fen=0;
shi++;
sfm(0,shi);
if(shi==25)
{
shi=1;
sfm(0,shi);
}
}
}
}
display();
}
void timer1() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
j++;
if(j==20)
{
TR0=1;
TR1=0;
}
}

『肆』 c語言怎麼樣編寫一個時鍾程序

c語言時鍾程序代碼如下:

#include<windows.h>

#include<math.h>

#define ID_TIMER 1//計時器ID

#define TWOPI (2*3.14159)

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)

{

static TCHAR szAppName[]=TEXT("Clock");

HWND hwnd;

MSG msg;

WNDCLASS wndclass;

wndclass.cbClsExtra=0;

wndclass.cbWndExtra=0;

wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);

wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);

wndclass.hInstance=hInstance;

wndclass.lpfnWndProc=WndProc;

wndclass.lpszClassName=szAppName;

wndclass.lpszMenuName=NULL;

wndclass.style=CS_HREDRAW|CS_VREDRAW;

if(!RegisterClass(&wndclass))

{

MessageBox(NULL,TEXT("This program requires Windows

T"),szAppName,MB_ICONERROR);

return 0;

}

hwnd=CreateWindow(szAppName,TEXT("Analog Clock"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,iCmdShow);

UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

void Setsotropic(HDC hdc,int cxClient,int cyClient)

{

SetMapMode(hdc,MM_ISOTROPIC);

SetWindowExtEx(hdc,1000,1000,NULL);

SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL);

SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);

}

void RotatePoint(POINT pt[],int iNum,int iAngle)

{

int i;

POINT ptTemp;

for(i=0;i<iNum;i++)

{

ptTemp.x=(int)(pt[i].x*cos(TWOPI*iAngle/360)+pt[i].y*sin(TWOPI*iAngle/360));

ptTemp.y=(int)(pt[i].y*cos(TWOPI*iAngle/360)+pt[i].x*sin(TWOPI*iAngle/360));

pt[i]=ptTemp;

}

}

void DrawClock(HDC hdc)

{

int iAngle;

POINT pt[3];

for(iAngle=0;iAngle<360;iAngle+=6)

{

pt[0].x=0;

pt[0].y=900;

RotatePoint(pt,1,iAngle);

pt[2].x=pt[2].y=iAngle%5?33:100;

pt[0].x-=pt[2].x/2;

pt[0].y-=pt[2].y/2;

pt[1].x=pt[0].x+pt[2].x;

pt[1].y=pt[0].y+pt[2].y;

SelectObject(hdc,GetStockObject(BLACK_BRUSH));

Ellipse(hdc,pt[0].x,pt[0].y,pt[1].x,pt[1].y );

}

}

void DrawHands(HDC hdc,SYSTEMTIME *pst,BOOL fChange)

{

static POINT pt[3][5]={0,-150,100,0,0,600,-100,0,0,-150, 0,-200,50,0,0,800,-50,0,0,-200, 0,0,0,0,0,0,0,0,0,800 };

int i,iAngle[3];

POINT ptTemp[3][5];

iAngle[0]=(pst->wHour*30)%360+pst->wMinute/2;

iAngle[1]=pst->wMinute*6;

iAngle[2]=pst->wSecond*6;

memcpy(ptTemp,pt,sizeof(pt));

for(i=fChange?0:2;i<3;i++)

{

RotatePoint(ptTemp[i],5,iAngle[i]);

Polyline(hdc,ptTemp[i],5);

}

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

{

static int cxClient,cyClient;

static SYSTEMTIME stPrevious;

BOOL fChange;

HDC hdc;

PAINTSTRUCT ps;

SYSTEMTIME st;

switch(message)

{

case WM_CREATE:

SetTimer(hwnd,ID_TIMER,1000,NULL);

GetLocalTime(&st);

stPrevious=st;

return 0;

case WM_SIZE:

cxClient=LOWORD(lParam);

cyClient=HIWORD(lParam);

return 0;

case WM_TIMER:

GetLocalTime(&st);

fChange=st.wHour!=stPrevious.wHour||st.wMinute!=stPrevious.wMinute;

hdc=GetDC(hwnd);

Setsotropic(hdc,cxClient,cyClient);

SelectObject(hdc,GetStockObject(WHITE_PEN));

DrawHands(hdc,&stPrevious,fChange);

SelectObject(hdc,GetStockObject(BLACK_PEN));

DrawHands(hdc,&st,TRUE);

stPrevious=st;

return 0;

case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);

Setsotropic(hdc,cxClient,cyClient);

DrawClock(hdc);

DrawHands(hdc,&stPrevious,TRUE);

EndPaint(hwnd,&ps);

return 0;

case WM_DESTROY:

KillTimer(hwnd,ID_TIMER);

PostQuitMessage(0);

return 0;

}

return DefWindowProc(hwnd,message,wParam,lParam);

}

熱點內容
介面速率怎麼配置 發布:2024-12-27 02:42:58 瀏覽:470
原神主角聖遺物怎麼配置 發布:2024-12-27 02:24:33 瀏覽:857
寫小說的腳本怎麼樣 發布:2024-12-27 02:19:26 瀏覽:169
雙線雙ip伺服器 發布:2024-12-27 02:15:27 瀏覽:195
分鏡頭電視腳本 發布:2024-12-27 02:11:18 瀏覽:675
腳本反轉劇情 發布:2024-12-27 02:02:53 瀏覽:732
c語言是什麼軟體 發布:2024-12-27 01:56:43 瀏覽:596
二叉樹遞歸演算法 發布:2024-12-27 01:55:06 瀏覽:881
安卓怎麼氪金日服 發布:2024-12-27 01:53:39 瀏覽:9
linux增加命令 發布:2024-12-27 01:37:13 瀏覽:720