资源描述:
《C++闹钟程序(API)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include"Clock.h"#include"Resource.h"#defineSQUARESIZE20#defineID_TIMER_CLOCK1CMyAppmyApp;///////////////////////////////////////////////////////////////////////////CMyAppmemberfunctionsBOOLCMyApp::InitInstance(){SetRegistryKey(_T("ProgrammingWind
2、owswithMFC"));m_pMainWnd=newCMainWindow;if(!((CMainWindow*)m_pMainWnd)->RestoreWindowState())m_pMainWnd->ShowWindow(m_nCmdShow);m_pMainWnd->UpdateWindow();returnTRUE;}///////////////////////////////////////////////////////////////////////////CMainWindowmessagemapandmemberfunctions
3、BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)ON_WM_CREATE()ON_WM_PAINT()ON_WM_TIMER()ON_WM_GETMINMAXINFO()ON_WM_NCHITTEST()ON_WM_SYSCOMMAND()ON_WM_CONTEXTMENU()ON_WM_ENDSESSION()ON_WM_CLOSE()END_MESSAGE_MAP()CMainWindow::CMainWindow(){m_bAutoMenuEnable=FALSE;CTimetime=CTime::GetCurrent
4、Time();m_nPrevSecond=time.GetSecond();m_nPrevMinute=time.GetMinute();m_nPrevHour=time.GetHour()%12;CStringstrWndClass=AfxRegisterWndClass(CS_HREDRAW
5、CS_VREDRAW,myApp.LoadStandardCursor(IDC_ARROW),(HBRUSH)(COLOR_3DFACE+1),myApp.LoadIcon(IDI_APPICON));Create(strWndClass,_T("Clock"))
6、;}BOOLCMainWindow::PreCreateWindow(CREATESTRUCT&cs){if(!CFrameWnd::PreCreateWindow(cs))returnFALSE;cs.dwExStyle&=~WS_EX_CLIENTEDGE;returnTRUE;}intCMainWindow::OnCreate(LPCREATESTRUCTlpcs){if(CFrameWnd::OnCreate(lpcs)==-1)return-1;////Setatimertofireat1-secondintervals.//if(!SetTim
7、er(ID_TIMER_CLOCK,1000,NULL)){MessageBox(_T("SetTimerfailed"),_T("Error"),MB_ICONSTOP
8、MB_OK);return-1;}////Customizethesystemmenu.//CMenu*pMenu=GetSystemMenu(FALSE);pMenu->AppendMenu(MF_SEPARATOR);pMenu->AppendMenu(MF_STRING,IDM_SYSMENU_FULL_WINDOW,_T("Remove&Title"));pMenu->Appen
9、dMenu(MF_STRING,IDM_SYSMENU_STAY_ON_TOP,_T("StayonTo&p"));return0;}voidCMainWindow::OnClose(){SaveWindowState();KillTimer(ID_TIMER_CLOCK);CFrameWnd::OnClose();}voidCMainWindow::OnEndSession(BOOLbEnding){if(bEnding)SaveWindowState();CFrameWnd::OnEndSession(bEnding);}voidCMainWindow
10、::OnGetMinMaxInfo(MINMAXINFO*pMMI