三九宝宝网宝宝教育教学论文

C语言编图形时钟

03月18日 编辑 39baobao.com

[C语言图形界面]登陆框会要求你自行建立对话框资源,并定义框体坐标,并且要求建立相应的对象来操作这些资源,如果你对MFC一无所知,我最好用一个以弹出菜单来响应鼠标事件为例给你讲解: 文件->新...+阅读

试试这个 #include"graphics.h" #define PI 3.1416 #include"math.h" #include"dos.h" main() { int x0=320,y0=240,r0=150; void init_sceen(); void sec(); init_sceen(x0,y0,r0); sec(); closegraph(); } void init_sceen(int x0,int y0,int r0)/********************************************/ { int i,x,y,graphdriver,graphmode; char s[10]; float alpha,a0=90; graphdriver=DETECT; initgraph(&graphdriver,&graphmode,""); setbkcolor(3); setcolor(2); circle(x0,y0,r0); circle(x0,y0,r0+30); setfillstyle(SOLID_FILL,10); floodfill(x0-r0-10,y0,2); /*please input the time*/ for(i=12;i>=1;i--) { alpha=(a0+30*(11-i)*PI/180); x=x0+cos(alpha)*r0-16; y=y0-sin(alpha)*r0; sprintf(s,"%2d",i); setcolor(4); settextstyle(0,0,2); outtextxy(x,y,s); } /*input second*/ for(i=60;i>=1;i--) { alpha=(a0+6*(60-i)*PI/180); x=x0+cos(alpha)*(r0-20); y=y0-sin(alpha)*(r0-20); setcolor(14); if(i%5==0) circle(x,y,5); else circle(x,y,2); floodfill(x,y,14); } setlinestyle(0,0,3); } void sec(void) /******************************************************************/ { int x,y,i,j,k,xj,yj,xk,yk,xi,yi,x0=320,y0=240,r0=150; union REGS r; unsigned char *shijie=""; unsigned char *daa=""; struct time tim; struct date dat; float alphai,alphak,alphaj,a0=90; xi=x0;yi=y0;xj=x0;yj=y0;xk=x0;yk=y0; do { /*intput the time*/ x=38;y=12; gettime(&tim); sprintf(shijie,"%02d:%02d:%02d",tim.ti_hour,tim.ti_min,tim.ti_sec); setfillstyle(SOLID_FILL,0); bar(245,190,375,210); setcolor(15); outtextxy(245,190,shijie); /*input the date*/ /*****************************************************/ getdate(&dat); sprintf(daa,"%02d--%02d--%02d",dat.da_year,dat.da_mon,dat.da_day); /*setfillstyle(SOLID_FILL,3);*/ bar(225,290,395,310); setcolor(RED); outtextxy(225,290,daa); x=190;y=430; setcolor(RED); outtextxy(x-26,y,"Designed by GuoLiuTa0"); setcolor(LIGHTRED); outtextxy(x+76,y0+20,"NBA GAME"); setlinestyle(0,0,3); k=tim.ti_hour; j=tim.ti_min; i=tim.ti_sec; alphak=(a0+30*(12-k)-j*5/60.*6)*PI/180; alphaj=(a0-6*j)*PI/180; /*write second hand*/ alphai=(a0+6*(60-i))*PI/180; x=x0+cos(alphai)*(r0-32); y=y0-sin(alphai)*(r0-32); setcolor(BLACK); line(x0,y0,xi,yi); setcolor(YELLOW); line(x0,y0,x,y); xi=x; yi=y; /*write minute hand*/ x=x0+cos(alphaj)*(r0-60); y=y0-sin(alphaj)*(r0-60); setcolor(BLACK); line(x0,y0,xj,yj); setcolor(BLUE); line(x0,y0,x,y); xj=x; yj=y; /*write hour hand*/ x=x0+cos(alphak)*(r0-99); y=y0-sin(alphak)*(r0-99); setcolor(BLACK); line(x0,y0,xk,yk); setcolor(RED); line(x0,y0,x,y); xk=x; yk=y; delay(10000); } while(!kbhit()); }或者这个/*全屏幕模拟时钟的c源程序*/ #include#include#include#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(0); circle(300,240,200); circle(300,240,205); circle(300,240,5); for(i=0;i

整点报时程序DELPHI

unit Unit1;interfaceuses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ExtCtrls;type

TForm1 = class(TForm)

Timer1: TTimer;

Label1: TLabel;

Label2: TLabel;

procedure Timer1Timer(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;var

Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);

var s :string;

begin

Label1.Caption := FormatDateTime('yyyy/mm/dd AM/PM hh:mm ', Now + 0.125);

Label2.Caption := FormatDateTime('hhmmss',now());

if(FormatDateTime('hhmmss',now())='000000') then

showmessage(FormatDateTime('yyyy/mm/dd AM/PM hh:mm ', Now + 0.125));

