包括C++封装原理和MFC六大关键技术,以及类向导和MFC应用程序向导的使用方法。讲解MFC消息映射机制的原理、消息映射函数的建立,以及消息发送和接收的方法。
CTime类
void CTmDlg::OnButton1() { CTime t = CTime::GetCurrentTime(); int nYear = t.GetYear(); int nMonth = t.GetMonth(); int nDay = t.GetDay(); int nHour = t.GetHour(); int nMin = t.GetMinute(); int nSec = t.GetSecond(); int nWeek = t.GetDayOfWeek();//周三 CString str; str.Format("当前时间是:%d年%02d月%02d日 %02d:%02d:%02d", nYear,nMonth,nDay,nHour,nMin,nSec); //AfxMessageBox(str); SetWindowText(str);//SetTimer } void CTmDlg::OnButton2() { time_t tt = time(NULL); tm * pTime = localtime(&tt); int nYear = pTime ->tm_year+1900; int nMonth = pTime ->tm_mon+1; int nDay = pTime ->tm_mday; int nHour = pTime ->tm_hour; int nMin = pTime ->tm_min; int nSec = pTime ->tm_sec; CString str; str.Format("当前时间是:%d年%02d月%02d日 %02d:%02d:%02d", nYear,nMonth,nDay,nHour,nMin,nSec); //AfxMessageBox(str); SetWindowText(str);//SetTimer }
类
#include "stdafx.h" #include <time.h> #include <stdio.h> #include "MyTime.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CMyTime t = CMyTime::GetCurrentTime(); int nYear = t.GetYear(); //CTime time; /* time_t tt = time(NULL); tm * pTime = localtime(&tt); int nYear = pTime ->tm_year+1900; int nMonth = pTime ->tm_mon+1; int nDay = pTime ->tm_mday; int nHour = pTime ->tm_hour; int nMin = pTime ->tm_min; int nSec = pTime ->tm_sec; char s[200]; sprintf(s,"当前时间是:%d年%02d月%02d日 %02d:%02d:%02d", nYear,nMonth,nDay,nHour,nMin,nSec); MessageBox(NULL,s,"提示",0);*/ return 0; }