普通软件界面上的走动时间是如何实现的?
用while循环一直打印吗?一直打印要刷新界面不怎么好。
还是设置定时器,然后触发事件,打印时间,
打印时间其实也没什么问题,可是要不停的刷新客户端就有问题?这个不知道怎么做
好多外面挂的大屏幕显示时间,很稳定,没看出来,是刷新做的。
希望大家教教我如何做一个在客户端显示时间的思路,有思路就可以了。
[解决办法]
1、设置窗体为Double Buffer模式,没有的话,自己构建双缓冲的显示机制;
2、开一个Timer,200ms触发一次,获取数据更新显示。
[解决办法]
仅供参考
- C/C++ code
#include <graphics.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <dos.h>#include <conio.h>#include <time.h>#include <math.h>time_t t;char timestr1[30];//DDD MMM dd hh:mm:ss YYYYchar timestr2[30];//DDD MMM dd hh:mm:ss YYYYchar hhmmss[9];int graphdriver,graphmode,page;int i,xo,yo,r0,r1,r2,r3,r4,r5,r6,r7;int x1,y1,x2,y2;int hh,mm,ss;double c,s;int xasp,yasp;void main() { xo=60;yo=60; r0=5; //轴 r1=20;//时针 r2=36;//分针 r3=45;//秒针 r4=50;//时刻度 r5=53;//分刻度 r6=55;//刻度外 r7=59;//表盘 graphdriver=VGA; graphmode=VGAMED; initgraph(&graphdriver,&graphmode,"C:\\BC\\BGI"); getaspectratio(&xasp, &yasp); page=0; timestr2[0]=0; while (1) { if (kbhit()) break; time(&t); strcpy(timestr1,ctime(&t)); if (strcmp(timestr1,timestr2)) { strcpy(timestr2,timestr1); hh=atoi(timestr2+11); mm=atoi(timestr2+14); ss=atoi(timestr2+17); setvisualpage(page); setactivepage(1-page); cleardevice(); sprintf(hhmmss,"%02d:%02d:%02d",hh,mm,ss); outtextxy(28,0,hhmmss); pieslice(xo,yo,0,360,r0); circle(xo,yo,r7); for (i=0;i<60;i++) { c=cos(i*6*3.14159265/180); s=sin(i*6*3.14159265/180)*xasp/yasp; if (0==(i%5)) { x1=xo+r4*c; y1=yo+r4*s; } else { x1=xo+r5*c; y1=yo+r5*s; } x2=xo+r6*c; y2=yo+r6*s; line(x1,y1,x2,y2); if (((hh%12)*5+mm/12+45)%60==i) { x2=xo+r1*c; y2=yo+r1*s; setlinestyle(0,-1,3); line(xo,yo,x2,y2); setlinestyle(0,-1,1); } if ((mm+45)%60==i) { x2=xo+r2*c; y2=yo+r2*s; setlinestyle(0,-1,3); line(xo,yo,x2,y2); setlinestyle(0,-1,1); } if ((ss+45)%60==i) { x2=xo+r3*c; y2=yo+r3*s; line(xo,yo,x2,y2); } } page=1-page; } delay(100); } getch(); closegraph();}
[解决办法]
1、用Double Buffer才能使得画面切换比较平滑,建议查查这方面的资料先;
2、因为最频繁的是秒数,你的Timer用于采样,肯定要高于秒的频率,200ms只是一个参考。
[解决办法]
看LZ以往都是做后台的。
前台个人觉得会比较悲剧,了解下基本的Windows编程吧。
[解决办法]
如果是win32 可以SetTimer一个定时器 1秒触发一次
然后在WM_TIMER里 获取信息 刷新界面
也可以开一个线程 Sleep(1000)然后更新界面
[解决办法]