资源描述:
《windows程序设计举例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、效果显示:步骤1:2.3.点完成4.将以下的代码,写入clock..cpp(下面的代码是经过对工程裁剪,又添加的)/*时钟程序以下参考《WIndows程序设计》做了比较详细的解释****************************/#include"stdafx.h"HINSTANCEhInst;//函数声明ATOMMyRegisterClass(HINSTANCEhInstance);BOOLInitInstance(HINSTANCE,int);LRESULTCALLBACKWndProc(
2、HWND,UINT,WPARAM,LPARAM);voidDisplayTime(HDChdc,BOOLf24hour,BOOLfNzero);voidDisPlayColon(HDChdc);voidDisplayTwoDigits(HDChdc,intnNumber,BOOLbNzero);voidDisPlayDigit(HDChdc,intnNumber);intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlp
3、CmdLine,intnCmdShow){//TODO:Placecodehere.MSGmsg;MyRegisterClass(hInstance);//Performapplicationinitialization:if(!InitInstance(hInstance,nCmdShow)){returnFALSE;}//Mainmessageloop:while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(
4、&msg);}returnmsg.wParam;}ATOMMyRegisterClass(HINSTANCEhInstance){WNDCLASSEXwcex;wcex.cbSize=sizeof(WNDCLASSEX);wcex.style=CS_HREDRAW
5、CS_VREDRAW;wcex.lpfnWndProc=(WNDPROC)WndProc;wcex.cbClsExtra=0;wcex.cbWndExtra=0;wcex.hInstance=hInstance;wcex.hIcon=::
6、LoadIcon(hInst,IDI_APPLICATION);wcex.hCursor=LoadCursor(NULL,IDC_ARROW);wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName=NULL;wcex.lpszClassName="clock";wcex.hIconSm=NULL;returnRegisterClassEx(&wcex);}BOOLInitInstance(HINSTANCEhInstance,in
7、tnCmdShow){HWNDhWnd;hInst=hInstance;hWnd=CreateWindow("clock","河池-狼影",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);if(!hWnd){returnFALSE;}ShowWindow(hWnd,nCmdShow);UpdateWindow(hWnd);returnTRUE;}//以上部分我就不做多余的解释啦,我想看到这的基
8、本都会知道上面什么意思了吧LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam){PAINTSTRUCTps;HDChdc;TCHARszBuffer[2];staticintcxClient,cyClient;//客户区的宽高staticHBRUSHhbrush;//画刷staticBOOLf24hour,fNzero;//记录时间是24小时制或12小时制时间的开头不为0switch(message){caseW
9、M_CREATE:{//设置定时器::SetTimer(hWnd,1,1000,NULL);hbrush=::CreateSolidBrush(RGB(250,0,250));//创建画刷break;}caseWM_TIMER:{::InvalidateRect(hWnd,NULL,TRUE);//使客户区无效(进行重画)break;}caseWM_SETTINGCHANGE://系统设置发生改变时,出发此消息{::GetLocaleInfo(LOCALE_USER_