资源描述:
《Windows编程之定时器用于时钟.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Windows编程之定时器用于时钟时钟是定时器最明显的应用,因此让我们来看看两个时钟,一个数字时钟,一个模拟时钟。建立数字时钟程序8-3所示的DIGCLOCK程序,使用类似LED的7个显示方块显示了目前的时间。程序8-3DIGCLOCKDIGCLOCK.C/*----------------------------------------------------------------------------DIGCLOCK.C--DigitalClock(c)CharlesPetzold,1998---------------------------
2、-------------------------------------------------*/#include#defineID_TIMER1LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT("DigClock");HWNDhwnd;MSGmsg;WND
3、CLASSwndclass;wndclass.style=CS_HREDRAW
4、CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetSt
5、ockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT("ProgramrequiresWindowsNT!"),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,TEXT("DigitalClock"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
6、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);}returnmsg.wParam;}voidDisplayDigit(HDChdc,intiNumber){staticBOOLfSevenSegment[10][7]={1
7、,1,1,0,1,1,1,//00,0,1,0,0,1,0,//11,0,1,1,1,0,1,//21,0,1,1,0,1,1,//30,1,1,1,0,1,0,//41,1,0,1,0,1,1,//51,1,0,1,1,1,1,//61,0,1,0,0,1,0,//71,1,1,1,1,1,1,//81,1,1,1,0,1,1};//9staticPOINTptSegment[7][6]={7,6,11,2,31,2,35,6,31,10,11,10,6,7,10,11,10,31,6,35,2,31,2,11,36,7,40,11,40,31,36
8、,35,32,31,32,11,7,36,11,32,31,32,35,36,31,40,11,40,6,37,10,41,10,61,6,65,2,61,2,41,36,37,40,41,40,61,36,65,32,61,32,41,7,66,11,62,31,62,35,66,31,70,11,70};intiSeg;for(iSeg=0;iSeg<7;iSeg++)if(fSevenSegment[iNumber][iSeg])Polygon(hdc,ptSegment[iSeg],6);}voidDisplayTwoDigits(HDChdc
9、,intiNumber,BOOLfSuppress){if(!fSuppress
10、
11、(iNum