end;end.

c语言的时钟程序

#include#include#include#define PI 3.1415926 //屏幕中心的坐标(640X480模式下)#define mid_x 320 #define mid_y 240 int main() { int graphdriver=DETECT,graphmode; int end_x,end_y; struct time curtime; float th_hour,th_min,th_sec; initgraph(&graphdriver,&graphmode,"C:\\TC2"); //初始化VGA屏幕模式 setbkcolor(BLACK); //使用黑色的背景色 while(!kbhit(0)) //若有键盘输入,则跳出,即是结束程序 { setcolor(GREEN); //把画笔设为绿色 circle(mid_x,mid_y,180); //钟的外圆 circle(mid_x,mid_y,150); //钟的内圆 circle(mid_x,mid_y,1); //画出钟的圆心 gettime(&curtime); //取得系统当前时间 th_sec=(float)curtime.ti_sec*0.1047197551; //把秒针的角度化为弧度,为以后绘制时方便,下同 th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0; //分针的弧度 th_hour=(float)curtime.ti_hour*0.5235987755+th_min/12.0; //时度的弧度,注意整时是12等分的,所时乘的是3.14/180*5//计算出时针的尾的坐标(时针长70) end_x=mid_x+70*sin(th_hour); end_y=mid_y-70*cos(th_hour); setcolor(RED); line(mid_x,mid_y,end_x,end_y); //用红色线画出时针//计算出分针坐标(分针长110) end_x=mid_x+110*sin(th_min); end_y=mid_y-110*cos(th_min); setcolor(RED); line(mid_x,mid_y,end_x,end_y); //用红色画出分针 end_x=mid_x+140*sin(th_sec); end_y=mid_y-140*cos(th_sec); setcolor(RED); line(mid_x,mid_y,end_x,end_y); //同上,画出秒针,长为140//画出钟盘上的刻度,刻度长20 line(140,240,160,240); //9点对应的大刻度 line(320,60,320,80); //12点对应的大刻度 line(500,240,480,240); //3点的刻度 line(320,420,320,400); //6点的刻度 line(410,395.7,400,378.4); //5点 line(475.7,330,458.4,320); //4点 line(475.7,150,458.4,160); //2点 line(410,84.3,400,101.6); //1点 line(230,84.3,240,101.6); //11点 line(164.3,150,181.6,160); //10点 line(164.3,330,181.6,320); //8点 line(230,395.7,240,378.4); //7点 sleep(BLUE); //这里应该是打错,停止一秒,应为sleep(1000) cleardevice(); //清除屏幕上的显示 } closegraph(); //关闭VGA屏幕,即返回文本方式 return 0; }

以下为关联文档:

c语言怎样编图形界面啊#include #include #define PI 3.1415926 void main() { double a; int x,y,y1,r,r1; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\turboc2\\bgi"); printf("Pl...

求c语言实现图形界面c c c语言都可以那得学习windows编程了。。。用VC6.0新建一个wn32程序,而不DOS程序,输入如下代码即可:#include#include#include#includeint g_nYPos = 200; //文字的Y坐标 long WINAPI WndProc...

我要做一个C语言的图形界面用vc编希望可以用鼠标点击#include "stdio.h" #include "windows.h" LRESULT CALLBACK wndproc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam); class win { public: BOOL W_class(HINSTANCE hInsta...

c语言二维函数图形# include "graphics.h" # include "math.h" # define N 100 void init_graphic( ) main() { int i; float x0,y0,x,y; float x[100],y[100]; init_graphic(); for(i=0;i<100;i+...

c语言输出图形编写函数。函数功能输出如下图形#include<stdio.h> void main() { int i,j,n; printf("请输入菱形的高\t"); scanf("%d",&n); for(i=1;i<=n/2+1;i++)//打印上面 { for(j=1;j<=n-i;j++) //打印空格 { printf(" "); }...

用c语言编电子时钟#include <graphics.h> #include <math.h> #include <dos.h> #include <conio.h> #define PI 3.1415926 /*定义常量*/ #define mid_x 240 /*定义常量*/ #define mid_y 240 /...

c语言倒计时时钟程序如果你有TC,可以试一试。 VC 的 kbhit() 不能返回 键名。 23:59:59 -- 86400 秒 #include <stdio.h> #include <windows.h> #include <conio.h> void main() { long int t; in...

C语言图形编程在绘图之前要先在网上下一个绘画的库 graphics.h 可以在这个网站下这个文件, http://code.google.com/p/vcgraphics/downloads/list 具体代码如下: #include<graphics.h> #inc...

C语言编游戏?用Visual C++ ,或者加载图形驱动 1. C语言适合基层编程。涉及到网络,图形,音频的程序,用C++要方便很多。尤其图形界面这一点,C虽然也能做到,但是效果很差,C++的程序才可能有你说的...

推荐阅读
图文推荐